-
Notifications
You must be signed in to change notification settings - Fork 36
/
quadrotor_sim.asv
59 lines (44 loc) · 1.59 KB
/
quadrotor_sim.asv
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
%-----------------------------------------------------------------------%
% %
% This script simulates quadrotor dynamics and implements a control % %
% algrotihm. %
% Developed by: Wil Selby %
% %
% %
%-----------------------------------------------------------------------%
%% Initialize Workspace
clear all;
close all;
clc;
global Quad;
%% Initialize the plot
init_plot;
plot_quad_model;
%% Initialize Variables
quad_variables;
quad_dynamics_nonlinear;
%% Run The Simulation Loop
while Quad.t_plot(Quad.counter-1)< max(Quad.t_plot);
% Measure Parameters (for simulating sensor errors)
sensor_meas;
% Filter Measurements
% Implement Controller
% outer_PID;
inner_PID;
% Calculate Desired Motor Speeds
quad_motor_speed;
% Update Position With The Equations of Motion
quad_dynamics_nonlinear;
% Plot the Quadrotor's Position
if(mod(Quad.counter,3)==0)
plot_quad
% campos([A.X+2 A.Y+2 A.Z+2])
% camtarget([A.X A.Y A.Z])
% camroll(0);
Quad.counter;
drawnow
end
Quad.init = 1; %Ends initialization after first simulation iteration
end
%% Plot Data
plot_data