【无人机】四轴无人机的轨迹进行可视化和动画处理(Matlab代码实现)

 📋📋📋本文目录如下:⛳️⛳️⛳️

目录

1 概述

2 运行结果

3 参考文献

4 Matlab代码实现


1 概述

随着传感器检测技术、智能控制技术和材料技术的快速发展,四轴无人机及其配套系统的发展越来越成熟。无人机遥感系统具有成本低、易维护、效率高、时效性强及对环境要求低等特点。

2 运行结果

 

部分代码:

function animation = drone_Animation(x,y,z,roll,pitch,yaw)
% This Animation code is for QuadCopter. Written by Jitendra Singh 

%% Define design parameters
D2R = pi/180;
R2D = 180/pi;
b   = 0.6;   % the length of total square cover by whole body of quadcopter in meter
a   = b/3;   % the legth of small square base of quadcopter(b/4)
H   = 0.06;  % hight of drone in Z direction (4cm)
H_m = H+H/2; % hight of motor in z direction (5 cm)
r_p = b/4;   % radius of propeller
%% Conversions
ro = 45*D2R;                   % angle by which rotate the base of quadcopter
Ri = [cos(ro) -sin(ro) 0;
      sin(ro) cos(ro)  0;
       0       0       1];     % rotation matrix to rotate the coordinates of base 
base_co = [-a/2  a/2 a/2 -a/2; % Coordinates of Base 
           -a/2 -a/2 a/2 a/2;
             0    0   0   0];
base = Ri*base_co;             % rotate base Coordinates by 45 degree 

to = linspace(0, 2*pi);
xp = r_p*cos(to);
yp = r_p*sin(to);
zp = zeros(1,length(to));
%% Define Figure plot
 fig1 = figure('pos', [0 50 800 600]);
 hg   = gca;
 view(68,53);
 grid on;
 axis equal;
 xlim([-1.5 1.5]); ylim([-1.5 1.5]); zlim([0 3.5]);
 title('(JITENDRA) Drone Animation')
 xlabel('X[m]');
 ylabel('Y[m]');
 zlabel('Z[m]');
 hold(gca, 'on');
 
%% Design Different parts
% design the base square
 drone(1) = patch([base(1,:)],[base(2,:)],[base(3,:)],'r');
 drone(2) = patch([base(1,:)],[base(2,:)],[base(3,:)+H],'r');
 alpha(drone(1:2),0.7);
% design 2 parpendiculer legs of quadcopter 
 [xcylinder ycylinder zcylinder] = cylinder([H/2 H/2]);
 drone(3) =  surface(b*zcylinder-b/2,ycylinder,xcylinder+H/2,'facecolor','b');
 drone(4) =  surface(ycylinder,b*zcylinder-b/2,xcylinder+H/2,'facecolor','b') ; 
 alpha(drone(3:4),0.6);
% design 4 cylindrical motors 
 drone(5) = surface(xcylinder+b/2,ycylinder,H_m*zcylinder+H/2,'facecolor','r');
 drone(6) = surface(xcylinder-b/2,ycylinder,H_m*zcylinder+H/2,'facecolor','r');
 drone(7) = surface(xcylinder,ycylinder+b/2,H_m*zcylinder+H/2,'facecolor','r');
 drone(8) = surface(xcylinder,ycylinder-b/2,H_m*zcylinder+H/2,'facecolor','r');
 alpha(drone(5:8),0.7);
% design 4 propellers
 drone(9)  = patch(xp+b/2,yp,zp+(H_m+H/2),'c','LineWidth',0.5);
 drone(10) = patch(xp-b/2,yp,zp+(H_m+H/2),'c','LineWidth',0.5);
 drone(11) = patch(xp,yp+b/2,zp+(H_m+H/2),'p','LineWidth',0.5);
 drone(12) = patch(xp,yp-b/2,zp+(H_m+H/2),'p','LineWidth',0.5);
 alpha(drone(9:12),0.3);

%% create a group object and parent surface
  combinedobject = hgtransform('parent',hg );
  set(drone,'parent',combinedobject)
%  drawnow
 
 for i = 1:length(x)
  
     ba = plot3(x(1:i),y(1:i),z(1:i), 'b:','LineWidth',1.5);
   
     translation = makehgtform('translate',...
                               [x(i) y(i) z(i)]);
     %set(combinedobject, 'matrix',translation);
     rotation1 = makehgtform('xrotate',(pi/180)*(roll(i)));
     rotation2 = makehgtform('yrotate',(pi/180)*(pitch(i)));
     rotation3 = makehgtform('zrotate',yaw(i));
     %scaling = makehgtform('scale',1-i/20);
     set(combinedobject,'matrix',...
          translation*rotation3*rotation2*rotation1);
      
      %movieVector(i) =  getframe(fig1);
        %delete(b);
     drawnow
   % pause(0.2);
 end

 

function animation = drone_Animation(x,y,z,roll,pitch,yaw)
% This Animation code is for QuadCopter. Written by Jitendra Singh

%% Define design parameters
D2R = pi/180;
R2D = 180/pi;
b   = 0.6;   % the length of total square cover by whole body of quadcopter in meter
a   = b/3;   % the legth of small square base of quadcopter(b/4)
H   = 0.06;  % hight of drone in Z direction (4cm)
H_m = H+H/2; % hight of motor in z direction (5 cm)
r_p = b/4;   % radius of propeller
%% Conversions
ro = 45*D2R;                   % angle by which rotate the base of quadcopter
Ri = [cos(ro) -sin(ro) 0;
      sin(ro) cos(ro)  0;
       0       0       1];     % rotation matrix to rotate the coordinates of base
base_co = [-a/2  a/2 a/2 -a/2; % Coordinates of Base
           -a/2 -a/2 a/2 a/2;
             0    0   0   0];
