当前位置:   article > 正文

MATLAB - 四旋翼飞行器动力学方程_matlab飞行动力学分析

matlab飞行动力学分析

系列文章目录

 


前言

本例演示了如何使用 Symbolic Math Toolbox™(符号数学工具箱)推导四旋翼飞行器的连续时间非线性模型。具体来说,本例讨论了 getQuadrotorDynamicsAndJacobian 脚本,该脚本可生成四旋翼状态函数及其雅各布函数。这些函数将在使用非线性模型预测控制(模型预测控制工具箱)控制四旋翼飞行器的示例中使用。

四旋翼飞行器又称四旋翼直升机,是一种拥有四个旋翼的直升机。从四旋翼飞行器的质量中心出发,旋翼呈等距离的正方形排列。四旋翼的运动是通过调整四个旋翼的角速度来控制的,而四个旋翼是由电动马达带动旋转的。四旋翼飞行器动力学数学模型可从牛顿-欧拉方程和欧拉-拉格朗日方程中导出 [1]。

 


 

一、定义状态变量和参数

如图所示,四旋翼飞行器有六个自由度(三个线性坐标和三个角度坐标),四个控制输入。

dc20ac0f174e48139a28b58ed877395d.png

四旋翼飞行器的 12 个状态是

eq?%5Cleft%28x%2Cy%2Cz%2C%5Cphi%5C%2C%2C%5Ctheta%2C%5Cpsi%2C%5Cdot%7Bx%7D%2C%5Cdot%7By%7D%2C%5Cdot%7B%5C%20z%7D%2C%5Cdot%7B%5Cphi%7D%2C%5Cdot%7B%5Ctheta%7D%2C%5Cdot%7B%5Cpsi%7D%5Cright%29%5E%7BT%7D%2C

其中

eq?%5Cxi%3D%28x%2Cy%2Cz%29%5E%7B%5Cmathrm%7BT%7D%7D 表示线性位置。

eq?%5Ceta%3D%5Cleft%28%5Cphi%5C%2C%2C%5Ctheta%2C%5Cpsi%5Cright%29%5E%7B%5Cmathrm%7BT%7D%7D 分别表示滚转角、俯仰角和偏航角。

eq?%5Cleft%28%5Cdot%7Bx%7D%2C%5Cdot%7By%7D%2C%5Cdot%7Bz%7D%2C%5Cdot%7B%5Cphi%7D%2C%5Cdot%7B%5Ctheta%7D%2C%5Cdot%7B%5Cpsi%7D%5Cright%29%5E%7BT%7D 表示线速度和角速度,或线性位置和角度位置的时间导数。

四旋翼飞行器的运动参数为

eq?%28u_1%2Cu_2%2Cu_3%2Cu_4%29%3D%5Cleft%28%5Comega_%7B1%7D%5E%7B2%7D%2C%5Comega_%7B2%7D%5E%7B2%7D%2C%5Comega_%7B3%7D%5E%7B2%7D%2C%5Comega_%7B4%7D%5E%7B2%7D%5Cright%29 代表四个旋翼的角速度平方。

eq?%28I_%7B%7Bxx%7D%7D%2CI_%7B%7Byy%7D%7D%2CI_%7B%7Bzz%7D%7D%29 代表机身坐标系中转动惯量矩阵的对角元素。

(k,l,m,b,g)代表升力常数、转子与质量中心的距离、四旋翼质量、阻力常数和重力。

前四个参数 eq?%28u_1%2Cu_2%2Cu_3%2Cu_4%29 是控制输入或控制四旋翼飞行器轨迹的操纵变量。其余参数固定为给定值。

二、定义变换矩阵和科里奥利矩阵

定义惯性坐标系和主体坐标系之间的变换矩阵。需要这些变换矩阵来描述四旋翼飞行器在两个坐标系中的运动。四旋翼飞行器的 12 个状态在惯性系中定义,旋转惯性矩阵在机身系中定义。

