first_principles
Full rigid-body physics model for a quadrotor.
This package implements Newton-Euler dynamics based on physical constants — mass, inertia, motor thrust and torque curves, arm length, and drag coefficients. The command interface is four motor angular velocities in RPM. No data fitting is required; all parameters are measurable physical quantities.
Motor forces and torques are quadratic polynomials in RPM:
When rotor dynamics are modelled, each motor RPM evolves as:
The rigid-body equations of motion are:
where \(R = {}^{\mathcal{I}}R_{\mathcal{B}}(\mathbf{q})\) is the rotation from body to world frame, and the forces and torques are:
with:
where \(D_b\) is the body-frame drag matrix, \(l\) is the motor arm length, \(J_p\) is the propeller moment of inertia, \(M\) is the \(3\times 4\) mixing matrix, and \(\mathbf{m}_z\) is its last row.
dynamics(pos, quat, vel, ang_vel, cmd, rotor_vel=None, dist_f=None, dist_t=None, *, mass, L, prop_inertia, gravity_vec, J, J_inv, rpm2thrust, rpm2torque, mixing_matrix, drag_matrix, rotor_dyn_coef)
¶
First principles model for a quatrotor.
The command is four motor angular velocities in RPM. Forces and torques are computed internally using quadratic thrust and torque curves, the mixing matrix, and the motor arm length.
Based on the quaternion model from https://www.dynsyslab.org/wp-content/papercite-data/pdf/mckinnon-robot20.pdf
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
Array
|
Position of the drone (m). |
required |
quat
|
Array
|
Quaternion of the drone (xyzw). |
required |
vel
|
Array
|
Velocity of the drone (m/s). |
required |
ang_vel
|
Array
|
Angular velocity of the drone (rad/s). |
required |
cmd
|
Array
|
Motor speeds (RPMs). |
required |
rotor_vel
|
Array | None
|
Angular velocity of the 4 motors (RPMs). If None, the commanded thrust is directly applied. If value is given, thrust dynamics are calculated. |
None
|
dist_f
|
Array | None
|
Disturbance force (N) in the world frame acting on the CoM. |
None
|
dist_t
|
Array | None
|
Disturbance torque (Nm) in the world frame acting on the CoM. |
None
|
mass
|
float
|
Mass of the drone (kg). |
required |
L
|
float
|
Distance from the CoM to the motor (m). |
required |
prop_inertia
|
float
|
Inertia of one propeller in z direction (kg m^2). |
required |
gravity_vec
|
Array
|
Gravity vector (m/s^2). We assume the gravity vector points downwards, e.g. [0, 0, -9.81]. |
required |
J
|
Array
|
Inertia matrix (kg m^2). |
required |
J_inv
|
Array
|
Inverse inertia matrix (1/kg m^2). |
required |
rpm2thrust
|
Array
|
Propeller force constant (N min^2). |
required |
rpm2torque
|
Array
|
Propeller torque constant (Nm min^2). |
required |
mixing_matrix
|
Array
|
Mixing matrix denoting the turn direction of the motors (4x3). |
required |
drag_matrix
|
Array
|
Drag matrix containing the linear drag coefficients (3x3). |
required |
rotor_dyn_coef
|
Array
|
Rotor dynamics coefficients. |
required |
Warning
Do not use quat_dot directly for integration! Only usage of ang_vel is mathematically correct. If you still decide to use quat_dot to integrate, ensure unit length! More information: https://ahrs.readthedocs.io/en/latest/filters/angular.html
Source code in drone_models/first_principles/model.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
symbolic_dynamics(model_rotor_vel=True, model_dist_f=False, model_dist_t=False, *, mass, L, prop_inertia, gravity_vec, J, J_inv, rpm2thrust, rpm2torque, mixing_matrix, rotor_dyn_coef, drag_matrix)
¶
Return CasADi symbolic expressions for the first-principles model.
Implements the same dynamics as dynamics using CasADi MX
symbolic expressions, validated to be numerically equivalent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_rotor_vel
|
bool
|
If |
True
|
model_dist_f
|
bool
|
If |
False
|
model_dist_t
|
bool
|
If |
False
|
mass
|
float
|
Drone mass in kg. |
required |
L
|
float
|
Distance from centre of mass to motor in metres. |
required |
prop_inertia
|
float
|
Moment of inertia of one propeller about its spin axis in kg m². |
required |
gravity_vec
|
Array
|
Gravity vector, shape |
required |
J
|
Array
|
Inertia matrix, shape |
required |
J_inv
|
Array
|
Inverse inertia matrix, shape |
required |
rpm2thrust
|
Array
|
Polynomial coefficients |
required |
rpm2torque
|
Array
|
Polynomial coefficients |
required |
mixing_matrix
|
Array
|
Matrix of shape |
required |
rotor_dyn_coef
|
Array
|
Four rotor dynamics coefficients |
required |
drag_matrix
|
Array
|
Diagonal |
required |
Returns:
| Type | Description |
|---|---|
MX
|
Tuple |
MX
|
|
MX
|
|
MX
|
|
tuple[MX, MX, MX, MX]
|
|
Source code in drone_models/first_principles/model.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |