control.controller¶
lsy_drone_racing.control.controller
¶
Base class for controller implementations.
Your task is to implement your own controller. This class must be the parent class of your implementation. You have to use the same function signatures as defined by the base class. Apart from that, you are free to add any additional methods, attributes, or classes to your controller.
As an example, you could load the weights of a neural network in the constructor and use it to compute the control commands in the compute_control method. You could also use the step_callback method to update the controller state at runtime.
Note
You can only define one controller class in a single file. Otherwise we will not be able to determine which class to use.
Classes¶
Controller(obs, info, config)
¶
Bases: ABC
Base class for controller implementations.
Initialization of the controller.
Instructions
The controller's constructor has access the initial observation obs, the a priori
information contained in dictionary info, and the config of the race track. Use this
method to initialize constants, counters, pre-plan trajectories, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obs
|
dict[str, NDArray[floating]]
|
The initial observation of the environment's state. See the environment's observation space for details. |
required |
info
|
dict
|
The initial environment information from the reset. |
required |
config
|
dict
|
The race configuration. See the config files for details. Contains additional information such as disturbance configurations, randomizations, etc. |
required |
Source code in lsy_drone_racing/control/controller.py
Methods:¶
compute_control(obs, info=None)
abstractmethod
¶
Compute the next desired state of the drone.
Instructions
Implement this method to return the target state to be sent to the Crazyflie.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obs
|
dict[str, NDArray[floating]]
|
The current observation of the environment. See the environment's observation space for details. |
required |
info
|
dict | None
|
Optional additional information as a dictionary. |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[floating]
|
A drone state command [x, y, z, vx, vy, vz, ax, ay, az, yaw, rrate, prate, yrate] in |
NDArray[floating]
|
absolute coordinates or an attitude command [thrust, roll, pitch, yaw] as a numpy array. |
Source code in lsy_drone_racing/control/controller.py
episode_callback()
¶
Callback function called once after each episode.
You can use this function to reset your controller's internal state, save training data, train your models, compute additional statistics, etc.
Instructions
Use any collected information to learn, adapt, and/or re-plan.
Source code in lsy_drone_racing/control/controller.py
episode_reset()
¶
render_callback(sim)
¶
Callback function called before the environment's rendering.
You can use this function to render additional information on the screen, such as the planned trajectory, the drone's target state, etc.
Source code in lsy_drone_racing/control/controller.py
reset()
¶
step_callback(action, obs, reward, terminated, truncated, info)
¶
Callback function called once after the control step.
You can use this function to update your controller's internal state, save training data, update your models, and to terminate the episode.
Instructions
Use any collected information to learn, adapt, and/or re-plan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
NDArray[floating]
|
Latest applied action. |
required |
obs
|
dict[str, NDArray[floating]]
|
Latest environment observation. |
required |
reward
|
float
|
Latest reward. |
required |
terminated
|
bool
|
Latest terminated flag. |
required |
truncated
|
bool
|
Latest truncated flag. |
required |
info
|
dict
|
Latest information dictionary. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A flag to signal if the controller has finished. |