✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
⛄ 内容介绍
针对四旋翼无人机在野外工作受风干扰的问题,提出了风场干扰下四旋翼无人机的飞行控制方法.通过对四旋翼无人机的受力分析,考虑陀螺仪效应建立非线性数学模型,并引进外部风场干扰,建立了在风场作用下的位置姿态控制模型.设计反步法控制器,实现四旋翼无人机的位置及姿态控制,利用Lyapunov稳定性理论证明系统的稳定性,并利用Matlab/Simulink模拟分析控制策略的效果.在自然风的作用下,这一模型准确反映了系统的动态特性,且反步法控制器对四旋翼无人机执行轨迹追踪控制稳定性良好.
⛄ 部分代码
classdef mav_dynamics < handle
properties
ts_simulation
state
true_state
en
methods
function self = mav_dynamics(Ts, MAV)
self.ts_simulation = Ts;
self.state = [MAV.pn0; MAV.pe0; MAV.pd0; MAV.u0; MAV.v0; MAV.w0;...
MAV.e0; MAV.e1; MAV.e2; MAV.e3; MAV.p0; MAV.q0; MAV.r0];
addpath('../message_types');
self.true_state = msg_state();
end
function self=update_state(self, forces_moments, MAV)
%
% Integrate the differential equations defining dynamics
% forces_moments are the forces and moments on the MAV.
%
% Integrate ODE using Runge-Kutta RK4 algorithm
k1 = self.derivatives(self.state, forces_moments, MAV);
k2 = self.derivatives(self.state + (self.ts_simulation/2)*k1, forces_moments, MAV);
k3 = self.derivatives(self.state + (self.ts_simulation/2)*k2, forces_moments, MAV);
k4 = self.derivatives(self.state + self.ts_simulation*k3, forces_moments, MAV);
self.state = self.state + (self.ts_simulation/6) * (k1 + 2*k2 + 2*k3 + k4);
% normalize the quaternion
self.state(7:10) = self.state(7:10)/norm(self.state(7:10));
self.update_true_state(forces_moments);
end
function xdot = derivatives(self, state, forces_moments, MAV)
pn = state(1);
pe = state(2);
h = -state(3);
u = state(4);
v = state(5);
w = state(6);
e0 = state(7);
e1 = state(8);
e2 = state(9);
e3 = state(10);
p = state(11);
q = state(12);
r = state(13);
fx = forces_moments(1);
fy = forces_moments(2);
fz = forces_moments(3);
l = forces_moments(4);
m = forces_moments(5);
n = forces_moments(6);
mass = MAV.mass;
gamma1 = MAV.Gamma1;
gamma2 = MAV.Gamma2;
gamma3 = MAV.Gamma3;
gamma4 = MAV.Gamma4;
gamma5 = MAV.Gamma5;
gamma6 = MAV.Gamma6;
gamma7 = MAV.Gamma7;
gamma8 = MAV.Gamma8;
Jy = MAV.Jy;
% position kinematics
pn_dot = (e1^2 + e0^2 - e2^2 - e3^2)*u + 2*(e1*e2 - e3*e0)*v + 2*(e1*e3 + e2*e0)*w;
pe_dot = 2*(e1*e2 + e3*e0)*u + (e2^2 + e0^2 - e1^2 - e3^2)*v + 2*(e2*e3 - e1*e0)*w;
pd_dot = 2*(e1*e3 - e2*e0)*u + 2*(e2*e3 + e1*e0)*v + (e3^2 + e0^2 - e1^2 - e2^2)*w;
% position dynamics
u_dot = r*v - q*w + fx/mass;
v_dot = p*w - r*u + fy/mass;
w_dot = q*u - p*v + fz/mass;
% rotational kinematics
e0_dot = (-p*e1 - q*e2 - r*e3)/2;
e1_dot = (p*e0 + r*e2 - q*e3)/2;
e2_dot = (q*e0 - r*e1 + p*e3)/2;
e3_dot = (r*e0 + q*e1 - p*e2)/2;
% rotational dynamics
p_dot = gamma1*p*q - gamma2*q*r + gamma3*l + gamma4*n;
q_dot = gamma5*p*r - gamma6*(p*p-r*r) + m/Jy;
r_dot = gamma7*p*q - gamma1*q*r + gamma4*l + gamma8*n;
% collect all the derivaties of the states
xdot = [pn_dot; pe_dot; pd_dot; u_dot; v_dot; w_dot;...
e0_dot; e1_dot; e2_dot; e3_dot; p_dot; q_dot; r_dot];
end
function self=update_true_state(self, forces_moments)
eulerAngles = Quaternion2Euler(self.state(7:10));
self.true_state.pn = self.state(1); % pn
self.true_state.pe = self.state(2); % pe
self.true_state.h = -self.state(3); % pd
self.true_state.phi = eulerAngles(1); % phi
self.true_state.theta = eulerAngles(2); % theta
self.true_state.psi = eulerAngles(3); % psi
self.true_state.p = self.state(11); % p
self.true_state.q = self.state(12); % q
self.true_state.r = self.state(13); % r
self.true_state.Vg = norm(self.state(4:6)); % Vg
self.true_state.Va = forces_moments(7); % Va
self.true_state.alpha = forces_moments(8); % Angle of attack
self.true_state.beta = forces_moments(9); % Side-slip angle
self.true_state.wn = forces_moments(10); % w_n
self.true_state.we = forces_moments(11); % w_e
self.true_state.wd = forces_moments(12); % w_d
self.true_state.chi = atan2(forces_moments(7)*sin(eulerAngles(3)) + forces_moments(11), forces_moments(7)*cos(eulerAngles(3)) + forces_moments(10));
end
end
end
⛄ 运行结果
⛄ 参考文献
[1] 王永林. Matlab/Simulink环境下无人机全过程飞行仿真技术研究[D]. 南京航空航天大学.
[2] 杨剑锋, 黄创绵, 李小兵,等. 面向环境适应性的无人机飞行姿态 模拟器设计与仿真[J]. 中国测试, 2018, 44(8):7.
[3] 刘婕, 易生勇. 基于Matlab/Simulink的无人机飞行仿真研究[J]. 自动化信息, 2012(8):2.
[4] 王明杰, 张建华, 顾仁涛,等. 一种基于无人机测试的风场模拟发生装置:, CN216645782U[P]. 2022.
[5] 曹良秋, 吴立巍, 余建虎. 基于无人机飞行参数的风场估算技术研究[J]. 科技创新导报, 2018, 15(6):5.
[6] 行鸿彦, 侯天浩. 一种基于多旋翼无人机平台的测风装置:, CN109178300A[P]. 2019.