-
Notifications
You must be signed in to change notification settings - Fork 1
/
getStates.m
43 lines (33 loc) · 1.01 KB
/
getStates.m
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
function states = getStates(setting, arg, input)
state0 = zeros(6, 1);
state1 = zeros(6, 1);
state0(1) = arg.x;
state0(2) = arg.y;
state0(3) = arg.psi;
state0(4) = arg.v;
state0(5) = arg.cte;
state0(6) = arg.epsi;
Lf = setting.Lf;
dt = setting.dt;
N = setting.N;
states = zeros(6, N);
states(:,1) = state0;
for i = 1:(N-1)
state1(1) = state0(1) + state0(4) * cos(state0(3)) * dt;
state1(2) = state0(2) + state0(4) * sin(state0(3)) * dt;
state1(3) = state0(3) + state0(4) * input(i) / Lf * dt;
state1(4) = state0(4) + input(N-1+i) * dt;
state1(5) = polyVal(arg.coeffs, state0(1)) - state0(2) + state0(4)*sin(state0(6))*dt;
state1(6) = state0(3) - atan(arg.coeffs(2)+2*arg.coeffs(3)) + state0(4)*input(i)/Lf*dt;
state0(1) = state1(1);
state0(2) = state1(2);
state0(3) = state1(3);
state0(4) = state1(4);
state0(5) = state1(5);
state0(6) = state1(6);
states(:,i+1) = state0;
end
end
function y = polyVal(coeffs,x)
y = coeffs(1) +coeffs(2)*x +coeffs(3)*x*x;
end