Skip to content

Commit 74924c5

Browse files
committed
Add bounding box to figure8
1 parent 7cf6e31 commit 74924c5

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎crazyflow/envs/figure_8_env.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ def _reward(terminated: Array, pos: Array, goal: Array) -> Array:
112112
reward = jnp.where(terminated, -1.0, reward)
113113
return reward
114114

115+
@staticmethod
116+
@jax.jit
117+
def _terminated(pos: Array) -> Array:
118+
hit_floor = pos[:, 0, 2] < 0.0 # Terminate if the drone has crashed into the ground
119+
bounding_box = jnp.any(jnp.abs(pos[:, 0, :3]) > jnp.array([2.0, 2.0, 2.0]), axis=-1)
120+
return hit_floor | bounding_box
121+
115122
@staticmethod
116123
def _reset_randomization(data: SimData, mask: Array) -> SimData:
117124
"""Randomize the initial position and velocity of the drones.

‎examples/figure8.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def main():
2828

2929
# dummy action for going up (in attitude control)
3030
action = np.zeros((20, 4), dtype=np.float32)
31-
action[..., 0] = -0.2
31+
action[..., 3] = 0.3
3232

3333
obs, info = envs.reset()
3434
# Step through the environment

0 commit comments

Comments
 (0)