Skip to content

Commit a2181d0

Browse files
committed
Update so_rpy_rotor models
1 parent 9637fc6 commit a2181d0

6 files changed

Lines changed: 42 additions & 113 deletions

File tree

drone_models/data/params.toml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
# This file contains all the **physical** parameters for all models.
22

33
[cf2x_L250]
4-
mass = 0.033
54
gravity_vec = [0.0, 0.0, -9.81]
5+
mass = 0.033
6+
L = 0.03253
67
J = [
78
[1.68e-5, 0.0, 0.0],
89
[0.0, 1.68e-5, 0.0],
910
[0.0, 0.0, 2.98e-5]
1011
]
1112
rpm2thrust = [0.0, 0.0, 3.16e-10] # TODO
1213
rpm2torque = [0.0, 0.0, 7.94e-12] # TODO
13-
L = 0.03253
14+
# TODO: This is an arbitrary number that leads to a working simulation. It MUST be fitted and
15+
# updated as soon as possible.
16+
thrust_tau = 0.03 # TODO value? TODO rename to rotor_tau
1417
mixing_matrix = [
1518
[-1.0, -1.0, 1.0, 1.0],
1619
[-1.0, 1.0, 1.0, -1.0],
1720
[-1.0, 1.0, -1.0, 1.0]
1821
]
19-
# TODO: This is an arbitrary number that leads to a working simulation. It MUST be fitted and
20-
# updated as soon as possible.
21-
thrust_tau = 0.03
2222

2323

2424
[cf2x_P250]
25-
mass = 0.03454
2625
gravity_vec = [0.0, 0.0, -9.81]
26+
mass = 0.03454
27+
L = 0.03253
2728
# J from IROS 2022
2829
J = [
2930
[1.4e-5, 0.0, 0.0],
@@ -32,48 +33,48 @@ J = [
3233
]
3334
rpm2thrust = [0.0, 0.0, 5.792654323957372e-10] # TODO
3435
rpm2torque = [0.0, 0.0, 7.94e-12] # TODO
35-
L = 0.03253
36+
thrust_tau = 7.2333515424212695 # TODO value? TODO rename to rotor_tau
3637
mixing_matrix = [
3738
[-1.0, -1.0, 1.0, 1.0],
3839
[-1.0, 1.0, 1.0, -1.0],
3940
[-1.0, 1.0, -1.0, 1.0]
4041
]
41-
thrust_tau = 7.2333515424212695
4242

4343

4444
[cf2x_T350]
45-
mass = 0.03454
4645
gravity_vec = [0.0, 0.0, -9.81]
46+
mass = 0.03454
47+
L = 0.03253
4748
J = [
4849
[1.4e-5, 0.0, 0.0],
4950
[0.0, 1.4e-5, 0.0],
5051
[0.0, 0.0, 2.17e-5]
5152
]
5253
rpm2thrust = [0.0, 0.0, 1.068340683985525e-09] # TODO
5354
rpm2torque = [0.0, 0.0, 7.94e-12] # TODO
54-
L = 0.03253
55+
thrust_tau = 8.719306881898989 # TODO value? TODO rename to rotor_tau
5556
mixing_matrix = [
5657
[-1.0, -1.0, 1.0, 1.0],
5758
[-1.0, 1.0, 1.0, -1.0],
5859
[-1.0, 1.0, -1.0, 1.0]
5960
]
60-
thrust_tau = 8.719306881898989
6161

6262

6363
[cf21B_500]
64-
mass = 0.04338
6564
gravity_vec = [0.0, 0.0, -9.81]
65+
mass = 0.04338
66+
L = 0.035355
6667
J = [
6768
[2.5e-5, 0.0, 0.0],
6869
[0.0, 2.8e-5, 0.0],
6970
[0.0, 0.0, 4.9e-5]
7071
]
7172
rpm2thrust = [0.0, -8.357406697944084e-07, 4.716909960828207e-10]
7273
rpm2torque = [0.0, 2.435151264350409e-09, 2.424629050055297e-12]
73-
L = 0.035355
74+
thrust2torque = 0.00593893393599368
75+
thrust_tau = 0.08 # TODO value? TODO rename to rotor_tau
7476
mixing_matrix = [
7577
[-1.0, -1.0, 1.0, 1.0],
7678
[-1.0, 1.0, 1.0, -1.0],
7779
[-1.0, 1.0, -1.0, 1.0]
78-
]
79-
thrust_tau = 0.03 # TODO
80+
]

