Skip to content

Commit 4542ba0

Browse files
committed
Fix and remove outdated tests
1 parent 493e8f0 commit 4542ba0

24 files changed

+289
-484
lines changed

benchmarks/main.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def main(
2525
reset_fn, step_fn = time_multi_drone_reset, time_multi_drone_step
2626
if reset:
2727
timings = reset_fn(n_tests=n_tests, number=number)
28-
print_benchmark_results(name="Sim reset", timings=timings / number)
28+
print_benchmark_results(name="Racing env reset", timings=timings / number)
2929
if step:
3030
timings = step_fn(n_tests=n_tests, number=number)
31-
print_benchmark_results(name="Sim steps", timings=timings / number)
31+
print_benchmark_results(name="Racing env steps", timings=timings / number)
3232
timings = step_fn(n_tests=n_tests, number=number, physics_mode="sys_id")
33-
print_benchmark_results(name="Sim steps (sys_id backend)", timings=timings / number)
33+
print_benchmark_results(name="Racing env steps (sys_id backend)", timings=timings / number)
3434
# timings = step_fn(n_tests=n_tests, number=number, physics_mode="mujoco")
3535
# print_benchmark_results(name="Sim steps (mujoco backend)", timings=timings / number)
3636

config/level0.toml

+16-15
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,13 @@ freq = 500 # Simulation frequency, in Hz
2727
attitude_freq = 500 # Controller frequency, in Hz. This frequency is used to simulate the onboard controller, NOT for the environment's step function
2828
gui = false # Enable/disable PyBullet's GUI
2929

30-
[sim.disturbances.action]
31-
type = "GaussianNoise"
32-
std = 0.001
33-
34-
[sim.disturbances.dynamics]
35-
type = "UniformNoise"
36-
low = [-0.1, -0.1, -0.1]
37-
high = [0.1, 0.1, 0.1]
38-
3930
[env]
40-
id = "DroneRacing-v0" # Either "DroneRacing-v0" or "DroneRacingAttitude-v0". If using "DroneRacingAttitude-v0", the drone will use the attitude controller instead of the position controller.
41-
random_resets = false # Whether to re-seed the random number generator between episodes
42-
seed = 1337 # Random seed
43-
freq = 50 # Frequency of the environment's step function, in Hz
44-
symbolic = false # Whether to include symbolic expressions in the info dict. Note: This can interfere with multiprocessing! If you want to parallelize your training, set this to false.
45-
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
31+
id = "DroneRacing-v0" # "DroneRacing-v0" for single races, "MultiDroneRacing-v0" for multi-drone races. Each environment also implements a vector-environment for faster training
32+
random_resets = false # Whether to re-seed the random number generator between episodes
33+
seed = 1337 # Random seed
34+
freq = 50 # Frequency of the environment's step function, in Hz
35+
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
36+
action_space = "state" # Action space of the environment. Can be either "state" or "attitude"
4637

4738
[env.track]
4839
# Tall gates: 1.0m height. Short gates: 0.525m height. Height is measured from the ground to the
@@ -75,3 +66,13 @@ pos = [1.0, 1.0, 0.05]
7566
rpy = [0, 0, 0]
7667
vel = [0, 0, 0]
7768
ang_vel = [0, 0, 0]
69+
70+
[env.disturbances.action]
71+
fn = "normal"
72+
scale = 0.001
73+
74+
[env.disturbances.dynamics]
75+
fn = "uniform"
76+
[env.disturbances.dynamics.kwargs]
77+
minval = [-0.1, -0.1, -0.1]
78+
maxval = [0.1, 0.1, 0.1]

config/level1.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ attitude_freq = 500 # Controller frequency, in Hz.
2424
gui = false # Enable/disable PyBullet's GUI
2525

2626
[env]
27-
id = "DroneRacing-v0" # Either "DroneRacing-v0" or "DroneRacingAttitude-v0". If using "DroneRacingAttitude-v0", the drone will use the attitude controller instead of the position controller.
28-
random_resets = false # Whether to re-seed the random number generator between episodes
29-
seed = 1337 # Random seed
30-
freq = 50 # Frequency of the environment's step function, in Hz
31-
symbolic = false # Whether to include symbolic expressions in the info dict. Note: This can interfere with multiprocessing! If you want to parallelize your training, set this to false.
32-
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
27+
id = "DroneRacing-v0" # "DroneRacing-v0" for single races, "MultiDroneRacing-v0" for multi-drone races. Each environment also implements a vector-environment for faster training
28+
random_resets = false # Whether to re-seed the random number generator between episodes
29+
seed = 1337 # Random seed
30+
freq = 50 # Frequency of the environment's step function, in Hz
31+
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
32+
action_space = "state" # Action space of the environment. Can be either "state" or "attitude"
3333

3434
[env.track]
3535
# Tall gates: 1.0m height. Short gates: 0.525m height. Height is measured from the ground to the

config/level2.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ attitude_freq = 500 # Controller frequency, in Hz.
2424
gui = false # Enable/disable PyBullet's GUI
2525

2626
[env]
27-
id = "DroneRacing-v0" # Either "DroneRacing-v0" or "DroneRacingAttitude-v0". If using "DroneRacingAttitude-v0", the drone will use the attitude controller instead of the position controller.
28-
random_resets = false # Whether to re-seed the random number generator between episodes
29-
seed = 1337 # Random seed
30-
freq = 50 # Frequency of the environment's step function, in Hz
31-
symbolic = false # Whether to include symbolic expressions in the info dict. Note: This can interfere with multiprocessing! If you want to parallelize your training, set this to false.
32-
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
27+
id = "DroneRacing-v0" # "DroneRacing-v0" for single races, "MultiDroneRacing-v0" for multi-drone races. Each environment also implements a vector-environment for faster training
28+
random_resets = false # Whether to re-seed the random number generator between episodes
29+
seed = 1337 # Random seed
30+
freq = 50 # Frequency of the environment's step function, in Hz
31+
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
32+
action_space = "state" # Action space of the environment. Can be either "state" or "attitude"
3333

3434
[env.track]
3535
# Tall gates: 1.0m height. Short gates: 0.525m height. Height is measured from the ground to the

config/level3.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ attitude_freq = 500 # Controller frequency, in Hz.
2424
gui = false # Enable/disable PyBullet's GUI
2525

2626
[env]
27-
id = "DroneRacing-v0" # Either "DroneRacing-v0" or "DroneRacingAttitude-v0". If using "DroneRacingAttitude-v0", the drone will use the attitude controller instead of the position controller.
28-
random_resets = true # Whether to re-seed the random number generator between episodes
29-
seed = 1337 # Random seed
30-
freq = 50 # Frequency of the environment's step function, in Hz
31-
symbolic = false # Whether to include symbolic expressions in the info dict. Note: This can interfere with multiprocessing! If you want to parallelize your training, set this to false.
32-
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
27+
id = "DroneRacing-v0" # "DroneRacing-v0" for single races, "MultiDroneRacing-v0" for multi-drone races. Each environment also implements a vector-environment for faster training
28+
random_resets = true # Whether to re-seed the random number generator between episodes
29+
seed = 1337 # Random seed
30+
freq = 50 # Frequency of the environment's step function, in Hz
31+
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
32+
action_space = "state" # Action space of the environment. Can be either "state" or "attitude"
3333

3434
[env.track]
3535
# Tall gates: 1.0m height. Short gates: 0.525m height. Height is measured from the ground to the

config/multi_level0.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ attitude_freq = 500 # Controller frequency, in Hz.
2828
gui = false # Enable/disable PyBullet's GUI
2929

3030
[env]
31-
id = "MultiDroneRacing-v0" # Either "MultiDroneRacingEnv-v0" or "MultiDroneRacingAttitude-v0". If using "MultiDroneRacingAttitude-v0", the drone will use the attitude controller instead of the position controller.
32-
n_drones = 2 # Number of drones has to match the track configuration for drones
33-
random_resets = false # Whether to re-seed the random number generator between episodes
34-
seed = 1337 # Random seed
35-
freq = 50 # Frequency of the environment's step function, in Hz
36-
symbolic = false # Whether to include symbolic expressions in the info dict. Note: This can interfere with multiprocessing! If you want to parallelize your training, set this to false.
37-
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
31+
id = "MultiDroneRacing-v0"
32+
n_drones = 2 # Number of drones has to match the track configuration for drones
33+
random_resets = false # Whether to re-seed the random number generator between episodes
34+
seed = 1337 # Random seed
35+
freq = 50 # Frequency of the environment's step function, in Hz
36+
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
37+
action_space = "state" # Action space of the environment. Can be either "state" or "attitude"
3838

3939
[env.track]
4040
# Tall gates: 1.0m height. Short gates: 0.525m height. Height is measured from the ground to the

config/multi_level3.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ attitude_freq = 500 # Controller frequency, in Hz.
2828
gui = false # Enable/disable PyBullet's GUI
2929

3030
[env]
31-
id = "MultiDroneRacing-v0" # Either "MultiDroneRacingEnv-v0" or "MultiDroneRacingAttitude-v0". If using "MultiDroneRacingAttitude-v0", the drone will use the attitude controller instead of the position controller.
32-
n_drones = 2 # Number of drones has to match the track configuration for drones
33-
random_resets = true # Whether to re-seed the random number generator between episodes
34-
seed = 1337 # Random seed
35-
freq = 50 # Frequency of the environment's step function, in Hz
36-
symbolic = false # Whether to include symbolic expressions in the info dict. Note: This can interfere with multiprocessing! If you want to parallelize your training, set this to false.
37-
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
31+
id = "MultiDroneRacing-v0"
32+
n_drones = 2 # Number of drones has to match the track configuration for drones
33+
random_resets = true # Whether to re-seed the random number generator between episodes
34+
seed = 1337 # Random seed
35+
freq = 50 # Frequency of the environment's step function, in Hz
36+
sensor_range = 0.45 # Range at which the exact location of gates and obstacles become visible to the drone. Objects that are not in the drone's sensor range report their nominal position.
37+
action_space = "state" # Action space of the environment. Can be either "state" or "attitude"
3838

3939
[env.track]
4040
# Tall gates: 1.0m height. Short gates: 0.525m height. Height is measured from the ground to the

lsy_drone_racing/control/thrust_controller.py lsy_drone_racing/control/attitude_controller.py

+12-28
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from typing import TYPE_CHECKING
1515

1616
import numpy as np
17-
import pybullet as p
17+
from crazyflow.constants import MASS
1818
from scipy.interpolate import CubicSpline
1919
from scipy.spatial.transform import Rotation as R
2020

@@ -24,23 +24,23 @@
2424
from numpy.typing import NDArray
2525

2626

27-
class ThrustController(BaseController):
27+
class AttitudeController(BaseController):
2828
"""Example of a controller using the collective thrust and attitude interface.
2929
3030
Modified from https://github.com/utiasDSL/crazyswarm-import/blob/ad2f7ea987f458a504248a1754b124ba39fc2f21/ros_ws/src/crazyswarm/scripts/position_ctl_m.py
3131
"""
3232

33-
def __init__(self, initial_obs: dict[str, NDArray[np.floating]], initial_info: dict):
33+
def __init__(self, obs: dict[str, NDArray[np.floating]], info: dict, config: dict):
3434
"""Initialization of the controller.
3535
3636
Args:
37-
initial_obs: The initial observation of the environment's state. See the environment's
37+
obs: The initial observation of the environment's state. See the environment's
3838
observation space for details.
39-
initial_info: Additional environment information from the reset.
39+
info: Additional environment information from the reset.
4040
"""
41-
super().__init__(initial_obs, initial_info)
42-
self.low_level_ctrl_freq = initial_info["low_level_ctrl_freq"]
43-
self.drone_mass = initial_info["drone_mass"]
41+
super().__init__(obs, info, config)
42+
self.freq = config.env.freq
43+
self.drone_mass = MASS
4444
self.kp = np.array([0.4, 0.4, 1.25])
4545
self.ki = np.array([0.05, 0.05, 0.05])
4646
self.kd = np.array([0.2, 0.2, 0.4])
@@ -58,8 +58,8 @@ def __init__(self, initial_obs: dict[str, NDArray[np.floating]], initial_info: d
5858
[0.2, -1.8, 0.65],
5959
[1.1, -1.35, 1.1],
6060
[0.2, 0.0, 0.65],
61-
[0.0, 0.75, 0.525],
62-
[0.0, 0.75, 1.1],
61+
[0.0, 0.7, 0.525],
62+
[0.0, 0.7, 1.1],
6363
[-0.5, -0.5, 1.1],
6464
[-0.5, -1.0, 1.1],
6565
]
@@ -71,28 +71,12 @@ def __init__(self, initial_obs: dict[str, NDArray[np.floating]], initial_info: d
7171
cs_z = CubicSpline(ts, waypoints[:, 2])
7272

7373
des_completion_time = 15
74-
ts = np.linspace(0, 1, int(initial_info["env_freq"] * des_completion_time))
74+
ts = np.linspace(0, 1, int(self.freq * des_completion_time))
7575

7676
self.x_des = cs_x(ts)
7777
self.y_des = cs_y(ts)
7878
self.z_des = cs_z(ts)
7979

80-
try:
81-
# Draw interpolated Trajectory. Limit segments to avoid excessive drawings
82-
stride = max(1, len(self.x_des) // 100)
83-
trajectory = np.vstack([self.x_des, self.y_des, self.z_des])[..., ::stride].T
84-
for i in range(len(trajectory) - 1):
85-
p.addUserDebugLine(
86-
trajectory[i],
87-
trajectory[i + 1],
88-
lineColorRGB=[1, 0, 0],
89-
lineWidth=2,
90-
lifeTime=0,
91-
physicsClientId=0,
92-
)
93-
except p.error:
94-
... # Ignore pybullet errors if not running in the pybullet GUI
95-
9680
def compute_control(
9781
self, obs: dict[str, NDArray[np.floating]], info: dict | None = None
9882
) -> NDArray[np.floating]:
@@ -116,7 +100,7 @@ def compute_control(
116100
vel_error = des_vel - obs["vel"]
117101

118102
# Update integral error
119-
self.i_error += pos_error * (1 / self.low_level_ctrl_freq)
103+
self.i_error += pos_error * (1 / self.freq)
120104
self.i_error = np.clip(self.i_error, -self.ki_range, self.ki_range)
121105

122106
# Compute target thrust

lsy_drone_racing/envs/drone_race.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from gymnasium.vector import VectorEnv
99
from gymnasium.vector.utils import batch_space
1010

11-
from lsy_drone_racing.envs.race_core import RaceCoreEnv, action_space, observation_space
11+
from lsy_drone_racing.envs.race_core import RaceCoreEnv, build_action_space, build_observation_space
1212

1313
if TYPE_CHECKING:
1414
import numpy as np
@@ -22,6 +22,7 @@ def __init__(
2222
freq: int,
2323
sim_config: ConfigDict,
2424
sensor_range: float,
25+
action_space: Literal["state", "attitude"] = "state",
2526
track: ConfigDict | None = None,
2627
disturbances: ConfigDict | None = None,
2728
randomizations: ConfigDict | None = None,
@@ -36,6 +37,7 @@ def __init__(
3637
freq=freq,
3738
sim_config=sim_config,
3839
sensor_range=sensor_range,
40+
action_space=action_space,
3941
track=track,
4042
disturbances=disturbances,
4143
randomizations=randomizations,
@@ -44,9 +46,9 @@ def __init__(
4446
max_episode_steps=max_episode_steps,
4547
device=device,
4648
)
47-
self.action_space = action_space("state")
49+
self.action_space = build_action_space(action_space)
4850
n_gates, n_obstacles = len(track.gates), len(track.obstacles)
49-
self.observation_space = observation_space(n_gates, n_obstacles)
51+
self.observation_space = build_observation_space(n_gates, n_obstacles)
5052
self.autoreset = False
5153

5254
def reset(self, seed: int | None = None, options: dict | None = None) -> tuple[dict, dict]:
@@ -69,6 +71,7 @@ def __init__(
6971
freq: int,
7072
sim_config: ConfigDict,
7173
sensor_range: float,
74+
action_space: Literal["state", "attitude"] = "state",
7275
track: ConfigDict | None = None,
7376
disturbances: ConfigDict | None = None,
7477
randomizations: ConfigDict | None = None,
@@ -83,6 +86,7 @@ def __init__(
8386
freq=freq,
8487
sim_config=sim_config,
8588
sensor_range=sensor_range,
89+
action_space=action_space,
8690
track=track,
8791
disturbances=disturbances,
8892
randomizations=randomizations,
@@ -91,10 +95,10 @@ def __init__(
9195
max_episode_steps=max_episode_steps,
9296
device=device,
9397
)
94-
self.single_action_space = action_space("state")
98+
self.single_action_space = build_action_space(action_space)
9599
self.action_space = batch_space(self.single_action_space, num_envs)
96100
n_gates, n_obstacles = len(track.gates), len(track.obstacles)
97-
self.single_observation_space = observation_space(n_gates, n_obstacles)
101+
self.single_observation_space = build_observation_space(n_gates, n_obstacles)
98102
self.observation_space = batch_space(self.single_observation_space, num_envs)
99103

100104
def reset(self, seed: int | None = None, options: dict | None = None) -> tuple[dict, dict]:

0 commit comments

Comments
 (0)