wa_simulator.visualization
¶
Classes
Base class to be used for visualization of the simulation world. |
|
Matplotlib visualizer of the simulator world and the vehicle |
-
class
WAVisualization
[source]¶ Bases:
wa_simulator.base.WABase
Base class to be used for visualization of the simulation world.
Inherits from WABase, so this class and any derived classes can be seen as components. Derived classes can/should use various world attributes to visualize the simulation. Matplotlib and irrlicht are two example visualizations that, depending on the simulation configuration, users may select. Additional visualizations may be implemented, as well.
-
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
-
abstract
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
-
abstract
visualize
(self, assets, *args, **kwargs)[source]¶ Helper method that visualizes some object(s) in the chosen visualizer
Different visualizations will visualize the object(s) in different ways. This is an abstract method, so it must be implemented.
- Parameters
assets (list) – The object(s) to visualize
*args – Positional arguments that are specific to the underyling visualizer implementation
**kwargs – Keyworded arguments that are specific to the underlying visualizer implementation
-
abstract
-
class
WAMatplotlibVisualization
(system: WASystem, vehicle: WAVehicle, vehicle_inputs: WAVehicleInputs, environment: WAEnvironment = None, plotter_type: str = 'single', opponents: list = [], record: bool = False, record_folder: str = 'OUTPUT/', **kwargs)[source]¶ Bases:
wa_simulator.visualization.WAVisualization
Matplotlib visualizer of the simulator world and the vehicle
Plotter requires a vehicle and should be used for vehicle simulations where a 2d world representation is adequate. Furthermore, for vehicle models that aren’t implemented through Chrono, this is the only implemented visualization for users.
There are three types of matplotlib plotters currently implemented: “single”, “multi” and “jupyter”. Each has a different purpose with the same goal (to visualize the simulation).
single:
Uses a single thread where visualization updates are done sequentially with other simulation components.
Worse performance than multi.
multi:
Uses two threads where visualization updates are placed on a separate threads and updates are asynchronous. State information of the environment and vehicle are passed to the plotter on each update, but updates of the visuals are done at a fixed rate(10 [Hz]).
Better performance than single.
jupyter:
Supports visualization of a matplotlib window in a jupyter notebook.
Performance is very poor. Do not use outside of jupyter.
- Parameters
system (WASystem) – system used to grab certain parameters of the simulation
vehicle (WAVehicle) – vehicle to render in the matplotlib plot window
vehicle_inputs (WAVehicleInputs) – the vehicle inputs
environment (WAEnvironment, optional) – An environment with various world assets to visualize. Defaults to None (doesn’t visualize anything).
plotter_type (str, optional) – Type of plotter. “single” for single threaded, “multi” for multi threaded (fastest), “jupyter” if jupyter is used. Defaults to “single”.
opponents (list, optional) – List of other
WAVehicle
’s that represent opponents. Used for rendering.record (bool, optional) – If set to true, images will be saved under record_filename. Defaults to False (doesn’t save images).
record_folder (str, optional) – The folder to save images to. Defaults to “OUTPUT/”.
**kwargs – Additional arguments that are based to the underlying plotter implementation.
- Raises
ValueError – plotter_type isn’t recognized
-
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
-
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
-
register_key_press_event
(self, callback)[source]¶ Register a key press callback with the matplotlib visualization
- Parameters
callback (function) – the callback to invoke when a key is pressed
-
plot
(self, *args, **kwargs)[source]¶ Pass plot info to the underyling plotter
In some cases, additional information will want to be plotted in the plotter window. For example, in a vehicle simulation where a controller is attempting to follow a path, that path may want to be visualized in the matplotlib window. This method faciliates that functionality.
See the matplotlib docs to see additional *args and **kwargs arguments.
- Parameters
*args – positional arguments that are passed to the underyling plotter (and subsequently to matplotlib)
**kwargs – keyworded arguments that are passed to the underyling plotter (and subsequently to matplotlib)
-
visualize
(self, assets, *args, **kwargs)[source]¶ Helper method that visualizes some object(s) in the chosen visualizer
Different visualizations will visualize the object(s) in different ways. This is an abstract method, so it must be implemented.
- Parameters
assets (list) – The object(s) to visualize
*args – Positional arguments that are specific to the underyling visualizer implementation
**kwargs – Keyworded arguments that are specific to the underlying visualizer implementation