@@ -37,14 +37,14 @@ def dynamics(
3737 J_inv : Array ,
3838 KF : Array ,
3939 KM : Array ,
40- rotor_coef : Array ,
40+ thrust_time_coef : Array ,
4141 acc_coef : Array ,
4242 cmd_f_coef : Array ,
4343 rpy_coef : Array ,
4444 rpy_rates_coef : Array ,
4545 cmd_rpy_coef : Array ,
4646 drag_linear_coef : Array ,
47- drag_abs_linear_coef : Array ,
47+ drag_square_coef : Array ,
4848) -> tuple [Array , Array , Array , Array , Array | None ]:
4949 """The fitted double integrator (DI) model with optional motor delay (D).
5050
@@ -66,14 +66,14 @@ def dynamics(
6666 J_inv: Inverse inertia matrix (1/kg m^2).
6767 KF: Motor force constant (N/rad^2).
6868 KM: Motor torque constant (Nm/rad^2).
69- rotor_coef : Coefficient for the rotor dynamics (1/s).
69+ thrust_time_coef : Coefficient for the rotor dynamics (1/s).
7070 acc_coef: Coefficient for the acceleration (1/s^2).
7171 cmd_f_coef: Coefficient for the collective thrust (N/rad^2).
7272 rpy_coef: Coefficient for the roll pitch yaw dynamics (1/s).
7373 rpy_rates_coef: Coefficient for the roll pitch yaw rates dynamics (1/s^2).
7474 cmd_rpy_coef: Coefficient for the roll pitch yaw command dynamics (1/s).
7575 drag_linear_coef: Coefficient for the linear drag (1/s).
76- drag_abs_linear_coef : Coefficient for the absolute linear drag (1/s).
76+ drag_square_coef : Coefficient for the square drag (1/s).
7777
7878 Returns:
7979 The derivatives of all state variables.
@@ -84,25 +84,31 @@ def dynamics(
8484 mass , gravity_vec , KF , KM , J , J_inv = to_xp (
8585 mass , gravity_vec , KF , KM , J , J_inv , xp = xp , device = device
8686 )
87- rotor_coef , acc_coef , cmd_f_coef = to_xp (rotor_coef , acc_coef , cmd_f_coef , xp = xp , device = device )
87+ thrust_time_coef , acc_coef , cmd_f_coef = to_xp (
88+ thrust_time_coef , acc_coef , cmd_f_coef , xp = xp , device = device
89+ )
8890 rpy_coef , rpy_rates_coef , cmd_rpy_coef = to_xp (
8991 rpy_coef , rpy_rates_coef , cmd_rpy_coef , xp = xp , device = device
9092 )
91- drag_linear_coef , drag_abs_linear_coef = to_xp (
92- drag_linear_coef , drag_abs_linear_coef , xp = xp , device = device
93+ drag_linear_coef , drag_square_coef = to_xp (
94+ drag_linear_coef , drag_square_coef , xp = xp , device = device
9395 )
9496 cmd_f = cmd [..., - 1 ]
95- cmd_rotor_vel = motor_force2rotor_vel (cmd_f / 4 , KF )
97+ # cmd_rotor_vel = motor_force2rotor_vel(cmd_f / 4, KF)
98+ cmd_rotor_vel = cmd_f # this is just a hack for testing TODO remove
9699 cmd_rpy = cmd [..., 0 :3 ]
97100 rot = R .from_quat (quat )
98101 euler_angles = rot .as_euler ("xyz" )
99102
100103 if rotor_vel is None :
101104 rotor_vel , rotor_vel_dot = cmd_rotor_vel [..., None ], None
102105 else :
103- rotor_vel_dot = 1 / rotor_coef * (cmd_rotor_vel [..., None ] - rotor_vel ) - KM * rotor_vel ** 2
106+ rotor_vel_dot = (
107+ 1 / thrust_time_coef * (cmd_rotor_vel [..., None ] - rotor_vel )
108+ ) # - KM * rotor_vel**2
104109
105110 forces_motor = KF * xp .sum (rotor_vel ** 2 , axis = - 1 )
111+ forces_motor = rotor_vel [..., 0 ]
106112 thrust = acc_coef + cmd_f_coef * forces_motor
107113
108114 drone_z_axis = rot .inv ().as_matrix ()[..., - 1 , :]
@@ -112,7 +118,7 @@ def dynamics(
112118 1 / mass * thrust [..., None ] * drone_z_axis
113119 + gravity_vec
114120 + 1 / mass * drag_linear_coef * vel
115- + 1 / mass * drag_abs_linear_coef * vel * xp .abs (vel )
121+ + 1 / mass * drag_square_coef * vel * xp .abs (vel )
116122 )
117123 if dist_f is not None :
118124 vel_dot = vel_dot + dist_f / mass
@@ -149,14 +155,14 @@ def symbolic_dynamics(
149155 J_inv : Array ,
150156 KF : Array ,
151157 KM : Array ,
152- rotor_coef : Array ,
158+ thrust_time_coef : Array ,
153159 acc_coef : Array ,
154160 cmd_f_coef : Array ,
155161 rpy_coef : Array ,
156162 rpy_rates_coef : Array ,
157163 cmd_rpy_coef : Array ,
158164 drag_linear_coef : Array ,
159- drag_abs_linear_coef : Array ,
165+ drag_square_coef : Array ,
160166) -> tuple [cs .MX , cs .MX , cs .MX , cs .MX ]:
161167 """The fitted double integrator (DI) model with optional motor delay (D).
162168
@@ -176,11 +182,15 @@ def symbolic_dynamics(
176182 # Defining the dynamics function
177183 if model_rotor_vel :
178184 # motor_force2rotor_vel
179- cmd_rotor_vel = cs .sqrt (symbols .cmd_thrust / 4 / KF )
185+ # cmd_rotor_vel = cs.sqrt(symbols.cmd_thrust / 4 / KF)
186+ cmd_rotor_vel = symbols .cmd_thrust # this is just a hack for testing TODO remove
180187 rotor_vel_dot = (
181- 1 / rotor_coef * (cmd_rotor_vel - symbols .rotor_vel ) - KM * symbols .rotor_vel ** 2
188+ 1
189+ / thrust_time_coef
190+ * (cmd_rotor_vel - symbols .rotor_vel ) # - KM * symbols.rotor_vel**2
182191 )
183- forces_motor = KF * cs .sum1 (symbols .rotor_vel ** 2 )
192+ # forces_motor = KF * cs.sum1(symbols.rotor_vel**2)
193+ forces_motor = symbols .rotor_vel [0 ]
184194 else :
185195 forces_motor = symbols .cmd_thrust
186196 # Creating force vector
@@ -192,7 +202,7 @@ def symbolic_dynamics(
192202 symbols .rot @ forces_motor_vec / mass
193203 + gravity_vec
194204 + 1 / mass * drag_linear_coef * symbols .vel
195- + 1 / mass * drag_abs_linear_coef * symbols .vel * cs .fabs (symbols .vel )
205+ + 1 / mass * drag_square_coef * symbols .vel * cs .fabs (symbols .vel )
196206 )
197207 if model_dist_f :
198208 # Adding force disturbances to the state
0 commit comments