-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkinesim.m
115 lines (97 loc) · 2.24 KB
/
kinesim.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
%% Stewart Platform Kinematic Simulation
% Made by Benedictus Christo Geroda Cinun
clc
clear variables
close all
syms x(t) y(t) z(t) phi(t) theta(t) psi(t)
%% Parameters
dt = 0.01; %step
t_max = 5; %max time
t = 0:dt:t_max; %iteration
rb = 0.2; %radius frame {B} in meter
rp = 0.16; %radius frame {P} in meter
sigma = deg2rad(15);
%% Desired Position
x = 0;
y = 0;
z = 0.37;
%% Desired Orientation
phi = deg2rad(5*sin(0.02*t*100)); %pitch
theta = deg2rad(5*cos(0.02*t*100)); %roll
psi = 0; %yaw
%% Empty array to store values
s1 = [];
s2 = [];
s3 = [];
s4 = [];
s5 = [];
%% Make a video of the simulation
v = VideoWriter('KineSim.mp4','MPEG-4');
open(v);
%% Loop
for i = 1:length(t)
%if the position or the orientation changes , use the letter and add i
%(example: x(i))
%if the position or the orientation doesn't change, just use the letter
%(example: x)
q = [x; y; z; phi(i); theta(i); psi];
[s] = kinematics(rp, rb, sigma, q);
s1(i) = s(1);
s2(i) = s(2);
s3(i) = s(3);
s4(i) = s(4);
s5(i) = s(5);
s6(i) = s(6);
frame = getframe(gcf);
writeVideo(v, frame);
end
close(v);
%% Plotting Legs length
figure(2)
plot(t, s1, '.','Color',[0 0 0]);
title("1st Leg's Length");
xlabel('Time (t)');
ylabel('Length (m)');
axis([0 t_max, 0.3 0.55]);
grid on
hold on
figure(3)
plot(t, s2, '.','Color',[0 0 0]);
title("2nd Leg's Length");
xlabel('Time (t)');
ylabel('Length (m)');
axis([0 t_max, 0.3 0.55]);
grid on
hold on
figure(4)
plot(t, s3, '.','Color',[0 0 0]);
title("3rd Leg's Length");
xlabel('Time (t)');
ylabel('Length (m)');
axis([0 t_max, 0.3 0.55]);
grid on
hold on
figure(5)
plot(t, s4, '.','Color',[0 0 0]);
title("4th Leg's Length");
xlabel('Time (t)');
ylabel('Length (m)');
axis([0 t_max, 0.3 0.55]);
grid on
hold on
figure(6)
plot(t, s5, '.','Color',[0 0 0]);
title("5th Leg's Length");
xlabel('Time (t)');
ylabel('Length (m)');
axis([0 t_max, 0.3 0.55]);
grid on
hold on
figure(7)
plot(t, s6, '.','Color',[0 0 0]);
title("6th Leg's Length");
xlabel('Time (t)');
ylabel('Length (m)');
axis([0 t_max, 0.3 0.55]);
grid on
hold on