创建符号函数来表示随时间变化的角度。在按照 [1] 进行的数学推导中,需要这种明确的时间依赖性来评估时间导数。定义矩阵 Wη 以将角速度从惯性系转换到体坐标系。定义旋转矩阵 R,使用局部函数部分定义的 rotationMatrixEulerZYX 函数将线性力从机身坐标系转换到惯性坐标系。创建符号矩阵来表示这些变换矩阵。

  1. % Create symbolic functions for time-dependent angles
  2. % phi: roll angle
  3. % theta: pitch angle
  4. % psi: yaw angle
  5. syms phi(t) theta(t) psi(t)
  6. % Transformation matrix for angular velocities from inertial frame
  7. % to body frame
  8. W = [ 1, 0, -sin(theta);
  9. 0, cos(phi), cos(theta)*sin(phi);
  10. 0, -sin(phi), cos(theta)*cos(phi) ];
  11. % Rotation matrix R_ZYX from body frame to inertial frame
  12. R = rotationMatrixEulerZYX(phi,theta,psi);

 求用于表示惯性系中旋转能量的雅各布矩阵 eq?J%3DW_%7B%5Ceta%7D%5E%7BT%7D%5C%2CI%5C%2CW_%7B%5Ceta%7D

  1. % Create symbolic variables for diagonal elements of inertia matrix
  2. syms Ixx Iyy Izz
  3. % Jacobian that relates body frame to inertial frame velocities
  4. I = [Ixx, 0, 0; 0, Iyy, 0; 0, 0, Izz];
  5. J = W.'*I*W;

接下来,找出科里奥利矩阵 eq?C%28%5Ceta%2C%5Cdot%7B%5Ceta%7D%29%3D%5Cfrac%7B%5Cmathrm%7Bd%7D%7D%7B%5Cmathrm%7Bd%7Dt%7DJ-%5Cfrac%7B1%7D%7B2%7D%5Cfrac%7B%5Cpartial%7D%7B%5Cpartial%5Ceta%7D%5Cleft%28%5Cdot%7B%5Ceta%7D%5E%7B%5CUpsilon%7DJ%5Cright%29,它包含角欧拉-拉格朗日方程中的陀螺项和向心项。使用符号 diff 和 jacobian 函数进行微分运算。为了简化微分后科里奥利矩阵的符号,可以用 eq?C%28%5Ceta%2C%7B%5Cdot%7B%5Ceta%7D%7D%29中的显式时间相关项替换为符号变量(代表特定时间的某些值)。这种简化的符号使这里的结果更容易与 [1] 中的推导进行比较。 

  1. % Coriolis matrix
  2. dJ_dt = diff(J);
  3. h_dot_J = [diff(phi,t), diff(theta,t), diff(psi,t)]*J;
  4. grad_temp_h = transpose(jacobian(h_dot_J,[phi theta psi]));
  5. C = dJ_dt - 1/2*grad_temp_h;
  6. C = subsStateVars(C,t);

三、证明科里奥利矩阵定义是一致的

科里奥利矩阵 eq?C%28%5Ceta%2C%7B%5Cdot%7B%5Ceta%7D%7D%29 很容易用上一节的符号工作流程推导出来。然而,这里的 eq?C%28%5Ceta%2C%7B%5Cdot%7B%5Ceta%7D%7D%29 定义与 [1] 中的不同,后者使用克里斯托弗符号推导科里奥利矩阵。由于 eq?C%28%5Ceta%2C%7B%5Cdot%7B%5Ceta%7D%7D%29 并非唯一,因此可以有多种定义方法。但是,欧拉-拉格朗日方程中使用的 eq?C%28%5Ceta%2C%5Cdot%7B%5Ceta%7D%29%5C%3B%5Cdot%7B%5Ceta%7D 项必须是唯一的。本节将证明 eq?C%28%5Ceta%2C%7B%5Cdot%7B%5Ceta%7D%7D%29 的符号定义与 [1] 中的定义是一致的,即 eq?C%28%5Ceta%2C%5Cdot%7B%5Ceta%7D%29%5C%3B%5Cdot%7B%5Ceta%7D项在两个定义中在数学上是相等的。

