Skip to content

Commit 50359d8

Browse files
committed
Remove sim module. Update dependencies. Disable sim script output print
1 parent 41acff1 commit 50359d8

14 files changed

+17
-1906
lines changed

lsy_drone_racing/control/trajectory_controller.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def __init__(self, initial_obs: dict[str, NDArray[np.floating]], initial_info: d
4242
[0.2, -1.8, 0.65],
4343
[1.1, -1.35, 1.1],
4444
[0.2, 0.0, 0.65],
45-
[0.0, 0.75, 0.525],
46-
[0.0, 0.75, 1.1],
45+
[0.0, 0.7, 0.525],
46+
[0.0, 0.7, 1.1],
4747
[-0.5, -0.5, 1.1],
4848
[-0.5, -1.0, 1.1],
4949
]
File renamed without changes.

lsy_drone_racing/envs/drone_racing_deploy_env.py

+9-22
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828

2929
import gymnasium
3030
import numpy as np
31+
from crazyflow.control.control import thrust_curve
32+
from crazyflow.sim.symbolic import symbolic_attitude
3133
from gymnasium import spaces
3234
from scipy.spatial.transform import Rotation as R
3335

3436
from lsy_drone_racing.control.closing_controller import ClosingController
35-
from lsy_drone_racing.sim.drone import Drone
36-
from lsy_drone_racing.sim.sim import Sim
3737
from lsy_drone_racing.utils import check_gate_pass
3838
from lsy_drone_racing.utils.import_utils import get_ros_package_path, pycrazyswarm
3939
from lsy_drone_racing.utils.ros_utils import check_drone_start_pos, check_race_track
@@ -111,17 +111,7 @@ def __init__(self, config: dict | Munch):
111111
names += [f"gate{g}" for g in range(1, len(config.env.track.gates) + 1)]
112112
names += [f"obstacle{g}" for g in range(1, len(config.env.track.obstacles) + 1)]
113113
self.vicon = Vicon(track_names=names, timeout=5)
114-
self.symbolic = None
115-
if config.env.symbolic:
116-
sim = Sim(
117-
track=config.env.track,
118-
sim_freq=config.sim.sim_freq,
119-
ctrl_freq=config.sim.ctrl_freq,
120-
disturbances=getattr(config.sim, "disturbances", {}),
121-
randomization=getattr(config.env, "randomization", {}),
122-
physics=config.sim.physics,
123-
)
124-
self.symbolic = sim.symbolic()
114+
self.symbolic = symbolic_attitude(config.env.freq) if config.env.symbolic else None
125115
self._last_pos = np.zeros(3)
126116

