Skip to content

Commit 8a2b365

Browse files
committed
Update gradient example. Reduce sampling example duration
1 parent 3e47b70 commit 8a2b365

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

examples/control/sampling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
# Simulation configuration
3434
DRONE_MODEL = "cf21B_500"
35-
DURATION = 18.0
35+
DURATION = 10.0
3636
FPS = 60
3737
RENDER = True
3838

examples/jax/gradient.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
from crazyflow.control import Control
88
from crazyflow.sim import Physics, Sim
99
from crazyflow.sim.data import SimData
10-
from crazyflow.sim.pipeline import remove_fn
1110

1211

1312
def main():
1413
sim = Sim(control=Control.attitude, physics=Physics.first_principles, attitude_freq=50)
1514
# Remove clipping floor function which kills gradients
16-
remove_fn(sim.step_pipeline, "clip_floor_pos")
1715
sim_step = sim.build_step_fn()
16+
# If the drone starts on the floor, the gradient gets killed by the floor clipping function. We
17+
# thus start in the air to avoid zero gradients. Alternatively, we could also remove the floor
18+
# clipping function
19+
sim.data = sim.data.replace(
20+
states=sim.data.states.replace(pos=sim.data.states.pos.at[..., 2].set(0.5))
21+
)
1822

1923
def step(cmd: NDArray, data: SimData) -> jax.Array:
2024
data = data.replace(

0 commit comments

Comments
 (0)