利用上一节中得出的 eq?C%28%5Ceta%2C%7B%5Cdot%7B%5Ceta%7D%7D%29 的符号定义来评估 eq?C%28%5Ceta%2C%5Cdot%7B%5Ceta%7D%29%5C%3B%5Cdot%7B%5Ceta%7D 项。

  1. % Evaluate C times etadot using symbolic definition
  2. phidot = subsStateVars(diff(phi,t),t);
  3. thetadot = subsStateVars(diff(theta,t),t);
  4. psidot = subsStateVars(diff(psi,t),t);
  5. Csym_etadot = C*[phidot; thetadot; psidot];

使用 [1] 中得出的 eq?C%28%5Ceta%2C%7B%5Cdot%7B%5Ceta%7D%7D%29 的定义,对 eq?C%28%5Ceta%2C%5Cdot%7B%5Ceta%7D%29%5C%3B%5Cdot%7B%5Ceta%7D 项进行评估。

  1. % Evaluate C times etadot using reference paper definition
  2. C11 = 0;
  3. C12 = (Iyy - Izz)*(thetadot*cos(phi)*sin(phi) + psidot*sin(phi)^2*cos(theta)) ...
  4. + (Izz - Iyy)*(psidot*cos(phi)^2*cos(theta)) - Ixx*psidot*cos(theta);
  5. C13 = (Izz - Iyy)*psidot*cos(phi)*sin(phi)*cos(theta)^2;
  6. C21 = (Izz - Iyy)*(thetadot*cos(phi)*sin(phi) + psidot*sin(phi)^2*cos(theta)) ...
  7. + (Iyy - Izz)*psidot*cos(phi)^2*cos(theta) + Ixx*psidot*cos(theta);
  8. C22 = (Izz - Iyy)*phidot*cos(phi)*sin(phi);
  9. C23 = - Ixx*psidot*sin(theta)*cos(theta) + Iyy*psidot*sin(phi)^2*sin(theta)*cos(theta) ...
  10. + Izz*psidot*cos(phi)^2*sin(theta)*cos(theta);
  11. C31 = (Iyy - Izz)*psidot*cos(theta)^2*sin(phi)*cos(phi) - Ixx*thetadot*cos(theta);
  12. C32 = (Izz - Iyy)*(thetadot*cos(phi)*sin(phi)*sin(theta) + phidot*sin(phi)^2*cos(theta)) ...
  13. + (Iyy - Izz)*phidot*cos(phi)^2*cos(theta) + Ixx*psidot*sin(theta)*cos(theta) ...
  14. - Iyy*psidot*sin(phi)^2*sin(theta)*cos(theta) - Izz*psidot*cos(phi)^2*sin(theta)*cos(theta);
  15. C33 = (Iyy - Izz)*phidot*cos(phi)*sin(phi)*cos(theta)^2 ...
  16. - Iyy*thetadot*sin(phi)^2*cos(theta)*sin(theta) ...
  17. - Izz*thetadot*cos(phi)^2*cos(theta)*sin(theta) + Ixx*thetadot*cos(theta)*sin(theta);
  18. Cpaper = [C11, C12, C13; C21, C22, C23; C31 C32 C33];
  19. Cpaper_etadot = Cpaper*[phidot; thetadot; psidot];
  20. Cpaper_etadot = subsStateVars(Cpaper_etadot,t);

证明这两个定义对 eq?C%28%5Ceta%2C%5Cdot%7B%5Ceta%7D%29%5C%3B%5Cdot%7B%5Ceta%7D 项给出了相同的结果。

tf_Cdefinition = isAlways(Cpaper_etadot == Csym_etadot)
  1. tf_Cdefinition = 3x1 logical array
  2. 1
  3. 1
  4. 1

四、查找运动方程

求出 12 个状态的运动方程。

根据 [1],求出扭矩 τ B 在滚转、俯仰和偏航角方向上的扭矩:

  • 通过降低第 2 个转子的速度和提高第 4 个转子的速度来设定滚转运动。
  • 通过降低第 1 个转子的速度和提高第 3 个转子的速度来设置俯仰运动。
  • 偏航运动是通过增大两个相对旋翼的速度和减小另外两个旋翼的速度来实现的。

