1111
1212import drone_models .symbols as symbols
1313from drone_models .core import supports
14- from drone_models .transform import motor_force2rotor_vel
1514from drone_models .utils import rotation , to_xp
1615
1716if TYPE_CHECKING :
@@ -33,9 +32,7 @@ def dynamics(
3332 gravity_vec : Array ,
3433 J : Array ,
3534 J_inv : Array ,
36- KF : Array ,
37- KM : Array ,
38- rotor_coef : Array ,
35+ thrust_time_coef : Array ,
3936 acc_coef : Array ,
4037 cmd_f_coef : Array ,
4138 rpy_coef : Array ,
@@ -60,9 +57,7 @@ def dynamics(
6057 [0, 0, -9.81].
6158 J: Inertia matrix (kg m^2).
6259 J_inv: Inverse inertia matrix (1/kg m^2).
63- KF: Motor force constant (N/rad^2).
64- KM: Motor torque constant (Nm/rad^2).
65- rotor_coef: Coefficient for the rotor dynamics (1/s).
60+ thrust_time_coef: Coefficient for the rotor dynamics (1/s).
6661 acc_coef: Coefficient for the acceleration (1/s^2).
6762 cmd_f_coef: Coefficient for the collective thrust (N/rad^2).
6863 rpy_coef: Coefficient for the roll pitch yaw dynamics (1/s).
@@ -75,26 +70,26 @@ def dynamics(
7570 xp = array_namespace (pos )
7671 # Convert constants to the correct framework and device
7772 device = xp_device (pos )
78- mass , gravity_vec , KF , KM , J , J_inv = to_xp (
79- mass , gravity_vec , KF , KM , J , J_inv , xp = xp , device = device
73+ mass , gravity_vec , J , J_inv = to_xp (mass , gravity_vec , J , J_inv , xp = xp , device = device )
74+ thrust_time_coef , acc_coef , cmd_f_coef = to_xp (
75+ thrust_time_coef , acc_coef , cmd_f_coef , xp = xp , device = device
8076 )
81- rotor_coef , acc_coef , cmd_f_coef = to_xp (rotor_coef , acc_coef , cmd_f_coef , xp = xp , device = device )
8277 rpy_coef , rpy_rates_coef , cmd_rpy_coef = to_xp (
8378 rpy_coef , rpy_rates_coef , cmd_rpy_coef , xp = xp , device = device
8479 )
8580
8681 cmd_f = cmd [..., - 1 ]
87- cmd_rotor_vel = motor_force2rotor_vel (cmd_f / 4 , KF )
8882 cmd_rpy = cmd [..., 0 :3 ]
8983 rot = R .from_quat (quat )
9084 euler_angles = rot .as_euler ("xyz" )
9185
86+ # Note that we are abusing the rotor_vel state as the thrust
9287 if rotor_vel is None :
93- rotor_vel , rotor_vel_dot = cmd_rotor_vel [..., None ], None
88+ rotor_vel , rotor_vel_dot = cmd_f [..., None ], None
9489 else :
95- rotor_vel_dot = 1 / rotor_coef * (cmd_rotor_vel [..., None ] - rotor_vel ) - KM * rotor_vel ** 2
90+ rotor_vel_dot = 1 / thrust_time_coef * (cmd_f [..., None ] - rotor_vel )
9691
97- forces_motor = KF * xp . sum ( rotor_vel ** 2 , axis = - 1 )
92+ forces_motor = rotor_vel [..., 0 ]
9893 thrust = acc_coef + cmd_f_coef * forces_motor
9994
10095 drone_z_axis = rot .as_matrix ()[..., - 1 ]
@@ -135,9 +130,7 @@ def symbolic_dynamics(
135130 gravity_vec : Array ,
136131 J : Array ,
137132 J_inv : Array ,
138- KF : Array ,
139- KM : Array ,
140- rotor_coef : Array ,
133+ thrust_time_coef : Array ,
141134 acc_coef : Array ,
142135 cmd_f_coef : Array ,
143136 rpy_coef : Array ,
@@ -160,13 +153,18 @@ def symbolic_dynamics(
160153 cmd_rpy = cs .vertcat (symbols .cmd_roll , symbols .cmd_pitch , symbols .cmd_yaw )
161154
162155 # Defining the dynamics function
156+ # Note that we are abusing the rotor_vel state as the thrust
163157 if model_rotor_vel :
164158 # motor_force2rotor_vel
165- cmd_rotor_vel = cs .sqrt (symbols .cmd_thrust / 4 / KF )
159+ # cmd_rotor_vel = cs.sqrt(symbols.cmd_thrust / 4 / KF)
160+ cmd_rotor_vel = symbols .cmd_thrust # this is just a hack for testing TODO remove
166161 rotor_vel_dot = (
167- 1 / rotor_coef * (cmd_rotor_vel - symbols .rotor_vel ) - KM * symbols .rotor_vel ** 2
162+ 1
163+ / thrust_time_coef
164+ * (cmd_rotor_vel - symbols .rotor_vel ) # - KM * symbols.rotor_vel**2
168165 )
169- forces_motor = KF * cs .sum1 (symbols .rotor_vel ** 2 )
166+ # forces_motor = KF * cs.sum1(symbols.rotor_vel**2)
167+ forces_motor = symbols .rotor_vel [0 ]
170168 else :
171169 forces_motor = symbols .cmd_thrust
172170 # Creating force vector
0 commit comments