-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVehicleDynamicRespond.m
66 lines (54 loc) · 1.11 KB
/
VehicleDynamicRespond.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function sys = VehicleDynamicRespond(command)
%% state variable
global ego_satation_init
global ego_velocity_init
global ego_accelaration_init
global ego_jerk_init
global sample_time
persistent init
persistent s
persistent v
persistent a
persistent jerk
if isempty(init)
init = false;
end
if isempty(s)
s = ego_satation_init;
end
if isempty(v)
v = ego_velocity_init;
end
if isempty(a)
a = ego_accelaration_init;
end
if isempty(jerk)
jerk = ego_jerk_init;
end
if ~init
sys.s = s;
sys.v = v;
sys.a = a;
sys.jerk = jerk;
init = true;
return;
end
%% system model
states = [v; a; jerk];
input = [command];
f = @CalculateDifferential;
states = OED_RK4(f, states, input, sample_time);
global upper_velocity
global lower_velocity
global upper_acceleration
global lower_acceleration
global upper_jerk
global lower_jerk
v = min(max(states(1, 1), lower_velocity), upper_velocity);
a = min(max(states(2, 1), lower_acceleration), upper_acceleration);
jerk = min(max(states(3, 1), lower_jerk), upper_jerk);
s = s + states(1, 1) * sample_time;
sys.s = s;
sys.v = v;
sys.a = a;
sys.jerk = jerk;