w x mV = F ... eq.(1.136),(2.31)*/ AccelerationType acceleration_in_body_frame( const VelocityType& body_velocity, const EulerType& angle, const AngularVelocityType& body_angular_velocity, double thrust, double mass /* 0 is not allowed */, double gravity, /* usually 9.8 > 0*/ double drag, /* air friction of 1-st order(-d1*v) counter to velocity */ { assert(!is_zero(mass)); using std::sin; using std::cos; const auto c_phi = cos(angle.phi), s_phi = sin(angle.phi), c_theta = cos(angle.theta), s_theta = sin(angle.theta); const auto [u, v, w] = body_velocity; const auto [p, q, r] = body_angular_velocity; const auto T = thrust; const auto m = mass; const auto g = gravity; //... 引数を数式で使われている 変数⽂字に全部バラす 内部でも assert かけまくる 引数は,型名と合わせ技で 意味を伝える名前 (ソフトウェアエンジニア向け)
force is (p, q, r) x (u, v, w). * * Difference with the 'ground' version is that * (1) 'g' is broken down to x, y, z components. * (2) T is only relavant to z-axis. * (3) Coriolis force(using uvw,pqr) IS needed(because the body frame is rotating!) */ /*****************************************************************/ double dot_u = - g * s_theta - (q*w - r*v) - d/m * u; double dot_v = + g * c_theta * s_phi - (r*u - p*w) - d/m * v; double dot_w = -T/m + g * c_theta * c_phi - (p*v - q*u) - d/m * w; /*****************************************************************/ return {dot_u, dot_v, dot_w}; } 教科書の式番号 最も⽬レビューしやすいように できるだけ数式そのまま. (制御エンジニア向け)