-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtailsitterDyna.m
82 lines (74 loc) · 1.88 KB
/
tailsitterDyna.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
76
77
78
79
80
81
82
% Author: Boyang Li
% The Hong Kong Polytechnic University
% email: [email protected]
% Website: https://boyangli.com
% May 2018;
function state_dot = tailsitterDyna2(state,control,p)
% dx = tailsitterDyna(state,control,p)
%
% This function calculate derivative of the uav at
% given time, state, and control input
%
% INPUTS:
% state = [3, n] = [xd;zd;theta]
% u = [2, n] = [ft_cmd;theta_cmd]
% p = parameter struct
% .g = gravity
% .mass = UAV mass
% .rho = density
% .tau = time constanct
% .k = gain
% OUTPUTS:
% state_dot = dx/dt = time derivative of state
%
% uppack
xd = state(1,:);
zd = state(2,:);
theta = state(3,:);
ft_cmd = control(1,:);
theta_cmd = control(2,:);
% Ft = thro_to_force(thro_cmd);
% aerodynamics //control surface?
% Cl0 = 0;
% Cla = 4.0;
% Cda = 0.5;
% aoa = atan2(u,-w);
% aoa = theta + 0.5*pi;
% AS = sqrt(u^2+w^2);
% AS = sqrt(xd.^2 + zd.^2);
% AS = xd;
% Cl = Cl0 + aoa .* Cla;
% Cd = 0.2 + aoa .* Cda;
% Cl = sin(2*aoa);
% Cd = 0.1 + 1.7 .* sin(aoa).^2;
% accurate aero params
% get aoa and as
aoa = theta + pi/2 + atan(zd/xd);
AS = sqrt(xd.^2+zd.^2);
% search Cl and Cd
% Cl = interp1(p.aoa,p.cl,aoa*180/pi);
% Cd = interp1(p.aoa,p.cd,aoa*180/pi);
Cl = ppval(p.pp_cl,aoa*180/pi);
Cd = ppval(p.pp_cd,aoa*180/pi);
% Aero force, wind axis
Fl = 0.5 * p.rho * AS.^2 * p.S .* Cl;
Fd = 0.5 * p.rho * AS.^2 * p.S .* Cd;
Fxb = -Fl.*cos(aoa)-Fd.*sin(aoa);
Fzb = -Fl.*sin(aoa)+Fd.*cos(aoa);
Fxi = Fxb.*cos(theta)+Fzb.*sin(theta);
Fzi = -Fxb.*sin(theta)+Fzb.*cos(theta);
% derivatave
xdd = -ft_cmd .* sin(theta) ./ p.mass + Fxi;%-Fd
zdd = p.g - ft_cmd .* cos(theta)./ p.mass + Fzi;%-Fl
thetad = (1/p.Ts) .* (theta_cmd - theta);
state_dot = [xdd; zdd; thetad];
end
% function ft = thro_to_force(u)
% if (u > 1)
% u = 1;
% elseif (u<0)
% u = 0;
% end
% ft_single = -10.861*u^3+21.803*u^2-2.0175*u+0.5661875;
% ft = ft_single * 4;
% end