Skip to content

Commit 5a4beb6

Browse files
committed
Rename BaseController to Controller
1 parent 37a7b96 commit 5a4beb6

File tree

11 files changed

+27
-29
lines changed

11 files changed

+27
-29
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,6 @@ In a second terminal:
418418
python scripts/deploy.py --controller <your_controller.py> --config level3.toml
419419
```
420420

421-
where `<your_controller.py>` implements a controller that inherits from `lsy_drone_racing.control.BaseController`
421+
where `<your_controller.py>` implements a controller that inherits from `lsy_drone_racing.control.Controller`
422422

423423

docs/getting_started/general.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ Welcome to the LSY Drone Racing Project! This is a platform developed by the LSY
55

66
Implementing Your Own Algorithms
77
--------------------------------
8-
To implement your own controller, you need to implement a ``Controller`` class in the :mod:`lsy_drone_racing.control` module. The only restriction we place on controllers is that they have to implement the interface defined by the :class:`BaseController <lsy_drone_racing.control.controller.BaseController>` class. Apart from that, you are encouraged to use the full spectrum of control algorithms, e.g., MPC, trajectory optimization, reinforcement learning, etc., to compete in the challenge. Please make sure to put your controller implementation in the :mod:`lsy_drone_racing.control` module to make sure that it is correctly recognized by our scripts.
8+
To implement your own controller, you need to implement a ``Controller`` class in the :mod:`lsy_drone_racing.control` module. The only restriction we place on controllers is that they have to implement the interface defined by the :class:`Controller <lsy_drone_racing.control.controller.Controller>` class. Apart from that, you are encouraged to use the full spectrum of control algorithms, e.g., MPC, trajectory optimization, reinforcement learning, etc., to compete in the challenge. Please make sure to put your controller implementation in the :mod:`lsy_drone_racing.control` module to make sure that it is correctly recognized by our scripts.
99

1010
.. note::
1111
Make sure to inherit from the base class for your controller implementation. This ensures that your controller is compatible with our scripts. Also make sure to only create one controller class per file. Otherwise, we do not know which controller to load from the file.
1212

1313
.. warning::
14-
You are not allowed to modify the interface of the :class:`BaseController <lsy_drone_racing.control.controller.BaseController>` class. Doing so will make your controller incompatible with the deployment environment and we won't be able to run your controller on our setup.
14+
You are not allowed to modify the interface of the :class:`Controller <lsy_drone_racing.control.controller.Controller>` class. Doing so will make your controller incompatible with the deployment environment and we won't be able to run your controller on our setup.
1515

1616
.. warning::
1717
Many students are enthusiastic about deep reinforcement learning and try to use it to solve the challenge. While you are completely free in choosing your control algorithm, we know from experience that training good agents is non-trivial, requires significant compute, and can be difficult to transfer into the real world setup. Students taking this approach should make sure they already have some experience with RL, and take their policies to the real world setup early to address potential sim2real issues.

lsy_drone_racing/control/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
77
To give you an idea of what you need to do, we also include some example implementations:
88
9-
* :class:`~.BaseController`: The abstract base class defining the interface for all controllers.
9+
* :class:`~.Controller`: The abstract base class defining the interface for all controllers.
1010
* :class:`PPOController <lsy_drone_racing.control.ppo_controller.PPOController>`: An example
1111
implementation using a pre-trained Proximal Policy Optimization (PPO) model.
1212
* :class:`PPOController <lsy_drone_racing.control.trajectory_controller.TrajectoryController>`: A
1313
controller that follows a pre-defined trajectory using cubic spline interpolation.
1414
"""
1515

16-
from lsy_drone_racing.control.controller import BaseController
16+
from lsy_drone_racing.control.controller import Controller
1717

18-
__all__ = ["BaseController"]
18+
__all__ = ["Controller"]

lsy_drone_racing/control/attitude_controller.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
from scipy.interpolate import CubicSpline
1919
from scipy.spatial.transform import Rotation as R
2020

21-
from lsy_drone_racing.control import BaseController
21+
from lsy_drone_racing.control import Controller
2222

2323
if TYPE_CHECKING:
2424
from numpy.typing import NDArray
2525

2626

27-
class AttitudeController(BaseController):
27+
class AttitudeController(Controller):
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

lsy_drone_racing/control/controller.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from that, you are free to add any additional methods, attributes, or classes to your controller.
66
77
As an example, you could load the weights of a neural network in the constructor and use it to
8-
compute the control commands in the :meth:`compute_control <.BaseController.compute_control>`
9-
method. You could also use the :meth:`step_callback <.BaseController.step_callback>` method to
8+
compute the control commands in the :meth:`compute_control <.Controller.compute_control>`
9+
method. You could also use the :meth:`step_callback <.Controller.step_callback>` method to
1010
update the controller state at runtime.
1111
1212
Note:
@@ -24,7 +24,7 @@
2424
from numpy.typing import NDArray
2525

2626

27-
class BaseController(ABC):
27+
class Controller(ABC):
2828
"""Base class for controller implementations."""
2929

3030
def __init__(self, obs: dict[str, NDArray[np.floating]], info: dict, config: dict):

lsy_drone_racing/control/ppo_controller.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
import numpy as np
1818
from stable_baselines3 import PPO
1919

20-
from lsy_drone_racing.control import BaseController
20+
from lsy_drone_racing.control import Controller
2121

2222
if TYPE_CHECKING:
2323
from numpy.typing import NDArray
2424

2525

26-
class PPOController(BaseController):
26+
class PPOController(Controller):
2727
"""Controller using a pre-trained PPO model."""
2828

2929
def __init__(self, initial_obs: dict[str, NDArray[np.floating]], initial_info: dict):

lsy_drone_racing/control/trajectory_controller.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
import numpy as np
1717
from scipy.interpolate import CubicSpline
1818

19-
from lsy_drone_racing.control import BaseController
19+
from lsy_drone_racing.control import Controller
2020

2121
if TYPE_CHECKING:
2222
from numpy.typing import NDArray
2323

2424

25-
class TrajectoryController(BaseController):
25+
class TrajectoryController(Controller):
2626
"""Controller that follows a pre-defined trajectory."""
2727

2828
def __init__(self, obs: dict[str, NDArray[np.floating]], info: dict, config: dict):

lsy_drone_racing/utils/utils.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from jax.scipy.spatial.transform import Rotation as R
1616
from ml_collections import ConfigDict
1717

18-
from lsy_drone_racing.control.controller import BaseController
18+
from lsy_drone_racing.control.controller import Controller
1919

2020
if TYPE_CHECKING:
2121
from pathlib import Path
@@ -26,7 +26,7 @@
2626
logger = logging.getLogger(__name__)
2727

2828

29-
def load_controller(path: Path) -> Type[BaseController]:
29+
def load_controller(path: Path) -> Type[Controller]:
3030
"""Load the controller module from the given path and return the Controller class.
3131
3232
Args:
@@ -45,17 +45,15 @@ def filter(mod: Any) -> bool:
4545
Args:
4646
mod: Any attribute of the controller module to be checked.
4747
"""
48-
subcls = inspect.isclass(mod) and issubclass(mod, BaseController)
48+
subcls = inspect.isclass(mod) and issubclass(mod, Controller)
4949
return subcls and mod.__module__ == controller_module.__name__
5050

5151
controllers = inspect.getmembers(controller_module, filter)
52-
controllers = [c for _, c in controllers if issubclass(c, BaseController)]
53-
assert len(controllers) > 0, (
54-
f"No controller found in {path}. Have you subclassed BaseController?"
55-
)
52+
controllers = [c for _, c in controllers if issubclass(c, Controller)]
53+
assert len(controllers) > 0, f"No controller found in {path}. Have you subclassed Controller?"
5654
assert len(controllers) == 1, f"Multiple controllers found in {path}. Only one is allowed."
5755
controller_module.Controller = controllers[0]
58-
assert issubclass(controller_module.Controller, BaseController)
56+
assert issubclass(controller_module.Controller, Controller)
5957

6058
try:
6159
return controller_module.Controller

scripts/multi_sim.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
if TYPE_CHECKING:
2424
from ml_collections import ConfigDict
2525

26-
from lsy_drone_racing.control.controller import BaseController
26+
from lsy_drone_racing.control.controller import Controller
2727
from lsy_drone_racing.envs.multi_drone_race import MultiDroneRacingEnv
2828

2929

@@ -76,7 +76,7 @@ def simulate(
7676

7777
for _ in range(n_runs): # Run n_runs episodes with the controller
7878
obs, info = env.reset()
79-
controller: BaseController = controller_cls(obs, info, config)
79+
controller: Controller = controller_cls(obs, info, config)
8080
i = 0
8181
fps = 60
8282

scripts/sim.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
if TYPE_CHECKING:
2222
from ml_collections import ConfigDict
2323

24-
from lsy_drone_racing.control.controller import BaseController
24+
from lsy_drone_racing.control.controller import Controller
2525
from lsy_drone_racing.envs.drone_race import DroneRaceEnv
2626

2727

@@ -73,7 +73,7 @@ def simulate(
7373
for _ in range(n_runs): # Run n_runs episodes with the controller
7474
done = False
7575
obs, info = env.reset()
76-
controller: BaseController = controller_cls(obs, info, config)
76+
controller: Controller = controller_cls(obs, info, config)
7777
i = 0
7878
fps = 60
7979

tests/unit/utils/test_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ml_collections import ConfigDict
66
from scipy.spatial.transform import Rotation as R
77

8-
from lsy_drone_racing.control.controller import BaseController
8+
from lsy_drone_racing.control.controller import Controller
99
from lsy_drone_racing.utils import gate_passed, load_config, load_controller
1010

1111

@@ -20,7 +20,7 @@ def test_load_controller():
2020
c = load_controller(
2121
Path(__file__).parents[3] / "lsy_drone_racing/control/trajectory_controller.py"
2222
)
23-
assert issubclass(c, BaseController), f"Controller {c} is not a subclass of BaseController"
23+
assert issubclass(c, Controller), f"Controller {c} is not a subclass of `Controller`"
2424

2525

2626
@pytest.mark.unit

0 commit comments

Comments
 (0)