-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwasm.c
74 lines (54 loc) · 1.15 KB
/
wasm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "types.h"
#include "rkdp.h"
static RKDP_WA_NEW(m_rkdp_wa, 2);
static double x[2] = {1.0, 0.0};
static double u[2] = {0.0, 0.0};
static double t = 0.0;
static double h = 0.1;
static double plant_params[3] = {1.0, 0.1, 1.0};
static void plant_function(
double * p_plant_params,
Vector x_dot,
double t,
const Vector x,
const Vector u
){
double m = p_plant_params[0];
double d = p_plant_params[1];
double k = p_plant_params[2];
x_dot[0] = x[1];
x_dot[1] = (-k * x[0] - d * x[1] + u[1]) / m;
}
static Plant plant = {
plant_params,
plant_function
};
double get_t(){
return t;
}
double get_x(int index){
return x[index];
}
double get_u(int index){
return u[index];
}
double get_plant_param(int index){
return plant_params[index];
}
void set_t(double new_t){
t = new_t;
}
void set_x(int index, double new_x){
x[index] = new_x;
}
void set_u(int index, double new_u){
u[index] = new_u;
}
void set_plant_param(int index, double new_param){
plant_params[index] = new_param;
}
double step(){
rkdp_step(m_rkdp_wa, &plant, x, NULL, t, x, u, h);
t = t + h;
return t;
}