@@ -186,8 +186,8 @@ def attitude2force_torque(
186186 prev_ang_vel: Previous angular velocity in rad/s.
187187 prev_ang_vel_des: Previous angular velocity command in rad/s.
188188 L: Distance from the center of the quadrotor to the center of the rotor in m.
189- KM: Torque constant in Nm/rad/s^2 .
190- KF: Force constant in N/rad/s^2 .
189+ KM: Torque constant ( Nm/RPM) .
190+ KF: Force constant (N/RPM) .
191191 mixing_matrix: Mixing matrix for the motor forces with shape (4, 3).
192192
193193 Returns:
@@ -252,14 +252,14 @@ def attitude2force_torque(
252252 # controllers within drone_models, we still want to return SI forces and torques. We thus need
253253 # to convert the legacy output to SI units.
254254 # l. 310 ff
255- torque_des = motor_forces @ mixing_matrix * xp .stack ([L , L , KM / KF ])
255+ torque_des = ( mixing_matrix @ motor_forces [..., None ])[..., 0 ] * xp .stack ([L , L , KM / KF ])
256256 force_des = xp .sum (motor_forces , axis = - 1 )[..., None ]
257257 return force_des , torque_des , r_int_error
258258
259259
260260def force_torque_pwms2pwms (force_pwm : Array , torque_pwm : Array , mixing_matrix : Array ) -> Array :
261261 """Convert desired collective thrust and torques to rotor speeds using legacy behavior."""
262- return force_pwm [..., None ] + (mixing_matrix @ torque_pwm [..., None ])[..., 0 ]
262+ return force_pwm [..., None ] + (torque_pwm @ mixing_matrix )
263263
264264
265265@register_controller_parameters (ForceTorqueParams )
@@ -293,8 +293,8 @@ def force_torque2rotor_vel(
293293 thrust_min: Minimum thrust in N.
294294 thrust_max: Maximum thrust in N.
295295 L: Distance from the center of the quadrotor to the center of the rotor in m.
296- KM: Torque constant in Nm/rad/s^2 .
297- KF: Force constant in N/rad/s^2 .
296+ KM: Torque constant ( Nm/RPM) .
297+ KF: Force constant (N/RPM) .
298298 mixing_matrix: Mixing matrix for the motor forces with shape (4, 3).
299299
300300 Returns:
@@ -303,7 +303,7 @@ def force_torque2rotor_vel(
303303 xp = array_namespace (torque )
304304 assert torque .shape [- 1 ] == 3 , f"Torque must have shape (..., 3), but has { torque .shape } "
305305 assert force .shape [- 1 ] == 1 , f"Force must have shape (..., 1), but has { force .shape } "
306- torque_forces = (mixing_matrix @ ( torque * xp .asarray ([L , L , KM / KF ]))[..., None ])[..., 0 ]
306+ torque_forces = (torque * xp .asarray ([1 / L , 1 / L , KF / KM ])) @ mixing_matrix
307307 motor_forces = (torque_forces + force ) / 4
308308 # Clip motor forces on the thrust instead of PWM level.
309309 motor_forces = xp .where (xp .all (force == 0 ), 0.0 , xp .clip (motor_forces , thrust_min , thrust_max ))
0 commit comments