127117
self.gates_visited = np.array([False] * len(config.env.track.gates))
@@ -153,7 +143,7 @@ def reset(
153143
info["low_level_ctrl_freq"] = self.config.sim.ctrl_freq
154144
info["env_freq"] = self.config.env.freq
155145
info["drone_mass"] = 0.033 # Crazyflie 2.1 mass in kg
156-
return self.obs, info
146+
return self.obs(), info
157147

158148
def step(
159149
self, action: NDArray[np.floating]
@@ -175,7 +165,7 @@ def step(
175165
if self.target_gate >= len(self.config.env.track.gates):
176166
self.target_gate = -1
177167
terminated = self.target_gate == -1
178-
return self.obs, -1.0, terminated, False, self.info
168+
return self.obs(), -1.0, terminated, False, self.info
179169

180170
def close(self):
181171
"""Close the environment by stopping the drone and landing back at the starting position."""
@@ -189,7 +179,7 @@ def close(self):
189179
self.config.env.freq = freq_new
190180
t_step_ctrl = 1 / self.config.env.freq
191181

192-
obs = self.obs
182+
obs = self.obs()
193183
obs["acc"] = np.array(
194184
[0, 0, 0]
195185
) # TODO, use actual value when avaiable or do one step to calculate from velocity
@@ -211,15 +201,14 @@ def close(self):
211201
action[10:],
212202
)
213203
self.cf.cmdFullState(pos, vel, acc, yaw, rpy_rate)
214-
obs = self.obs
204+
obs = self.obs()
215205
obs["acc"] = np.array([0, 0, 0])
216206
controller.step_callback(action, obs, 0, True, False, info)
217207
time.sleep(t_step_ctrl)
218208

219209
self.cf.notifySetpointsStop()
220210
self.cf.land(0.05, 2.0)
221211

222-
@property
223212
def obs(self) -> dict:
224213
"""Return the observation of the environment."""
225214
drone = self.vicon.drone_name
@@ -312,7 +301,6 @@ def __init__(self, config: dict | Munch):
312301
"""
313302
super().__init__(config)
314303
self.action_space = gymnasium.spaces.Box(low=-1, high=1, shape=(4,))
315-
self.drone = Drone("mellinger")
316304

317305
def step(
318306
self, action: NDArray[np.floating]
@@ -329,12 +317,11 @@ def step(
329317
assert action.shape == self.action_space.shape, f"Invalid action shape: {action.shape}"
330318
collective_thrust, rpy = action[0], action[1:]
331319
rpy_deg = np.rad2deg(rpy)
332-
collective_thrust = self.drone._thrust_to_pwms(collective_thrust)
333-
self.cf.cmdVel(*rpy_deg, collective_thrust)
320+
self.cf.cmdVel(*rpy_deg, thrust_curve(collective_thrust))
334321
current_pos = self.vicon.pos[self.vicon.drone_name]
335322
self.target_gate += self.gate_passed(current_pos, self._last_pos)
336323
self._last_pos[:] = current_pos
337324
if self.target_gate >= len(self.config.env.track.gates):
338325
self.target_gate = -1
339326
terminated = self.target_gate == -1
340-
return self.obs, -1.0, terminated, False, self.info
327+
return self.obs(), -1.0, terminated, False, self.info

lsy_drone_racing/envs/drone_racing_env.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from gymnasium import spaces
4040
from scipy.spatial.transform import Rotation as R
4141

42-
from lsy_drone_racing.envs.utils import randomize_sim_fn
42+
from lsy_drone_racing.envs.randomize import randomize_sim_fn
4343
from lsy_drone_racing.utils import check_gate_pass
4444

4545
if TYPE_CHECKING:
@@ -87,8 +87,8 @@ class DroneRacingEnv(gymnasium.Env):
8787
low-level controller.
8888
"""
8989

90-
gate_spec_path = Path(__file__).parents[1] / "sim/assets/gate.xml"
91-
obstacle_spec_path = Path(__file__).parents[1] / "sim/assets/obstacle.xml"
90+
gate_spec_path = Path(__file__).parent / "assets/gate.xml"
91+
obstacle_spec_path = Path(__file__).parent / "assets/obstacle.xml"
9292

9393
def __init__(self, config: dict):
9494
"""Initialize the DroneRacingEnv.
@@ -176,7 +176,7 @@ def reset(
176176
# the sim.reset_hook function, so we don't need to explicitly do it here
177177
self.sim.reset()
178178

179-
# TODO: Add randomization of gates, obstacles, drone, and disturbances
179+
# TODO: Add disturbances
180180
self.target_gate = 0
181181
self._steps = 0
182182
self._last_drone_pos[:] = self.sim.data.states.pos[0, 0]
@@ -201,7 +201,6 @@ def step(
201201
"""
202202
assert action.shape == self.action_space.shape, f"Invalid action shape: {action.shape}"
203203
# TODO: Add action noise
204-
# TODO: Check why sim is being compiled twice
205204
self.sim.state_control(action.reshape((1, 1, 13)).astype(np.float32))
206205
self.sim.step(self.sim.freq // self.config.env.freq)
207206
self.target_gate += self.gate_passed()
@@ -435,7 +434,6 @@ def step(
435434
"""
436435
assert action.shape == self.action_space.shape, f"Invalid action shape: {action.shape}"
437436
# TODO: Add action noise
438-
# TODO: Check why sim is being compiled twice
439437
self.sim.attitude_control(action.reshape((1, 1, 4)).astype(np.float32))
440438
self.sim.step(self.sim.freq // self.config.env.freq)
441439
self.target_gate += self.gate_passed()
File renamed without changes.

lsy_drone_racing/sim/__init__.py

-33
This file was deleted.

0 commit comments

Comments
 (0)