-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdrawAircraft.m
154 lines (126 loc) · 3.83 KB
/
drawAircraft.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
function drawAircraft(uu)
% process inputs to function
pn = uu(1); % inertial North position
pd = uu(2); % inertial Down position
u = uu(3); % body frame velocities
w = uu(4);
theta = uu(5); % pitch angle
q = uu(6); % pitch rate
t = uu(7); % time
% define persistent variables
persistent aircraft_handle; % figure handle for UAV
persistent Vertices
persistent Faces
persistent facecolors
persistent S
% first time function is called, initialize plot and persistent vars
if t==0,
figure(1), clf
c130(pn,0,pd,...
'color','red',...
'pitch',theta,...
'yaw',270,...
'roll',270,...
'scale',1,...
'wing','g',...
'tailwing','g',...
'fuselage','g',...
'lines','none')
S = 800;
title('UAV')
xlabel('North')
ylabel('East')
zlabel('Altitude')
axis([0, 1000, 0, 1000,0,1000]);
grid on
% at every other time step, redraw quadrotor and target
else
c130(pn,0,pd,...
'color','red',...
'pitch',theta,...
'yaw',270,...
'roll',0,...
'scale',10,...
'wing','g',...
'tailwing','g',...
'fuselage','g',...
'lines','none')
view([30 90 30])
title('UAV')
xlabel('North')
ylabel('East')
zlabel('Altitude')
axis([0, 2000, -200, 200,-200,800]);
grid on
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function handle = drawBody(V,F,colors,...
pn, pd, theta,...
handle, mode)
V = rotate(V, theta); % rotate rigid body
V = translate(V, pn, pd); % translate after rotation
% transform vertices from NED to XYZ (for matlab rendering)
R = [...
1, 0;...
0, -1;...
];
V = R*V;
if isempty(handle),
handle = patch('Vertices', V', 'Faces', F,...
'FaceVertexCData',colors,...
'FaceColor','flat',...
'EraseMode', mode);
else
set(handle,'Vertices',V','Faces',F);
drawnow
end
end
%%%%%%%%%%%%%%%%%%%%%%%
function pts=rotate(pts,theta)
% define rotation matrix (right handed)
R_pitch = [...
cos(theta), -sin(theta);...
sin(theta), cos(theta)];
R = R_pitch;
% note that R above either leaves the vector alone or rotates
% a vector in a left handed rotation. We want to rotate all
% points in a right handed rotation, so we must transpose
R = R';
% rotate vertices
pts = R*pts;
end
% end rotateVert
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% translate vertices by pn, pe, pd
function pts = translate(pts,pn,pd)
pts = pts + repmat([pn;pd],1,size(pts,2));
end
% end translate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% define aircraft vertices and faces
function [V,F,colors] = defineAircraftBody(scale)
% parameters for drawing aircraft
% colors
%red = [1, 0, 0];
%green = [0, 1, 0];
blue = [0, 0, 1];
%yellow = [1,1,0];
%magenta = [0, 1, 1];
% define vertices and faces for aircraft
V = [...
6, 1;... % point 1
7, 0;... % point 2
3, -2;... % point 3
-5, -1;... % point 4
-9, -3;... % point 5
-9, 1;... % point 6
]';
F = [...
1, 2, 3, 4, 5, 6;... % nose-top
];
colors = [...
blue;...
];
V = scale*V; % rescale vertices
end