-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathquadrotor_sim.m
68 lines (53 loc) · 1.75 KB
/
quadrotor_sim.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
%-----------------------------------------------------------------------%
% %
% This script simulates quadrotor dynamics and implements a control % %
% algrotihm. %
% 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;
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
% Kalman_phi2;
% Kalman_theta2;
% Kalman_psi2;
% Kalman_Z2;
% Kalman_X2;
% Kalman_Y2;
% Implement Controller
position_PID;
attitude_PID;
rate_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