-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbiped main.m
More file actions
82 lines (65 loc) · 2.01 KB
/
biped main.m
File metadata and controls
82 lines (65 loc) · 2.01 KB
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
75
76
77
78
79
80
81
82
clear
clc
global p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 psi;
mH = 10;
m1 = 5;
m2 = 5;
a = 0.5;
b = 0.5;
l = a + b;
g= 9.81;
p1 = mH*l^2 + m1*b^2 + m2*l^2;
p2 = m2*l*a;
p3 = m2*a^2;
p4 = (m1*b + m2*l + mH*l)*g;
p5 = m2*a*g;
p6 = m1*l^2 + mH*l^2 + m2*b^2;
p7 = m1*a*l;
p8 = m1*a^2;
p9 = m1*a*b;
p10 = m2*b*l + mH*l^2 + m1*b*l;
p11 = m2*b*a;
psi = 4.1255*pi/180;
%psi = 3.1*pi/180;
q0 = [(12.53*pi/180); (-18.53*pi/180)];
Dq0 = [-1;1.5];
x0 = [q0; Dq0];
MAP_SELECTOR = 1;
SIMULATION_TIME = 15;
DRAW_INTERVAL = 0.05;
T0=0;
tspan=[T0 SIMULATION_TIME];
state_space = [];
time = [];
impacts = [];
last_impact = 0;
gait_period = [];
current_time = T0;
while (current_time < SIMULATION_TIME)
options = odeset('Events', @impact_event);
[tout, xout, event_time, event_state, event_id] = ode45(...
@equations_of_motion, tspan, x0, options);
xout(:,1)=wrapToPi(xout(:,1));
xout(:,2)=wrapToPi(xout(:,2));
disp(xout)
if ~isempty(event_id) && event_time(end) == tout(end)
impact_time = tout(end);
impact_index = length(time) + length(tout);
impacts = [impacts; impact_time, impact_index];
gait_period = [gait_period; impact_time - last_impact];
last_impact = impact_time;
x0 = impact_map(xout(end,:));
%fprintf('**************\n');
%fprintf('Impact at time = %0.2f\n', impact_time);
%fprintf('Index = %d\n', impact_index);
%fprintf('q1 = %0.2f\n', xout(end,1)*180/pi);
%fprintf('q2 = %0.2f\n', xout(end,2)*180/pi);
end
time = [time; tout];
state_space = [state_space; xout];
tspan = [time(end) max(SIMULATION_TIME, time(end))];
current_time = time(end);
end
%x0=wrapToPi(x0);
plot(state_space(:,1),state_space(:,3),state_space(:,2),state_space(:,4))
%animate_walker(time, impacts, DRAW_INTERVAL, state_space, figure);