-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathQuadSimulink.m
75 lines (58 loc) · 1.89 KB
/
QuadSimulink.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
%-----------------------------------------------------------------------%
% %
% This script simulates quadrotor dynamics and implements a control % %
% algrotihm using the Simulnk Block Diagram file QuadrotorSimulink.mdl %
% Developed by: Wil Selby %
% %
% %
%-----------------------------------------------------------------------%
% Add Paths
addpath utilities
%% Initialize Workspace
clear all;
% close all;
clc;
global Quad;
%% Initialize the plot
init_plot;
plot_quad_model;
%% Initialize Variables
quad_variables;
%% Run Simulation
SimOut = sim('QuadrotorSimulink');
%% Run The Simulation Loop
for S = 1 : 1 : size(SimOut,1)
Quad.X = X_out.signals.values(S);
Quad.Y = Y_out.signals.values(S);
Quad.Z = Z_out.signals.values(S);
Quad.phi = Phi_out.signals.values(S);
Quad.theta = Theta_out.signals.values(S);
Quad.psi = Psi_out.signals.values(S);
% Plot the Quadrotor's Position
plot_quad
% campos([A.X+2 A.Y+2 A.Z+2])
% camtarget([A.X A.Y A.Z])
% camroll(0);
drawnow;
end
%% Plot Data
figure();
plot(SimOut,X_out.signals.values)
hold on;
plot(SimOut,X_desired.signals.values);
title('X');
figure();
plot(SimOut,Y_out.signals.values)
hold on;
plot(SimOut,Y_desired.signals.values);
title('Y');
figure();
plot(SimOut,Z_out.signals.values)
hold on;
plot(SimOut,Z_desired.signals.values);
title('Z');
figure();
plot(SimOut,Psi_out.signals.values)
hold on;
plot(SimOut,Psi_desired.signals.values);
title('Psi');