forked from chijiang/Simulation-StewartPlatform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStewartPlatformSetup.m
More file actions
224 lines (210 loc) · 7.25 KB
/
Copy pathStewartPlatformSetup.m
File metadata and controls
224 lines (210 loc) · 7.25 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
%% Simulation of a Stewart platform
% Instructions
% ------------
%
% This file is the setup file to simulate a Stewart platform, which
% is designed for project using in IRP, TU Braunschweig. The thesis
% "Design und Dynamikanalyse der Stewart-Plattform" by Yunqi Gu provides
% the theoretical background of this simulation. The detail of the
% simulation process is written in thesis "Simulation einer Stewart-
% Plattform mit MATLAB" by Chijiang Duan.
% The files needed in this simulation
%
% Base.step
% Control_loop.slx
% holder.step
% inverse_kinematic.m
% leg_d.step
% leg_u.step
% platform.step
% StewartPlatformSetup.m
%
% All datas and files can be downloaded from
% https://github.com/chijiang/Simulation-StewartPlatform.git
%% Initialization
clc; clear; close all; format;
%% Define basic angular unit conversions and axes
deg2rad = pi / 180;
x_axis = [1 0 0];
y_axis = [0 1 0];
z_axis = [0 0 1];
%% Connection points on the base and top platform w.r.t the world frame
pos_base = zeros(6, 3);
pos_top = zeros(6, 3);
radius_b = 0.25145;
radius_t = 0.2169;
alpha_b = (60 - 11.47) * deg2rad;
alpha_t = 12.86 * deg2rad;
height = 0.5;
for i = 1:3
% base points
angle_m_b = (2 * pi/3) * (i-1) - alpha_b - pi/2;
angle_p_b = (2 * pi/3) * (i-1) + alpha_b - pi/2;
pos_base(2 * i - 1,:) = [radius_b * cos(angle_m_b), ...
radius_b * sin(angle_m_b), 0.05];
pos_base(2 * i, :) = [radius_b * cos(angle_p_b), ...
radius_b* sin(angle_p_b), 0.05];
% top points
angle_m_t = (2 * pi / 3)* (i-1) - alpha_t - pi/2;
angle_p_t = (2 * pi / 3)* (i-1) + alpha_t - pi/2;
pos_top(2 * i - 1, :) = [radius_t * cos(angle_m_t), ...
radius_t * sin(angle_m_t), height + 0.05];
pos_top(2 * i,:) = [radius_t * cos(angle_p_t), ...
radius_t * sin(angle_p_t), height + 0.05];
end
%% Leg lengths and unit vectors
legs = pos_top - pos_base;
leg_length = zeros(1, 6);
leg_vectors = zeros(6, 3);
for i = 1:6
leg_length(i) = norm(legs(i, :));
leg_vectors(i, :) = legs(i, :) / leg_length(i);
end
%% Important translations, density and center of masses (Not all needed for this version of simulation)
% %% revolute and cylindrical axes for joints
% rev1 = zeros(6,3);
% rev2 = zeros(6,3);
% rev3 = zeros(6,3);
% rev4 = zeros(6,3);
% cyl1 = zeros(6,3);
% for i = 1:6
% % spherical joints
% rev1(i,:) = cross(leg_vectors(i,:), z_axis);
% rev1(i,:) = rev1(i,:) / norm(rev1(i,:));
% rev2(i,:) = - cross(rev1(i,:), leg_vectors(i,:));
% rev2(i,:) = rev2(i,:) / norm(rev2(i,:));
% % cylinder joints
% cyl1(i,:) = leg_vectors(i,:);
% % universal joints
% rev3(i,:) = rev1(i,:);
% rev4(i,:) = rev2(i,:);
% end
% % The Translation from platform to upper legs
top2leg = pos_top' - (height + 0.05 + 0.02) * [zeros(2,6);ones(1,6)];
% lower_leg = struct('origin', [0 0 0], 'rotation', eye(3), 'end_point', [0 0 0]);
% upper_leg = struct('origin', [0 0 0], 'rotation', eye(3), 'end_point', [0 0 0]);
% for i = 1:6
% lower_leg(i).origin = pos_base(i,:) + (3/8)*legs(i,:);
% lower_leg(i).end_point = pos_base(i,:) + (3/4)*legs(i,:);
% lower_leg(i).rotation = [rev1(i,:)', rev2(i,:)', cyl1(i,:)'];
% upper_leg(i).origin = pos_base(i,:) + (1-3/8)*legs(i,:);
% upper_leg(i).end_point = pos_base(i,:) + (1/4)*legs(i,:);
% upper_leg(i).rotation = [rev1(i,:)', rev2(i,:)', cyl1(i,:)'];
% end
% %% Inertia and mass of the top plate, bottom plate, and the legs
% top_thickness = 0.04;
% base_thickness = 0.05;
% inner_radius = 0.02; % legs
% outer_radius = 0.035; % legs
density = 2712; % Kg/m^3 --- Aluminum 2712;
% [lower_leg_mass, lower_leg_inertia] = inertiaCylinder(density, 0.350,outer_radius, inner_radius);
% [upper_leg_mass, upper_leg_inertia] = inertiaCylinder(density, 0.350,inner_radius, 0);
% [top_mass, top_inertia] = inertiaCylinder(density, top_thickness, radius_t, 0.15);
% [base_mass, base_inertia] = inertiaCylinder(density, base_thickness, radius_b, 0.175);
%% PID controller gains
% Kp = 2e6; Ki = 1e4; Kd = 4.5e4;
Kp = 3e6; Ki = 0; Kd = 2.5e4;
%% Motion control
% Amplitude of sine signals
xang_a = 0; yang_a = 20*deg2rad; zang_a = 0;
xpos_a = 0.15; ypos_a = 0; zpos_a = 0;
% Frequency of sine signals
xang_f = 2; yang_f = 2; zang_f = 0;
xpos_f = 2; ypos_f = 0; zpos_f = 2;
% Phase of sine signals
xang_p = 0; yang_p = 0; zang_p = 0;
xpos_p = 0; ypos_p = pi/2; zpos_p = 0;
%% Initial posture
alpha = xang_a*sin(0 + xang_p);
beta = yang_a*sin(0 + yang_p);
gamma = zang_a*sin(0 + zang_p);
top_position = [xpos_a*sin(0 + xpos_p);
ypos_a*sin(0 + ypos_p);
zpos_a*sin(0 + zpos_p) + height+0.07];
speed_top = zeros(6, 1);
[length, speed] = inverse_kinematic(alpha, beta, gamma, top_position, speed_top, pos_base', top2leg);
length = length - leg_length;
%% Perform the simulation
% i = 1;
% for Ki = [0, 1000, 1e4]
% sim('Control_loop.slx')
% subplot(3,2,i)
% plot(error, 'LineWidth', 2)
% title(['Error by K_i = ', num2str(Ki)])
% legend('Leg 1','Leg 2','Leg 3','Leg 4','Leg 5','Leg 6')
% ylabel('Error [m]')
% xlabel('Time [s]')
% set(gca,'FontSize',15)
% subplot(3,2,i+1)
% plot(force, 'LineWidth', 2)
% % axis([0,5,50,120]);
% title(['Force by K_i = ', num2str(Ki)])
% ylabel('Force [N]')
% xlabel('Time [s]')
% legend('Leg 1','Leg 2','Leg 3','Leg 4','Leg 5','Leg 6')
% set(gca,'FontSize',15)
% i = i + 2;
% end
% --------------------------------------------------
% Pendulum
% figure;
% sim('Control_loop.slx')
% subplot(3,2,1)
% plot(Platform_pos, 'LineWidth', 2)
% legend('x','y','z')
% title('Platform position for pendulum')
% xlabel('Time [s]')
% ylabel('Position [m]')
% set(gca,'FontSize',15)
% subplot(3,2,3)
% plot(error, 'LineWidth', 2)
% legend('Leg 1','Leg 2','Leg 3','Leg 4','Leg 5','Leg 6')
% title('Error for pendulum')
% xlabel('Time [s]')
% ylabel('Error [m]')
% set(gca,'FontSize',15)
% subplot(3,2,5)
% plot(force, 'LineWidth', 2)
% legend('Leg 1','Leg 2','Leg 3','Leg 4','Leg 5','Leg 6')
% title('Leg force for pendulum')
% xlabel('Time [s]')
% ylabel('Force [N]')
% set(gca,'FontSize',15)
% % -------------------------------------------------
% % Lifting movement
% yang_a = 0; xpos_a = 0; zpos_a = 0.2;
% zpos_f = 2; zpos_p = 0;
% alpha = xang_a*sin(0 + xang_p);
% beta = yang_a*sin(0 + yang_p);
% gamma = zang_a*sin(0 + zang_p);
%
% top_position = [xpos_a*sin(0 + xpos_p);
% ypos_a*sin(0 + ypos_p);
% zpos_a*sin(0 + zpos_p) + height+0.07];
% speed_top = zeros(6, 1);
% [length, speed] = inverse_kinematic(alpha, beta, gamma, top_position, speed_top, pos_base', top2leg);
% length = length - leg_length;
% sim('Control_loop.slx')
% subplot(3,2,2)
% plot(Platform_pos, 'LineWidth', 2)
% legend('x','y','z')
% title('Platform position for lifting movement')
% xlabel('Time [s]')
% ylabel('Position [m]')
% set(gca,'FontSize',15)
% subplot(3,2,4)
% plot(error, 'LineWidth', 2)
% legend('Leg 1','Leg 2','Leg 3','Leg 4','Leg 5','Leg 6')
% title('Error for lifting movement')
% xlabel('Time [s]')
% ylabel('Error [m]')
% set(gca,'FontSize',15)
% subplot(3,2,6)
% plot(force, 'LineWidth', 2)
% legend('Leg 1','Leg 2','Leg 3','Leg 4','Leg 5','Leg 6')
% title('Leg force for lifting movement')
% xlabel('Time [s]')
% ylabel('Force [N]')
% set(gca,'FontSize',15)
% saveas(gcf, '~/Documents/StewartPlatform/variFig.png')
sim('Control_loop.slx')