SKILL.md
Motor Model and Dynamics Simulation
Overview
Two modules form the physics layer of the simulator:
- Motor model — maps desired
[F, Mx, My, Mz]→ desired motor RPMs → applies first-order lag → returns actual thrust and moments - Dynamics — nonlinear equations of motion; given forces and moments, returns the 16-element state derivative for ODE integration
Motor Model
Propeller Allocation Matrix (X-frame quadrotor)
The 4×4 allocation matrix maps [F, Mx, My, Mz] to squared motor RPMs. For an X-frame with arm length d, thrust coefficient cT, and torque coefficient cQ:
motor: 1 2 3 4
Thrust: +cT +cT +cT +cT
Roll (Mx): 0 +d·cT 0 -d·cT
Pitch (My): -d·cT 0 +d·cT 0
Yaw (Mz): -cQ +cQ -cQ +cQ
Implementation Logic
- Build the 4×4
prop_matrixfromcT,cQ, andd. - Solve
prop_matrix @ rpm_sq = [F, Mx, My, Mz]forrpm_sq(desired squared RPMs). - Take
sqrtof each element (clamp negatives to 0 first), then clip to[rpm_min, rpm_max]. - Apply first-order motor lag:
rpm_dot = km * (rpm_desired - rpm_current). - Compute actual force/moment using
prop_matrix @ (motor_rpm ** 2)and return(F_actual, M_actual, rpm_dot).
Dynamics (Equations of Motion)
State vector (16,)
| Indices | Meaning |
|---|---|
| 0:3 | Position [x, y, z] |
| 3:6 | Velocity [vẋ, vẏ, vż] |