求转子 T 在机身 Z 轴方向上的总推力。

  1. % Define fixed parameters and control input
  2. % k: lift constant
  3. % l: distance between rotor and center of mass
  4. % m: quadrotor mass
  5. % b: drag constant
  6. % g: gravity
  7. % ui: squared angular velocity of rotor i as control input
  8. syms k l m b g u1 u2 u3 u4
  9. % Torques in the direction of phi, theta, psi
  10. tau_beta = [l*k*(-u2+u4); l*k*(-u1+u3); b*(-u1+u2-u3+u4)];
  11. % Total thrust
  12. T = k*(u1+u2+u3+u4);

接下来,创建符号函数来表示随时间变化的位置。为线性位置、角度及其时间导数定义 12 个状态 eq?%5Cleft%5B%5Cxi%3B%5Ceta%3B%5C%3B%7B%5Cdot%7B%5Cxi%7D%7D%3B%5C%3B%7B%5Cdot%7B%5Ceta%7D%7D%5Cright%5D。定义好状态后,用显式时间项代替,以简化符号。

  1. % Create symbolic functions for time-dependent positions
  2. syms x(t) y(t) z(t)
  3. % Create state variables consisting of positions, angles,
  4. % and their derivatives
  5. state = [x; y; z; phi; theta; psi; diff(x,t); diff(y,t); ...
  6. diff(z,t); diff(phi,t); diff(theta,t); diff(psi,t)];
  7. state = subsStateVars(state,t);

建立描述 12 个状态 eq?f%3D%5Cleft%5B%5C%2C%5Cdot%7B%5Cxi%7D%3B%5C%2C%5Cdot%7B%5Ceta%7D%5C%2C%3B%5C%2C%5Cddot%7B%5Cxi%7D%5C%2C%3B%5C%2C%5Cddot%7B%5Ceta%7D%5C%2C%5Cright%5D 的时间导数的 12 个运动方程。线性加速度的微分方程为 m.,角加速度的微分方程为 eq?%5Cddot%7B%5Ceta%7D%3DJ%5E%7B-1%7D%5Cbigl%28%5Ctau%20B-C%28%5Ceta%2C%5Cdot%7B%5Ceta%7D%29%5C%2C%5Cdot%7B%5Ceta%7D%5C%2C%5Cbigr%29%5C%2C.。代入明确的时间相关项,以简化符号。

  1. f = [ % Set time-derivative of the positions and angles
  2. state(7:12);
  3. % Equations for linear accelerations of the center of mass
  4. -g*[0;0;1] + R*[0;0;T]/m;
  5. % Euler–Lagrange equations for angular dynamics
  6. inv(J)*(tau_beta - C*state(10:12))
  7. ];
  8. f = subsStateVars(f,t);

在前面的步骤中,固定参数被定义为符号变量,以紧跟文献 [1] 的推导。接下来,用给定值替换固定参数。这些值用于设计四旋翼飞行器特定配置的轨迹跟踪控制器。替换固定参数后,使用简化对运动方程进行代数简化。

  1. % Replace fixed parameters with given values here
  2. IxxVal = 1.2;
  3. IyyVal = 1.2;
  4. IzzVal = 2.3;
  5. kVal = 1;
  6. lVal = 0.25;
  7. mVal = 2;
  8. bVal = 0.2;
  9. gVal = 9.81;
  10. f = subs(f, [Ixx Iyy Izz k l m b g], ...
  11. [IxxVal IyyVal IzzVal kVal lVal mVal bVal gVal]);
  12. f = simplify(f);

五、为非线性模型预测控制查找雅各布因子并生成文件

最后,使用符号数学工具箱查找非线性模型函数的解析雅各布因子并生成 MATLAB® 文件。这一步骤对于提高使用模型预测控制工具箱™ 解决轨迹跟踪非线性模型时的计算效率非常重要。更多信息,请参阅 nlmpc(模型预测控制工具箱)和 Specify Prediction Model for Nonlinear MPC(模型预测控制工具箱)。

查找状态函数相对于状态变量和控制输入的雅各布。

  1. % Calculate Jacobians for nonlinear prediction model
  2. A = jacobian(f,state);
  3. control = [u1; u2; u3; u4];
  4. B = jacobian(f,control);