drone_models/so_rpy/params.toml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
# TODO: Double-check yaw parameters. Currently induces weird behavior in sim
22
[cf2x_L250]
3-
mass = 0.03454
4-
gravity_vec = [0.0, 0.0, -9.81]
53
acc_coef = 0.0
64
cmd_f_coef = 1.0633
75
rpy_coef = [-286.2, -286.2, -192.9]
86
rpy_rates_coef = [-23.03, -23.03, -22.22]
97
cmd_rpy_coef = [225.6, 225.6, 323.5]
10-
J = [[1.68e-5, 0.0, 0.0], [0.0, 1.68e-5, 0.0], [0.0, 0.0, 2.98e-5]]
118

129
# TODO: Check if parameters are correct
1310
[cf2x_P250]
14-
mass = 0.03454
15-
gravity_vec = [0.0, 0.0, -9.81]
16-
J = [[1.4e-5, 0.0, 0.0], [0.0, 1.4e-5, 0.0], [0.0, 0.0, 2.17e-5]]
1711
acc_coef = 0.0
1812
cmd_f_coef = 1.0633
1913
rpy_coef = [-99.94, -130.3, 0.0]
@@ -22,9 +16,6 @@ cmd_rpy_coef = [84.73, 119.3, 0.0]
2216

2317
# TODO: Check if parameters are correct
2418
[cf2x_T350]
25-
mass = 0.03454
26-
gravity_vec = [0.0, 0.0, -9.81]
27-
J = [[1.4e-5, 0.0, 0.0], [0.0, 1.4e-5, 0.0], [0.0, 0.0, 2.17e-5]]
2819
acc_coef = 0.0
2920
cmd_f_coef = 1.0633
3021
rpy_coef = [-99.94, -130.3, 0.0]
@@ -33,9 +24,6 @@ cmd_rpy_coef = [84.73, 119.3, 0.0]
3324

3425
# TODO: Check if parameters are correct
3526
[cf2x_B500]
36-
mass = 0.043
37-
gravity_vec = [0.0, 0.0, -9.81]
38-
J = [[1.4e-5, 0.0, 0.0], [0.0, 1.4e-5, 0.0], [0.0, 0.0, 2.17e-5]]
3927
acc_coef = 0.0
4028
cmd_f_coef = 1.0633
4129
rpy_coef = [-99.94, -130.3, 0.0]

drone_models/so_rpy_rotor/model.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import drone_models.symbols as symbols
1313
from drone_models.core import supports
14-
from drone_models.transform import motor_force2rotor_vel
1514
from drone_models.utils import rotation, to_xp
1615

1716
if 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

drone_models/so_rpy_rotor/params.toml

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
[cf2x_L250]
2-
mass = 0.033
3-
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-
]
9-
KF = 8.701227710666256e-10
10-
KM = 7.94e-12
11-
rotor_coef = 0.1108
2+
thrust_time_coef = 0.1108
123
acc_coef = 0.0
134
cmd_f_coef = 1.0591
145
rpy_coef = [-257.2, -257.2, -225.3]
@@ -17,16 +8,7 @@ cmd_rpy_coef = [207.1, 207.1, 392.7]
178

189
# TODO: Check if parameters are correct
1910
[cf2x_P250]
20-
mass = 0.03454
21-
gravity_vec = [0.0, 0.0, -9.81]
22-
J = [
23-
[1.4e-5, 0.0, 0.0],
24-
[0.0, 1.4e-5, 0.0],
25-
[0.0, 0.0, 2.17e-5]
26-
]
27-
KF = 5.792654323957372e-10
28-
KM = 7.94e-12
29-
rotor_coef = 0.0654
11+
thrust_time_coef = 0.0654
3012
acc_coef = 0.1670
3113
cmd_f_coef = 0.5615
3214
rpy_coef = [-286.2, -286.2, -192.9]
@@ -35,16 +17,7 @@ cmd_rpy_coef = [225.6, 225.6, 323.5]
3517

