Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crazyflow/drones/cf21B_500.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<worldbody>
<body name="drone" pos="0 0 0.05" childclass="cf21B">
<site name="CoM" />
<inertial pos="0.0 0.0 0.0" mass="0.04338" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<inertial pos="0.0 0.0 0.0" mass="0.0434" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />

<!-- Meshes -->
<geom mesh="pcb" material="gray" class="visual" />
Expand Down Expand Up @@ -92,7 +92,7 @@
</body>

<body name="drone_fused" pos="0 0 0.05" childclass="cf21B">
<inertial pos="0.0 0.0 0.0" mass="0.04338" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<inertial pos="0.0 0.0 0.0" mass="0.0434" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<geom mesh="cf21B_fused" material="" class="visual" />
<geom name="col_sphere_fused" type="sphere" size="0.086" pos="0 0 0.02" class="collision" contype="1" conaffinity="1" />
<geom name="col_box_fused" type="box" size="0.07 0.07 0.02" class="collision" rgba="0.5 0.5 0.5 0" contype="0" conaffinity="0" />
Expand Down
4 changes: 2 additions & 2 deletions crazyflow/drones/cf2x_L250.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<worldbody>
<body name="drone" pos="0 0 0.05" childclass="cf2x">
<site name="CoM" />
<inertial pos="0.0 0.0 0.0" mass="0.027" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<inertial pos="0.0 0.0 0.0" mass="0.0328" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />

<!-- Meshes -->
<geom mesh="pcb" material="gray" class="visual" />
Expand Down Expand Up @@ -93,7 +93,7 @@

<!-- Drone version optimized by fusing the whole geometry into a single mesh -->
<body name="drone_fused" pos="0 0 0.05" childclass="cf2x">
<inertial pos="0.0 0.0 0.0" mass="0.027" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<inertial pos="0.0 0.0 0.0" mass="0.0328" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<geom mesh="cf2x_fused" material="" class="visual" />
<geom name="col_sphere_fused" type="sphere" size="0.07" pos="0 0 0.005" class="collision" contype="1" conaffinity="1" />
<geom name="col_box_fused" type="box" size="0.055 0.055 0.02" class="collision" rgba="0.5 0.5 0.5 0" contype="0" conaffinity="0" />
Expand Down
4 changes: 2 additions & 2 deletions crazyflow/drones/cf2x_P250.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<worldbody>
<body name="drone" pos="0 0 0.05" childclass="cf2x">
<site name="CoM" />
<inertial pos="0.0 0.0 0.0" mass="0.027" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<inertial pos="0.0 0.0 0.0" mass="0.0318" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />

<!-- Meshes -->
<geom mesh="pcb" material="gray" class="visual" />
Expand Down Expand Up @@ -92,7 +92,7 @@
</body>

<body name="drone_fused" pos="0 0 0.05" childclass="cf2x">
<inertial pos="0.0 0.0 0.0" mass="0.027" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<inertial pos="0.0 0.0 0.0" mass="0.0318" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<geom mesh="cf2x_fused" material="" class="visual" />
<geom name="col_sphere_fused" type="sphere" size="0.07" pos="0 0 0.005" class="collision" contype="1" conaffinity="1" />
<geom name="col_box_fused" type="box" size="0.055 0.055 0.02" class="collision" rgba="0.5 0.5 0.5 0" contype="0" conaffinity="0" />
Expand Down
4 changes: 2 additions & 2 deletions crazyflow/drones/cf2x_T350.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<worldbody>
<body name="drone" pos="0 0 0.05" childclass="cf2x">
<site name="CoM" />
<inertial pos="0.0 0.0 0.0" mass="0.027" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<inertial pos="0.0 0.0 0.0" mass="0.0379" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />

<!-- Meshes -->
<geom mesh="pcb" material="gray" class="visual" />
Expand Down Expand Up @@ -93,7 +93,7 @@
</body>

