👨🎓个人主页:研学社的博客
💥💥💞💞欢迎来到本博客❤️❤️💥💥
🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。
⛳️座右铭:行百里者,半于九十。
📋📋📋本文目录如下:🎁🎁🎁
目录
💥1 概述
📚2 运行结果
部分代码:
function drawVehicle(uu,V,F,patchcolors)
% process inputs to function
pn = uu(1); % inertial North position
pe = uu(2); % inertial East position
pd = uu(3);
u = uu(4);
v = uu(5);
w = uu(6);
phi = uu(7); % roll angle
theta = uu(8); % pitch angle
psi = uu(9); % yaw angle
p = uu(10); % roll rate
q = uu(11); % pitch rate
r = uu(12); % yaw rate
t = uu(13); % time
% define persistent variables
persistent vehicle_handle;
persistent Vertices
persistent Faces
persistent facecolors
% first time function is called, initialize plot and persistent vars
if t==0,
figure(1), clf
[Vertices,Faces,facecolors] = defineVehicleBody;
vehicle_handle = drawVehicleBody(Vertices,Faces,facecolors,...
pn,pe,pd,phi,theta,psi,...
[],'normal');
title('Vehicle')
xlabel('East')
ylabel('North')
zlabel('-Down')
view(32,47) % set the vieew angle for figure
axis([-10,10,-10,10,-10,10]);
hold on
% at every other time step, redraw base and rod
else
drawVehicleBody(Vertices,Faces,facecolors,...
pn,pe,pd,phi,theta,psi,...
vehicle_handle);
end
end
%=======================================================================
% drawVehicle
% return handle if 3rd argument is empty, otherwise use 3rd arg as handle
%=======================================================================
%
function handle = drawVehicleBody(V,F,patchcolors,...
pn,pe,pd,phi,theta,psi,...
handle,mode)
V = rotate(V, phi, theta, psi); % rotate vehicle
V = translate(V, pn, pe, pd); % translate vehicle
% transform vertices from NED to XYZ (for matlab rendering)
R = [...
0, 1, 0;...
1, 0, 0;...
0, 0, -1;...
];
V = R*V;
if isempty(handle),
handle = patch('Vertices', V', 'Faces', F,...
'FaceVertexCData',patchcolors,...
'FaceColor','flat',...
'EraseMode', mode);
else
set(handle,'Vertices',V','Faces',F);
drawnow
end
end
%%%%%%%%%%%%%%%%%%%%%%%
function pts=rotate(pts,phi,theta,psi)
% define rotation matrix (right handed)
R_roll = [...
1, 0, 0;...
0, cos(phi), sin(phi);...
0, -sin(phi), cos(phi)];
R_pitch = [...
cos(theta), 0, -sin(theta);...
0, 1, 0;...
sin(theta), 0, cos(theta)];
R_yaw = [...
cos(psi), sin(psi), 0;...
-sin(psi), cos(psi), 0;...
0, 0, 1];
R = R_roll*R_pitch*R_yaw;
% 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,pe,pd)
pts = pts + repmat([pn;pe;pd],1,size(pts,2));
end
% end translate
%=======================================================================
% defineVehicleBody
%=======================================================================
function [V,F,facecolors] = defineVehicleBody
% Define the vertices (physical location of vertices
V = [...
1, 0, 0;... % pt 1
-1, -2, 0;... % pt 2
0, 0, 0;... % pt 3
-1, 2, 0;... % pt 4
0, 0, -1;... % pt 5
]';
% define faces as a list of vertices numbered above
F = [...
1, 2, 3;... % left wing
1, 3, 4;... % right wing
1, 3, 5;... % tail
];
% define colors for each face
myred = [1, 0, 0];
mygreen = [0, 1, 0];
myblue = [0, 0, 1];
myyellow = [1, 1, 0];
mycyan = [0, 1, 1];
facecolors = [...
mygreen;... % left wing
mygreen;... % right wing
myblue;... % tail
];
end
🎉3 参考文献
部分理论来源于网络,如有侵权请联系删除。
[1]陈晓飞,董彦非.基于Matlab/Simulink的无人机自主着陆过程仿真[J].火力与指挥控制,2014,39(11):55-58+63.
[2]吕晓林,罗纯哲.无人机基于Matlab/Simulink仿真技术研究[J].宇航计测技术,2011,31(06):30-34+45.