3618
# TODO: Check if parameters are correct
3719
[cf2x_T350]
38-
mass = 0.03253
39-
gravity_vec = [0.0, 0.0, -9.81]
40-
J = [
41-
[1.4e-5, 0.0, 0.0],
42-
[0.0, 1.4e-5, 0.0],
43-
[0.0, 0.0, 2.17e-5]
44-
]
45-
KF = 1.068340683985525e-09
46-
KM = 7.94e-12
47-
rotor_coef = 0.0654
20+
thrust_time_coef = 0.0654
4821
acc_coef = 0.1670
4922
cmd_f_coef = 0.5615
5023
rpy_coef = [-286.2, -286.2, -192.9]

drone_models/so_rpy_rotor_drag/model.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ def dynamics(
3232
gravity_vec: Array,
3333
J: Array,
3434
J_inv: Array,
35-
KF: Array,
36-
KM: Array,
3735
thrust_time_coef: Array,
3836
acc_coef: Array,
3937
cmd_f_coef: Array,
@@ -61,8 +59,6 @@ def dynamics(
6159
[0, 0, -9.81].
6260
J: Inertia matrix (kg m^2).
6361
J_inv: Inverse inertia matrix (1/kg m^2).
64-
KF: Motor force constant (N/rad^2).
65-
KM: Motor torque constant (Nm/rad^2).
6662
thrust_time_coef: Coefficient for the rotor dynamics (1/s).
6763
acc_coef: Coefficient for the acceleration (1/s^2).
6864
cmd_f_coef: Coefficient for the collective thrust (N/rad^2).
@@ -78,9 +74,7 @@ def dynamics(
7874
xp = array_namespace(pos)
7975
device = xp_device(pos)
8076
# Convert constants to the correct framework and device
81-
mass, gravity_vec, KF, KM, J, J_inv = to_xp(
82-
mass, gravity_vec, KF, KM, J, J_inv, xp=xp, device=device
83-
)
77+
mass, gravity_vec, J, J_inv = to_xp(mass, gravity_vec, J, J_inv, xp=xp, device=device)
8478
thrust_time_coef, acc_coef, cmd_f_coef = to_xp(
8579
thrust_time_coef, acc_coef, cmd_f_coef, xp=xp, device=device
8680
)
@@ -91,20 +85,16 @@ def dynamics(
9185
drag_linear_coef, drag_square_coef, xp=xp, device=device
9286
)
9387
cmd_f = cmd[..., -1]
94-
# cmd_rotor_vel = motor_force2rotor_vel(cmd_f / 4, KF)
95-
cmd_rotor_vel = cmd_f # this is just a hack for testing TODO remove
9688
cmd_rpy = cmd[..., 0:3]
9789
rot = R.from_quat(quat)
9890
euler_angles = rot.as_euler("xyz")
9991

92+
# Note that we are abusing the rotor_vel state as the thrust
10093
if rotor_vel is None:
101-
rotor_vel, rotor_vel_dot = cmd_rotor_vel[..., None], None
94+
rotor_vel, rotor_vel_dot = cmd_f[..., None], None
10295
else:
103-
rotor_vel_dot = (
104-
1 / thrust_time_coef * (cmd_rotor_vel[..., None] - rotor_vel)
105-
) # - KM * rotor_vel**2
96+
rotor_vel_dot = 1 / thrust_time_coef * (cmd_f[..., None] - rotor_vel)
10697

107-
# forces_motor = KF * xp.sum(rotor_vel**2, axis=-1)
10898
forces_motor = rotor_vel[..., 0]
10999
thrust = acc_coef + cmd_f_coef * forces_motor
110100

@@ -149,8 +139,6 @@ def symbolic_dynamics(
149139
gravity_vec: Array,
150140
J: Array,
151141
J_inv: Array,
152-
KF: Array,
153-
KM: Array,
154142
thrust_time_coef: Array,
155143
acc_coef: Array,
156144
cmd_f_coef: Array,
@@ -176,6 +164,7 @@ def symbolic_dynamics(
176164
cmd_rpy = cs.vertcat(symbols.cmd_roll, symbols.cmd_pitch, symbols.cmd_yaw)
177165

178166
# Defining the dynamics function
167+
# Note that we are abusing the rotor_vel state as the thrust
179168
if model_rotor_vel:
180169
# motor_force2rotor_vel
181170
# cmd_rotor_vel = cs.sqrt(symbols.cmd_thrust / 4 / KF)

0 commit comments

Comments
 (0)