Skip to content

Commit ed1a4e6

Browse files
committed
Activate rotor dynamics. Fix controller pipeline ordering
1 parent aee0265 commit ed1a4e6

5 files changed

Lines changed: 24 additions & 32 deletions

File tree

crazyflow/sim/sim.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ def render(
183183
mode: str | None = "human",
184184
world: int = 0,
185185
default_cam_config: dict | None = None,
186-
width: int = 640,
187-
height: int = 480,
186+
width: int = 1920,
187+
height: int = 1080,
188188
) -> NDArray | None:
189189
if self.viewer is None:
190190
self.mj_model.vis.global_.offwidth = width
@@ -401,12 +401,12 @@ def build_control_fn(control: Control, physics: Physics) -> Callable[[SimData],
401401
"""Select the control function for the given control mode."""
402402
match control:
403403
case Control.state:
404-
control_pipeline = (step_attitude_controller, step_state_controller)
404+
control_pipeline = (step_state_controller, step_attitude_controller)
405405
if physics == Physics.first_principles:
406-
control_pipeline = (step_force_torque_controller,) + control_pipeline
406+
control_pipeline = control_pipeline + (step_force_torque_controller,)
407407
case Control.attitude:
408408
if physics == Physics.first_principles:
409-
control_pipeline = (step_force_torque_controller, step_attitude_controller)
409+
control_pipeline = (step_attitude_controller, step_force_torque_controller)
410410
elif physics in (Physics.so_rpy, Physics.so_rpy_rotor, Physics.so_rpy_rotor_drag):
411411
control_pipeline = (commit_attitude_controller,)
412412
else:
@@ -554,19 +554,11 @@ def step_force_torque_controller(data: SimData) -> SimData:
554554
assert ft_ctrl is not None, "Using force torque controller without initialized data"
555555
mask = controllable(data.core.steps, data.core.freq, ft_ctrl.steps, ft_ctrl.freq)
556556
ft_ctrl = leaf_replace(ft_ctrl, mask, cmd=ft_ctrl.staged_cmd)
557-
_ = force_torque2rotor_vel(
557+
rotor_vel = force_torque2rotor_vel(
558558
ft_ctrl.cmd[..., [0]], ft_ctrl.cmd[..., 1:], **ft_ctrl.params._asdict()
559559
)
560560
ft_ctrl = leaf_replace(ft_ctrl, mask, steps=data.core.steps)
561-
# TODO: Enable
562-
# data = data.replace(controls=data.controls.replace(rotor_vel=rotor_vel, force_torque=ft_ctrl))
563-
# return data
564-
# TODO: Remove
565-
r = R.from_quat(data.states.quat)
566-
cmd_force = jnp.zeros_like(ft_ctrl.cmd[..., 1:])
567-
cmd_force = cmd_force.at[..., 2].set(ft_ctrl.cmd[..., 0])
568-
force, torque = r.apply(cmd_force), r.apply(ft_ctrl.cmd[..., 1:])
569-
return data.replace(states=data.states.replace(force=force, torque=torque))
561+
return data.replace(controls=data.controls.replace(rotor_vel=rotor_vel, force_torque=ft_ctrl))
570562

571563

572564
def clip_floor_pos(data: SimData) -> SimData:

pixi.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies = [
2828
"ml_collections",
2929
"casadi",
3030
"numpy",
31-
"scipy @ git+https://github.com/amacati/scipy.git@broadcasting", # TODO: Replace with scipy 1.17 once released
31+
"scipy @ git+https://github.com/scipy/scipy.git@4cb83b6", # TODO: Replace with scipy 1.17 once released
3232
# "drone-models @ git+https://github.com/utiasDSL/drone-models.git@08ffb18",
3333
]
3434
requires-python = ">=3.11"

submodules/drone-controllers

submodules/drone-models

0 commit comments

Comments
 (0)