wa_simulator.controller
¶
Classes
Base class for a controller |
|
Controls a vehicle via keyboard input from a matplotlib figure |
|
Controller that communicates with a ROS2 control stack |
-
class
WAController
(system: WASystem, vehicle_inputs: WAVehicleInputs)[source]¶ Bases:
wa_simulator.base.WABase
Base class for a controller
Controllers are responsible for outputting a steering, throttle and braking value. This is done because in real life, those are the inputs our cars will have. The derived controller’s (i.e. the new class that inherits from this class) responsibility is to take inputs from the simulation and return these values through the get_inputs method.
- Parameters
system (WASystem) – The system used to manage the simulation
vehicle_inputs (WAVehicleInputs) – The vehicle inputs
- Variables
steering (float) – steering input.
throttle (float) – throttle input.
braking (float) – braking input.
-
abstract
synchronize
(self, time: float)[source]¶ Update the state of this component at the current time.
The primary reason to decouple the update method into two separate calls (i.e.
synchronize()
andadvance()
) is to provide flexibility to the user and is essentially semantic. In most simple cases, a user will only need one of the two. Furthermore, can only useadvance()
if they prefer and just update their owntime
variable. Given the unknown use cases for the simulator at the time of writing, it was chosen to provide two different methods with similar functionality as to allow the user to choose their desired implementation, rather than the writers of this package.As opposed to
advance()
, this method gets the current time of the simulation. As menthioned earlier,advance()
and a user defined time variable could be used to instead to hold the current state of the simulation. However, to aid in generality of the package, this method is provided to simply provide the current time of the simulation to the user in a decoupled manner from theadvance()
method.- Parameters
time (float) – The current time to synchronize to
-
abstract
advance
(self, step: float)[source]¶ Advance the state of this component by the specified time step.
The primary reason to decouple the update method into two separate calls (i.e.
synchronize()
andadvance()
) is to provide flexibility to the user and is essentially semantic. In most simple cases, a user will only need one of the two. Furthermore, can only useadvance()
if they prefer and just update their owntime
variable. Given the unknown use cases for the simulator at the time of writing, it was chosen to provide two different methods with similar functionality as to allow the user to choose their desired implementation, rather than the writers of this package.- Parameters
step (float) – The step size to advance this component by
-
is_ok
(self) → bool[source]¶ Check whether this component is still alive.
Depending the type of component, a specific element may “fail”. For example, when a visualization is used that presents a GUI/window, if the user closes that display, this would be considered a component death. Therefore,
is_ok()
should then return False.- Returns
bool – True if still alive, false otherwise
-
class
WAMatplotlibController
(system: WASystem, vehicle_inputs: WAVehicleInputs, vis: WAMatplotlibVisualization)[source]¶ Bases:
wa_simulator.controller._WAKeyboardController
Controls a vehicle via keyboard input from a matplotlib figure
Will asynchronously change inputs based on user input to the matplotlib window.
- Parameters
system (WASystem) – The system used to manage the simulation
vehicle_inputs (WAVehicleInputs) – The vehicle inputs
vis (WAMatplotlibVisualization) – The visualization that holds a matplotlib figure
-
class
WAROS2Controller
(system: WASystem, vehicle_inputs: WAVehicleInputs)[source]¶ Bases:
wa_simulator.controller.WAController
Controller that communicates with a ROS2 control stack
- Raises
ImportError – Will be raised if ROS 2 is not found on the system.
-
synchronize
(self, time: float)[source]¶ Update the state of this component at the current time.
The primary reason to decouple the update method into two separate calls (i.e.
synchronize()
andadvance()
) is to provide flexibility to the user and is essentially semantic. In most simple cases, a user will only need one of the two. Furthermore, can only useadvance()
if they prefer and just update their owntime
variable. Given the unknown use cases for the simulator at the time of writing, it was chosen to provide two different methods with similar functionality as to allow the user to choose their desired implementation, rather than the writers of this package.As opposed to
advance()
, this method gets the current time of the simulation. As menthioned earlier,advance()
and a user defined time variable could be used to instead to hold the current state of the simulation. However, to aid in generality of the package, this method is provided to simply provide the current time of the simulation to the user in a decoupled manner from theadvance()
method.- Parameters
time (float) – The current time to synchronize to
-
advance
(self, step: float)[source]¶ Advance the state of this component by the specified time step.
The primary reason to decouple the update method into two separate calls (i.e.
synchronize()
andadvance()
) is to provide flexibility to the user and is essentially semantic. In most simple cases, a user will only need one of the two. Furthermore, can only useadvance()
if they prefer and just update their owntime
variable. Given the unknown use cases for the simulator at the time of writing, it was chosen to provide two different methods with similar functionality as to allow the user to choose their desired implementation, rather than the writers of this package.- Parameters
step (float) – The step size to advance this component by