生成状态函数和状态函数 Jacobians 的 MATLAB 文件。这些文件可用于设计轨迹跟踪控制器,详见《使用非线性模型预测控制(模型预测控制工具箱)控制四旋翼飞行器》。

  1. % Create QuadrotorStateFcn.m with current state and control
  2. % vectors as inputs and the state time-derivative as outputs
  3. matlabFunction(f,'File','QuadrotorStateFcn', ...
  4. 'Vars',{state,control});
  5. % Create QuadrotorStateJacobianFcn.m with current state and control
  6. % vectors as inputs and the Jacobians of the state time-derivative
  7. % as outputs
  8. matlabFunction(A,B,'File','QuadrotorStateJacobianFcn', ...
  9. 'Vars',{state,control});

您可以在 getQuadrotorDynamicsAndJacobian.m 文件中访问该脚本中的代码。

六、函数

  1. function [Rz,Ry,Rx] = rotationMatrixEulerZYX(phi,theta,psi)
  2. % Euler ZYX angles convention
  3. Rx = [ 1, 0, 0;
  4. 0, cos(phi), -sin(phi);
  5. 0, sin(phi), cos(phi) ];
  6. Ry = [ cos(theta), 0, sin(theta);
  7. 0, 1, 0;
  8. -sin(theta), 0, cos(theta) ];
  9. Rz = [cos(psi), -sin(psi), 0;
  10. sin(psi), cos(psi), 0;
  11. 0, 0, 1 ];
  12. if nargout == 3
  13. % Return rotation matrix per axes
  14. return;
  15. end
  16. % Return rotation matrix from body frame to inertial frame
  17. Rz = Rz*Ry*Rx;
  18. end
  19. function stateExpr = subsStateVars(timeExpr,var)
  20. if nargin == 1
  21. var = sym("t");
  22. end
  23. repDiff = @(ex) subsStateVarsDiff(ex,var);
  24. stateExpr = mapSymType(timeExpr,"diff",repDiff);
  25. repFun = @(ex) subsStateVarsFun(ex,var);
  26. stateExpr = mapSymType(stateExpr,"symfunOf",var,repFun);
  27. stateExpr = formula(stateExpr);
  28. end
  29. function newVar = subsStateVarsFun(funExpr,var)
  30. name = symFunType(funExpr);
  31. name = replace(name,"_Var","");
  32. stateVar = "_" + char(var);
  33. newVar = sym(name + stateVar);
  34. end
  35. function newVar = subsStateVarsDiff(diffExpr,var)
  36. if nargin == 1
  37. var = sym("t");
  38. end
  39. c = children(diffExpr);
  40. if ~isSymType(c{1},"symfunOf",var)
  41. % not f(t)
  42. newVar = diffExpr;
  43. return;
  44. end
  45. if ~any([c{2:end}] == var)
  46. % not derivative wrt t only
  47. newVar = diffExpr;
  48. return;
  49. end
  50. name = symFunType(c{1});
  51. name = replace(name,"_Var","");
  52. extension = "_" + join(repelem("d",numel(c)-1),"") + "ot";
  53. stateVar = "_" + char(var);
  54. newVar = sym(name + extension + stateVar);
  55. end

七、参考资料

[1] Raffo, Guilherme V., Manuel G. Ortega, and Francisco R. Rubio. "An integral predictive/nonlinear ℋ∞ control structure for a quadrotor helicopter". Automatica 46, no. 1 (January 2010): 29–39. https://doi.org/10.1016/j.automatica.2009.10.018.

[2] Tzorakoleftherakis, Emmanouil, and Todd D. Murphey. "Iterative sequential action control for stable, model-based control of nonlinear systems." IEEE Transactions on Automatic Control 64, no. 8 (August 2019): 3170–83. https://doi.org/10.1109/TAC.2018.2885477.

[3] Luukkonen, Teppo. "Modelling and control of quadcopter". Independent research project in applied mathematics, Aalto University, 2011.

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/925576
推荐阅读
相关标签
  

闽ICP备14008679号