<body name="drone_fused" pos="0 0 0.05" childclass="cf2x">
<inertial pos="0.0 0.0 0.0" mass="0.027" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<inertial pos="0.0 0.0 0.0" mass="0.0379" diaginertia="2.3951e-5 2.3951e-5 3.2347e-5" />
<geom mesh="cf2x_fused" material="" class="visual" />
<geom name="col_sphere_fused" type="sphere" size="0.0725" pos="0 0 0.01" class="collision" contype="1" conaffinity="1" />
<geom name="col_box_fused" type="box" size="0.0575 0.0575 0.02" class="collision" rgba="0.5 0.5 0.5 0" contype="0" conaffinity="0" />
Expand Down
22 changes: 11 additions & 11 deletions crazyflow/dynamics/first_principles/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# rotor model, no drag and no propeller gyroscopic torque are reasonable defaults for a new drone.

[cf2x_L250]
mass = 0.0319
mass = 0.0328
J = [ # TODO
[16.8e-6, 0.0, 0.0],
[0.0, 16.8e-6, 0.0],
Expand All @@ -51,9 +51,9 @@ mixing_matrix = [
[-1.0, 1.0, -1.0, 1.0]
]
drag_matrix = [ # This term is from the so_rpy_rotor_drag dynamics
[-0.01471782, 0.0, 0.0 ],
[0.0, -0.01471782, 0.0 ],
[0.0, 0.0, -0.01277641 ]
[-0.014953790232821078, 0.0, 0.0],
[0.0, -0.014953790232821078, 0.0],
[0.0, 0.0, -0.013900090000325344]
]


Expand Down Expand Up @@ -103,14 +103,14 @@ mixing_matrix = [
[-1.0, 1.0, -1.0, 1.0]
]
drag_matrix = [ # This term is from the so_rpy_rotor_drag dynamics
[-0.01556697, 0.0, 0.0 ],
[0.0, -0.01556697, 0.0 ],
[0.0, 0.0, -0.02191672 ]
[-0.015203241038199845, 0.0, 0.0],
[0.0, -0.015203241038199845, 0.0],
[0.0, 0.0, -0.02204579179094129]
]


[cf21B_500]
mass = 0.04338
mass = 0.0434
J = [
[25e-6, 0.0, 0.0],
[0.0, 28e-6, 0.0],
Expand All @@ -129,7 +129,7 @@ mixing_matrix = [
[-1.0, 1.0, -1.0, 1.0]
]
drag_matrix = [ # This term is from the so_rpy_rotor_drag dynamics
[-0.02149163, 0.0, 0.0 ],
[0.0, -0.02149163, 0.0 ],
[0.0, 0.0, -0.02359736 ]
[-0.021643637770852733, 0.0, 0.0],
[0.0, -0.021643637770852733, 0.0],
[0.0, 0.0, -0.02477138502714662]
]
28 changes: 14 additions & 14 deletions crazyflow/dynamics/so_rpy/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# docs/user-guide/dynamics/system-identification.md).

[cf2x_L250]
mass = 0.0319
mass = 0.0328
J = [
[16.8e-6, 0.0, 0.0],
[0.0, 16.8e-6, 0.0],
Expand All @@ -28,10 +28,10 @@ J = [
thrust_min = 0.012817578393224994 # in N per motor
thrust_max = 0.12 # in N per motor
acc_coef = 0.0
cmd_f_coef = 0.97605781
rpy_coef = [-245.67, -245.67, -227.78]
rpy_rates_coef = [-17.32, -17.32, -25.63]
cmd_rpy_coef = [196.18, 196.18, 390.27]
cmd_f_coef = 1.023224599403443
rpy_coef = [-485.8620950386863, -485.8620950386863, -333.2438787006866]
rpy_rates_coef = [-33.17729279340664, -33.17729279340664, -39.535506757052424]
cmd_rpy_coef = [448.0183990789311, 448.0183990789311, 306.31685518928396]


[cf2x_P250]
Expand Down Expand Up @@ -60,14 +60,14 @@ J = [
thrust_min = 0.01922636758983749 # in N per motor
thrust_max = 0.18 # in N per motor
acc_coef = 0.0
cmd_f_coef = 1.0089779349974615
rpy_coef = [-371.41695523, -371.41695523, -261.99549945]
rpy_rates_coef = [-29.26311118, -29.26311118, -29.74357219]
cmd_rpy_coef = [347.94260321, 347.94260321, 241.06977014]
cmd_f_coef = 1.0140372607776442
rpy_coef = [-373.81009672301474, -373.81009672301474, -262.01237938054936]
rpy_rates_coef = [-29.447753470026274, -29.447753470026274, -29.745699818936384]
cmd_rpy_coef = [350.209624193645, 350.209624193645, 241.085024111866]


[cf21B_500]
mass = 0.04338
mass = 0.0434
J = [
[25e-6, 0.0, 0.0],
[0.0, 28e-6, 0.0],
Expand All @@ -76,10 +76,10 @@ J = [
thrust_min = 0.02136263065537499 # in N per motor
thrust_max = 0.2 # in N per motor
acc_coef = 0.0
cmd_f_coef = 0.96836458
rpy_coef = [-188.9910, -188.9910, -138.3109]
rpy_rates_coef = [-12.7803, -12.7803, -16.8485]
cmd_rpy_coef = [138.0834, 138.0834, 198.5161]
cmd_f_coef = 0.9459441379738676
rpy_coef = [-156.34812197843243, -156.34812197843243, -144.7222372741053]
rpy_rates_coef = [-16.300330418164553, -16.300330418164553, -17.368699336318954]
cmd_rpy_coef = [139.7494294272397, 139.7494294272397, 127.01037564242333]

[hb_x500]
mass = 2.28
Expand Down
34 changes: 17 additions & 17 deletions crazyflow/dynamics/so_rpy_rotor/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# docs/user-guide/dynamics/system-identification.md).

[cf2x_L250]
mass = 0.0319
mass = 0.0328
J = [
[16.8e-6, 0.0, 0.0],
[0.0, 16.8e-6, 0.0],
Expand All @@ -29,11 +29,11 @@ J = [
thrust_min = 0.012817578393224994 # in N per motor
thrust_max = 0.12 # in N per motor
acc_coef = 0.0
cmd_f_coef = 0.97732585
thrust_time_coef = 0.0858607
rpy_coef = [-245.67, -245.67, -227.78]
rpy_rates_coef = [-17.32, -17.32, -25.63]
cmd_rpy_coef = [196.18, 196.18, 390.27]
cmd_f_coef = 1.0242686698819605
thrust_time_coef = 0.08671854102279604
rpy_coef = [-485.8620950386863, -485.8620950386863, -333.2438787006866]
rpy_rates_coef = [-33.17729279340664, -33.17729279340664, -39.535506757052424]
cmd_rpy_coef = [448.0183990789311, 448.0183990789311, 306.31685518928396]


[cf2x_P250]
Expand Down Expand Up @@ -63,15 +63,15 @@ J = [
thrust_min = 0.01922636758983749 # in N per motor
thrust_max = 0.18 # in N per motor
acc_coef = 0.0
cmd_f_coef = 1.022561164673754
thrust_time_coef = 0.5712805549388994 # High value, maybe not correct?
rpy_coef = [-371.41695523, -371.41695523, -261.99549945]
rpy_rates_coef = [-29.26311118, -29.26311118, -29.74357219]
cmd_rpy_coef = [347.94260321, 347.94260321, 241.06977014]
cmd_f_coef = 1.0145454356801935
thrust_time_coef = 0.05941543454583637
rpy_coef = [-373.81009672301474, -373.81009672301474, -262.01237938054936]
rpy_rates_coef = [-29.447753470026274, -29.447753470026274, -29.745699818936384]
cmd_rpy_coef = [350.209624193645, 350.209624193645, 241.085024111866]


[cf21B_500]
mass = 0.04338
mass = 0.0434
J = [
[25e-6, 0.0, 0.0],
[0.0, 28e-6, 0.0],
Expand All @@ -80,11 +80,11 @@ J = [
thrust_min = 0.02136263065537499 # in N per motor
thrust_max = 0.2 # in N per motor
acc_coef = 0.0
cmd_f_coef = 0.96841816
thrust_time_coef = 0.02055366
rpy_coef = [-188.9910, -188.9910, -138.3109]
rpy_rates_coef = [-12.7803, -12.7803, -16.8485]
cmd_rpy_coef = [138.0834, 138.0834, 198.5161]
cmd_f_coef = 0.9472350463278153
thrust_time_coef = 0.05180073413161973
rpy_coef = [-156.34812197843243, -156.34812197843243, -144.7222372741053]
rpy_rates_coef = [-16.300330418164553, -16.300330418164553, -17.368699336318954]
cmd_rpy_coef = [139.7494294272397, 139.7494294272397, 127.01037564242333]

[hb_x500]
mass = 2.28
Expand Down
52 changes: 26 additions & 26 deletions crazyflow/dynamics/so_rpy_rotor_drag/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# docs/user-guide/dynamics/system-identification.md).

[cf2x_L250]
mass = 0.0319
mass = 0.0328
Comment thread
ratheron marked this conversation as resolved.
J = [
[16.8e-6, 0.0, 0.0],
[0.0, 16.8e-6, 0.0],
Expand All @@ -34,16 +34,16 @@ J = [
thrust_min = 0.012817578393224994 # in N per motor
thrust_max = 0.12 # in N per motor
acc_coef = 0.0
cmd_f_coef = 0.98325003
thrust_time_coef = 0.12116392
cmd_f_coef = 1.0322435843278281
thrust_time_coef = 0.14876008226610188
drag_matrix = [
[-0.01471782, 0.0, 0.0 ],
[0.0, -0.01471782, 0.0 ],
[0.0, 0.0, -0.01277641 ]
[-0.014953790232821078, 0.0, 0.0],
[0.0, -0.014953790232821078, 0.0],
[0.0, 0.0, -0.013900090000325344]
]
rpy_coef = [-245.67, -245.67, -227.78]
rpy_rates_coef = [-17.32, -17.32, -25.63]
cmd_rpy_coef = [196.18, 196.18, 390.27]
rpy_coef = [-485.8620950386863, -485.8620950386863, -333.2438787006866]
rpy_rates_coef = [-33.17729279340664, -33.17729279340664, -39.535506757052424]
cmd_rpy_coef = [448.0183990789311, 448.0183990789311, 306.31685518928396]


[cf2x_P250]
Expand Down Expand Up @@ -78,20 +78,20 @@ J = [
thrust_min = 0.01922636758983749 # in N per motor
thrust_max = 0.18 # in N per motor
acc_coef = 0.0
cmd_f_coef = 1.0226418398769022
thrust_time_coef = 0.16711124468068936
cmd_f_coef = 1.0229179982077607
thrust_time_coef = 0.17585713583659168
drag_matrix = [
[-0.01521728, 0.0, 0.0 ],
[0.0, -0.01521728, 0.0 ],
[0.0, 0.0, -0.02144565 ]
[-0.015203241038199845, 0.0, 0.0],
[0.0, -0.015203241038199845, 0.0],
[0.0, 0.0, -0.02204579179094129]
]
rpy_coef = [-371.41695523, -371.41695523, -261.99549945]
rpy_rates_coef = [-29.26311118, -29.26311118, -29.74357219]
cmd_rpy_coef = [347.94260321, 347.94260321, 241.06977014]
rpy_coef = [-373.81009672301474, -373.81009672301474, -262.01237938054936]
rpy_rates_coef = [-29.447753470026274, -29.447753470026274, -29.745699818936384]
cmd_rpy_coef = [350.209624193645, 350.209624193645, 241.085024111866]


[cf21B_500]
mass = 0.04338
mass = 0.0434
J = [
[25e-6, 0.0, 0.0],
[0.0, 28e-6, 0.0],
Expand All @@ -100,16 +100,16 @@ J = [
thrust_min = 0.02136263065537499 # in N per motor
thrust_max = 0.2 # in N per motor
acc_coef = 0.0
cmd_f_coef = 0.98023254
thrust_time_coef = 0.07993871
cmd_f_coef = 0.959471532998666
thrust_time_coef = 0.08824147411162254
drag_matrix = [
[-0.02149163, 0.0, 0.0 ],
[0.0, -0.02149163, 0.0 ],
[0.0, 0.0, -0.02359736 ]
[-0.021643637770852733, 0.0, 0.0],
[0.0, -0.021643637770852733, 0.0],
[0.0, 0.0, -0.02477138502714662]
]
rpy_coef = [-188.9910, -188.9910, -138.3109]
rpy_rates_coef = [-12.7803, -12.7803, -16.8485]
cmd_rpy_coef = [138.0834, 138.0834, 198.5161]
rpy_coef = [-156.34812197843243, -156.34812197843243, -144.7222372741053]
rpy_rates_coef = [-16.300330418164553, -16.300330418164553, -17.368699336318954]
cmd_rpy_coef = [139.7494294272397, 139.7494294272397, 127.01037564242333]

[hb_x500]
mass = 2.28
Expand Down
9 changes: 8 additions & 1 deletion crazyflow/dynamics/utils/identification.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,23 @@ def _residual_fun_trans_jac(
constants: dict[str, Array],
acc_observed: Array,
) -> Callable:
# The residuals ignore the parameters the dynamics do not have, so their Jacobian columns
# must be zero as well. Otherwise the optimizer steps along gradients of the full model
# that change nothing in the residuals and settles far from the minimum.
match dynamics: # Dummy values for other params
case "so_rpy":
params_jnp = jnp.array([params[0], 0.0, 0.0, 0.0])
mask = jnp.array([1.0, 0.0, 0.0, 0.0])
case "so_rpy_rotor":
params_jnp = jnp.array([params[0], params[1], 0.0, 0.0])
mask = jnp.array([1.0, 1.0, 0.0, 0.0])
case "so_rpy_rotor_drag":
params_jnp = jnp.array([params[0], params[1], params[2], params[3]])
mask = jnp.array([1.0, 1.0, 1.0, 1.0])
case _:
raise ValueError(f"Unknown dynamics type: {dynamics}")
return jax.device_get(jac_fun(params_jnp, quat, vel, cmd_f, t, constants, acc_observed))
jac = jac_fun(params_jnp, quat, vel, cmd_f, t, constants, acc_observed)
return jax.device_get(jac * mask)
Comment thread
ratheron marked this conversation as resolved.

return _residual_fun_trans, _residual_fun_trans_jac

Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/dynamics/dynamics-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ from crazyflow.dynamics.so_rpy_rotor_drag import dynamics
dynamics = parametrize(dynamics, drone="cf2x_L250")

# Reuses pos, quat, vel, ang_vel from above; the command interface is what differs
cmd = np.array([0.0, 0.0, 0.0, 0.31]) # [roll_rad, pitch_rad, yaw_rad, thrust_N]
rotor_vel = np.full(4, 0.31) # shape (4,) — thrust state [N]; None to skip thrust dynamics
cmd = np.array([0.0, 0.0, 0.0, 0.32]) # [roll_rad, pitch_rad, yaw_rad, thrust_N]
rotor_vel = np.full(4, 0.32) # shape (4,) — thrust state [N]; None to skip thrust dynamics

pos_dot, quat_dot, vel_dot, ang_vel_dot, rotor_vel_dot = dynamics(
pos, quat, vel, ang_vel, cmd, rotor_vel
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/dynamics/parametrize.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ rotor_vel = np.zeros(4)
cmd = np.zeros(4)

# Simulate with a 10 g payload for this call only — dynamics.keywords is not modified.
pos_dot, *_ = dynamics(pos, quat, vel, ang_vel, cmd, rotor_vel, mass=0.0419)
pos_dot, *_ = dynamics(pos, quat, vel, ang_vel, cmd, rotor_vel, mass=0.0428)
```

This becomes particularly useful for domain randomization: instead of baking randomized parameters into the partial, you can pass a batch of them as call-time arguments and keep the step function JIT-compiled across parameter changes. See [Batching & domain randomization](batching.md) for the full pattern.
Expand Down Expand Up @@ -130,7 +130,7 @@ If you need the parameter values directly, for example, to pass them to [`symbol
from crazyflow.dynamics import Dynamics, load_fn_params, load_params

params = load_fn_params(dynamics, "cf2x_L250")
params["mass"] # 0.0319
params["mass"] # 0.0328
params["J_inv"] # array([...])

params = load_params(Dynamics.first_principles, "cf2x_L250")
Expand Down
Loading
Loading