-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquadrotor.m
44 lines (30 loc) · 1.63 KB
/
quadrotor.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
function dz = quadrotor(t, z, u, p, r, n)
% State vector definition
%
% x1, x2, x3, phi, theta, psi, dx1, dx2, dx3, omega1, omega2, omega3
% z = [z1, z2, z3, z4, z5, z6, z7, z8, z9, z10, z11, z12]
%
% Parameter vector definition
%
% g, l, m, I11, I22, I33, mu, sigma
% p = [p1, p2, p3, p4, p5, p6, p7, p8]
% Forming the moment of inertia tensor based on the parametr values
I = diag(p(4:6));
% Rotation matrix mapping body fixed frame C to inertial frame E
R = [ cos(z(5))*cos(z(6)), sin(z(4))*sin(z(5))*cos(z(6)) - cos(z(4))*sin(z(6)), sin(z(4))*sin(z(6)) + cos(z(4))*sin(z(5))*cos(z(6));
cos(z(5))*sin(z(6)), cos(z(4))*cos(z(6)) + sin(z(4))*sin(z(5))*sin(z(6)), cos(z(4))*sin(z(5))*sin(z(6)) - sin(z(4))*cos(z(6));
-sin(z(5)), sin(z(4))*cos(z(5)), cos(z(4))*cos(z(5))];
% Adjusting thrust output based on feasible limits
u = max( min(u, p(7)), 0);
% Computing temporrary variables
% rt = torque vector induced by rotor thrusts
rt = [ ( u(2) - u(4) )*p(2);
( u(3) - u(1) )*p(2);
( u(1) - u(2) + u(3) - u(4) )*p(8)];
% Computing time derivative of the state vector
dz(1:3,1) = z(7:9,1);
dz(4:6,1) = [ z(10) + z(12)*cos(z(4))*tan(z(5)) + z(11)*sin(z(4))*tan(z(5));
z(11)*cos(z(4)) - z(12)*sin(z(4));
(z(12)*cos(z(4)) + z(11)*sin(z(4)))/cos(z(5))];
dz(7:9,1) = R*([0; 0; sum(u)] + r)/p(3) - [0; 0; p(1)];
dz(10:12,1) = I\( rt + n - cross( z(10:12,1) , I * z(10:12,1) ) );