Skip to content

Commit 8e8f43d

Browse files
committed
Add B500 model to so_rpy_rotor_drag model
1 parent bce9c3f commit 8e8f43d

3 files changed

Lines changed: 53 additions & 39 deletions

File tree

drone_models/so_rpy_rotor_drag/model.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

drone_models/so_rpy_rotor_drag/params.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ class SoRpyRotorDragParams(NamedTuple):
2121
J_inv: Array
2222
KF: Array
2323
KM: Array
24-
rotor_coef: Array
24+
thrust_time_coef: Array
2525
acc_coef: Array
2626
cmd_f_coef: Array
2727
rpy_coef: Array
2828
rpy_rates_coef: Array
2929
cmd_rpy_coef: Array
3030
drag_linear_coef: Array
31-
drag_abs_linear_coef: Array
31+
drag_square_coef: Array
3232

3333
@staticmethod
3434
def load(drone_model: str) -> SoRpyRotorDragParams:
Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,62 @@
11
[cf2x_L250]
22
mass = 0.033
33
gravity_vec = [0.0, 0.0, -9.81]
4-
J = [
5-
[1.68e-5, 0.0, 0.0],
6-
[0.0, 1.68e-5, 0.0],
7-
[0.0, 0.0, 2.98e-5]
8-
]
4+
J = [[1.68e-5, 0.0, 0.0], [0.0, 1.68e-5, 0.0], [0.0, 0.0, 2.98e-5]]
95
KF = 8.701227710666256e-10
106
KM = 7.94e-12
11-
rotor_coef = 0.1891
7+
thrust_time_coef = 0.1891
128
acc_coef = 0.0
139
cmd_f_coef = 1.0627
1410
rpy_coef = [-257.2, -257.2, 225.3]
1511
rpy_rates_coef = [-20.2, -20.2, -28.61]
1612
cmd_rpy_coef = [207.1, 207.1, 392.7]
1713
drag_linear_coef = -0.0177
18-
drag_abs_linear_coef = 0.0010
14+
drag_square_coef = 0.0010
1915

2016
# TODO: Check if parameters are correct
2117
[cf2x_P250]
2218
mass = 0.03454
2319
gravity_vec = [0.0, 0.0, -9.81]
24-
J = [
25-
[1.4e-5, 0.0, 0.0],
26-
[0.0, 1.4e-5, 0.0],
27-
[0.0, 0.0, 2.17e-5]
28-
]
20+
J = [[1.4e-5, 0.0, 0.0], [0.0, 1.4e-5, 0.0], [0.0, 0.0, 2.17e-5]]
2921
KF = 5.792654323957372e-10
3022
KM = 7.94e-12
31-
rotor_coef = 0.1891
23+
thrust_time_coef = 0.1891
3224
acc_coef = 0.0
3325
cmd_f_coef = 1.0627
3426
rpy_coef = [-257.2, -257.2, -225.3]
3527
rpy_rates_coef = [-20.2, -20.2, -28.61]
3628
cmd_rpy_coef = [207.1, 207.1, 392.7]
3729
drag_linear_coef = -0.0177
38-
drag_abs_linear_coef = 0.0010
30+
drag_square_coef = 0.0010
3931

4032
# TODO: Check if parameters are correct
4133
[cf2x_T350]
4234
mass = 0.03253
4335
gravity_vec = [0.0, 0.0, -9.81]
44-
J = [
45-
[1.4e-5, 0.0, 0.0],
46-
[0.0, 1.4e-5, 0.0],
47-
[0.0, 0.0, 2.17e-5]
48-
]
36+
J = [[1.4e-5, 0.0, 0.0], [0.0, 1.4e-5, 0.0], [0.0, 0.0, 2.17e-5]]
4937
KF = 1.068340683985525e-09
5038
KM = 7.94e-12
51-
rotor_coef = 0.1891
39+
thrust_time_coef = 0.1891
5240
acc_coef = 0.0
5341
cmd_f_coef = 1.0627
5442
rpy_coef = [-257.2, -257.2, -225.3]
5543
rpy_rates_coef = [-20.2, -20.2, -28.61]
5644
cmd_rpy_coef = [207.1, 207.1, 392.7]
5745
drag_linear_coef = -0.0177
58-
drag_abs_linear_coef = 0.0010
46+
drag_square_coef = 0.0010
47+
48+
49+
[cf2x_B500]
50+
mass = 0.0433777
51+
gravity_vec = [0.0, 0.0, -9.81]
52+
J = [[1.4e-5, 0.0, 0.0], [0.0, 1.4e-5, 0.0], [0.0, 0.0, 2.17e-5]]
53+
KF = 1.068340683985525e-09
54+
KM = 7.94e-12
55+
thrust_time_coef = 0.08238289
56+
acc_coef = 0.0
57+
cmd_f_coef = 0.99509171
58+
rpy_coef = [-160.5, -160.5, -109.3]
59+
rpy_rates_coef = [-10.74, -10.74, -13.69]
60+
cmd_rpy_coef = [115.2, 115.2, 154.6]
61+
drag_linear_coef = -0.02063486
62+
drag_square_coef = -0.02272605

0 commit comments

Comments
 (0)