base = Ri*base_co;             % rotate base Coordinates by 45 degree

to = linspace(0, 2*pi);
xp = r_p*cos(to);
yp = r_p*sin(to);
zp = zeros(1,length(to));
%% Define Figure plot
 fig1 = figure('pos', [0 50 800 600]);
 hg   = gca;
 view(68,53);
 grid on;
 axis equal;
 xlim([-1.5 1.5]); ylim([-1.5 1.5]); zlim([0 3.5]);
 title('(JITENDRA) Drone Animation')
 xlabel('X[m]');
 ylabel('Y[m]');
 zlabel('Z[m]');
 hold(gca, 'on');
 
%% Design Different parts
% design the base square
 drone(1) = patch([base(1,:)],[base(2,:)],[base(3,:)],'r');
 drone(2) = patch([base(1,:)],[base(2,:)],[base(3,:)+H],'r');
 alpha(drone(1:2),0.7);
% design 2 parpendiculer legs of quadcopter
 [xcylinder ycylinder zcylinder] = cylinder([H/2 H/2]);
 drone(3) =  surface(b*zcylinder-b/2,ycylinder,xcylinder+H/2,'facecolor','b');
 drone(4) =  surface(ycylinder,b*zcylinder-b/2,xcylinder+H/2,'facecolor','b') ;
 alpha(drone(3:4),0.6);
% design 4 cylindrical motors
 drone(5) = surface(xcylinder+b/2,ycylinder,H_m*zcylinder+H/2,'facecolor','r');
 drone(6) = surface(xcylinder-b/2,ycylinder,H_m*zcylinder+H/2,'facecolor','r');
 drone(7) = surface(xcylinder,ycylinder+b/2,H_m*zcylinder+H/2,'facecolor','r');
 drone(8) = surface(xcylinder,ycylinder-b/2,H_m*zcylinder+H/2,'facecolor','r');
 alpha(drone(5:8),0.7);
% design 4 propellers
 drone(9)  = patch(xp+b/2,yp,zp+(H_m+H/2),'c','LineWidth',0.5);
 drone(10) = patch(xp-b/2,yp,zp+(H_m+H/2),'c','LineWidth',0.5);
 drone(11) = patch(xp,yp+b/2,zp+(H_m+H/2),'p','LineWidth',0.5);
 drone(12) = patch(xp,yp-b/2,zp+(H_m+H/2),'p','LineWidth',0.5);
 alpha(drone(9:12),0.3);

%% create a group object and parent surface
  combinedobject = hgtransform('parent',hg );
  set(drone,'parent',combinedobject)
%  drawnow
 
 for i = 1:length(x)
 
     ba = plot3(x(1:i),y(1:i),z(1:i), 'b:','LineWidth',1.5);
   
     translation = makehgtform('translate',...
                               [x(i) y(i) z(i)]);
     %set(combinedobject, 'matrix',translation);
     rotation1 = makehgtform('xrotate',(pi/180)*(roll(i)));
     rotation2 = makehgtform('yrotate',(pi/180)*(pitch(i)));
     rotation3 = makehgtform('zrotate',yaw(i));
     %scaling = makehgtform('scale',1-i/20);
     set(combinedobject,'matrix',...
          translation*rotation3*rotation2*rotation1);
      
      %movieVector(i) =  getframe(fig1);
        %delete(b);
     drawnow
   % pause(0.2);
 end

3 参考文献

部分理论引用网络文献,如有侵权请联系删除。

[1]李想,李阳.四轴无人机在林业管理中的应用[J].广西林业科学,2020,49(02):296-299.DOI:10.19692/j.cnki.gfs.2020.02.028.

4 Matlab完整代码实现

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是代码: ```matlab % 初始化 clear all; close all; clc; % 轨迹追踪控制器参数 Kp = 0.5; % 比例系数 Kd = 0.2; % 微分系数 Ki = 0.1; % 积分系数 % 飞行器初始位置和速度 pos_init = [0;0;0]; % 初始位置 vel_init = [0;0;0]; % 初始速度 % 目标轨迹参数 A = 5; % 轨迹振幅 omega = 2*pi/20; % 轨迹角频率 k = 1; % 轨迹距离因子 % 时间步长 dt = 0.01; % 运行轨迹追踪控制器 pos = pos_init; vel = vel_init; error_integral = [0;0;0]; for t = 0:dt:30 % 计算目标位置、速度和加速度 pos_d = [A*cos(omega*t); A*sin(omega*t); k*t]; vel_d = [-A*omega*sin(omega*t); A*omega*cos(omega*t); k]; acc_d = [0; 0; 0]; % 计算误差和误差导数 error = pos_d - pos; error_derivative = vel_d - vel; % 更新积分误差 error_integral = error_integral + error*dt; % 计算轨迹追踪控制器输出 u = acc_d + Kp*error + Kd*error_derivative + Ki*error_integral; % 更新飞行器位置和速度 vel = vel + u*dt; pos = pos + vel*dt; % 可视化 plot3(pos(1),pos(2),pos(3),'r.'); hold on; plot3(pos_d(1),pos_d(2),pos_d(3),'b.'); hold off; axis([-10 10 -10 10 0 200]); xlabel('x'); ylabel('y'); zlabel('z'); drawnow; end ``` 这个代码实现了一个简单的无人机轨迹追踪控制器,它可以将无人机沿着一条预定的轨迹飞行。轨迹追踪控制器使用比例、微分和积分控制技术来计算无人机的加速度控制指令,并将其应用于无人机。在这个例子中,我们使用了一个简单的三维轨迹来模拟无人机的飞行轨迹可视化窗口显示了无人机的位置轨迹(红点)和轨迹的期望轨迹(蓝点)。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值