-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain_se3s2.m
78 lines (54 loc) · 1.3 KB
/
main_se3s2.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
% main script
%% environment setup
clear; close all; clc;
%% helper functions
addpath(genpath('./helper_functions'));
addpath('./models');
%% script parameters
%%
trajectory = @circular_traj;
model = Quadrotorload('traj',trajectory);
model.controller = @model.ctrlGeoPD;
%%
% time
t0 = 0;
tf = 20;
% initial condition
r0 = 0;
p0 = 0;
y0 = 0;
xL0 = 0.*[1;1;1];
vL0 = zeros(3,1);
R0 = RPY2Rot_ZXY([r0*pi/180,p0*pi/180,y0*pi/180]);
Om0 = zeros(3,1);
q0 = [0;0;-1];
om0 = zeros(3,1);
xq0 = model.zipState(xL0,vL0,R0,Om0,q0,om0);
%% simulate
sol = model.simulate([t0, tf], xq0, @ode45);
% results
results.t = sol.x;
results.x = sol.y;
results.td = sol.x;
results.xd = model.getRefState(sol.x);
%% animate
opts.data = results;
opts.RATE = 12.5;
model.animate(opts);
%% plots
figure;
subplot(3,1,1);
hold on;
plot(sol.x,results.x(1,:),'r','linewidth',1);
plot(sol.x,results.xd(1,:),'b','linewidth',1);
grid on; grid minor; latex_legend({'$$x$$','$$x_d$$'});
subplot(3,1,2);
hold on;
plot(sol.x,results.x(2,:),'r','linewidth',1);
plot(sol.x,results.xd(2,:),'b','linewidth',1);
grid on; grid minor; latex_legend({'$$y$$','$$y_d$$'});
subplot(3,1,3);
hold on;
plot(sol.x,results.x(3,:),'r','linewidth',1);
plot(sol.x,results.xd(3,:),'b','linewidth',1);
grid on; grid minor; latex_legend({'$$z$$','$$z_d$$'});