Skip to content

Commit

Permalink
[WIP] Refactor envs to prepare for single sim
Browse files Browse the repository at this point in the history
  • Loading branch information
amacati committed Jun 19, 2024
1 parent 6f68927 commit 2a385ea
Show file tree
Hide file tree
Showing 9 changed files with 410 additions and 860 deletions.
5 changes: 2 additions & 3 deletions safe_control_gym/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"""Register environments."""

from safe_control_gym.utils.registration import register
from gymnasium import register

register(
id="quadrotor",
entry_point="safe_control_gym.envs.quadrotor:Quadrotor",
config_entry_point="safe_control_gym.envs:quadrotor.yaml",
)

register(
id="firmware",
entry_point="safe_control_gym.envs.firmware_wrapper:FirmwareWrapper",
config_entry_point="safe_control_gym.controllers.firmware:firmware.yaml",
max_episode_steps=900, # 30 seconds * 30 Hz
)
257 changes: 71 additions & 186 deletions safe_control_gym/envs/base_aviary.py

Large diffs are not rendered by default.

393 changes: 165 additions & 228 deletions safe_control_gym/envs/benchmark_env.py

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions safe_control_gym/envs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ class SimConstants: ...
class DroneConstants:
firmware_freq: int = 500 # Firmware frequency in Hz
supply_voltage: float = 3.0 # Power supply voltage
min_pwm: int = 20000 # Minimum PWM signal
max_pwm: int = 65535 # Maximum PWM signal
thrust_curve_a: float = -0.0006239 # Thrust curve parameters for brushed motors
thrust_curve_b: float = 0.088 # Thrust curve parameters for brushed motors
tumble_threshold: float = -0.5 # Vertical acceleration threshold for tumbling detection
tumble_duration: int = 30 # Number of consecutive steps before tumbling is detected
# TODO: acc and gyro were swapped in original implementation. Possible bug?
acc_lpf_cutoff: int = 80 # Low-pass filter cutoff freq
gyro_lpf_cutoff: int = 30 # Low-pass filter cutoff freq
KF: float = 3.16e-10 # Motor force factor
pwm2rpm_scale: float = 0.2685 # mapping factor from PWM to RPM
pwm2rpm_const: float = 4070.3 # mapping constant from PWM to RPM
6 changes: 3 additions & 3 deletions safe_control_gym/envs/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def __init__(
self.rounding = rounding
self.constrained_variable = ConstrainedVariableType(constrained_variable)
if self.constrained_variable == ConstrainedVariableType.STATE:
self.dim = env.state_dim
self.dim = env.state_space.shape[0]
elif self.constrained_variable == ConstrainedVariableType.INPUT:
self.dim = env.action_dim
self.dim = env.action_space.shape[0]
elif self.constrained_variable == ConstrainedVariableType.INPUT_AND_STATE:
self.dim = env.state_dim + env.action_dim
self.dim = env.state_space.shape[0] + env.action_space.shape[0]
else:
raise NotImplementedError(
"[ERROR] invalid constrained_variable (use STATE, INPUT or INPUT_AND_STATE)."
Expand Down
Loading

0 comments on commit 2a385ea

Please sign in to comment.