simulator

class jiminy_py.simulator.Simulator(robot, controller=None, engine_class=<class 'jiminy_py.core.Engine'>, use_theoretical_model=False, viewer_backend=None, **kwargs)[source]

Bases: object

This class wraps the different submodules of Jiminy, namely the robot, controller, engine, and viewer, as a single simulation environment. The user only as to create a robot and associated controller if any, and give high-level instructions to the simulator.

Parameters
  • robot (jiminy_py.core.Robot) – Jiminy robot already initialized.

  • controller (Optional[jiminy_py.core.AbstractController]) – Jiminy (observer-)controller already initialized. Optional: None by default.

  • engine_class (Type[jiminy_py.core.Engine]) – Class of engine to use. Optional: jiminy_py.core.Engine by default.

  • use_theoretical_model (bool) – Whether the state corresponds to the theoretical model when updating and fetching the robot’s state.

  • viewer_backend (Optional[str]) – Backend of the viewer, e.g. panda3d or meshcat. Optional: It is setup-dependent. See Viewer documentation for details about it.

  • kwargs (Any) – Used arguments to allow automatic pipeline wrapper generation.

Return type

None

classmethod build(urdf_path, hardware_path=None, mesh_path=None, has_freeflyer=True, config_path=None, avoid_instable_collisions=True, debug=False, **kwargs)[source]

Create a new simulator instance from scratch, based on configuration files only.

Parameters
  • urdf_path (str) – Path of the urdf model to be used for the simulation.

  • hardware_path (Optional[str]) – Path of Jiminy hardware description toml file. Optional: Looking for ‘*_hardware.toml’ file in the same folder and with the same name.

  • mesh_path (Optional[str]) – Path to the folder containing the model meshes. Optional: Env variable ‘JIMINY_DATA_PATH’ will be used if available.

  • has_freeflyer (bool) – Whether the robot is fixed-based wrt its root link, or can move freely in the world. Optional: True by default.

  • config_path (Optional[str]) – Configuration toml file to import. It will be imported AFTER loading the hardware description file. It can be automatically generated from an instance by calling export_config_file method. Optional: Looking for ‘*_options.toml’ file in the same folder and with the same name. If not found, using default configuration.

  • avoid_instable_collisions (bool) – Prevent numerical instabilities by replacing collision mesh by vertices of associated minimal volume bounding box, and replacing primitive box by its vertices.

  • debug (bool) – Whether or not the debug mode must be activated. Doing it enables temporary files automatic deletion.

  • kwargs – Keyword arguments to forward to class constructor.

Return type

jiminy_py.simulator.Simulator

property pinocchio_model: pinocchio.pinocchio_pywrap.Model

Getter of the pinocchio model, depending on the value of ‘use_theoretical_model’.

property pinocchio_data: pinocchio.pinocchio_pywrap.Data

Getter of the pinocchio data, depending on the value of ‘use_theoretical_model’.

property state: Tuple[numpy.ndarray, numpy.ndarray]

Getter of the current state of the robot.

Warning

Return a reference whenever it is possible, which is computationally efficient but unsafe.

property log_data: Dict[str, numpy.ndarray]

Getter of the telemetry variables.

property log_constants: Dict[str, str]

Getter of the telemetry constants.

property is_viewer_available: bool

Returns whether or not a viewer instance associated with the robot is available.

seed(seed)[source]

Set the seed of the simulation and reset the simulation.

Warning

It also resets the low-level jiminy Engine. Therefore one must call the reset method manually afterward.

Parameters

seed (int) – Desired seed (Unsigned integer 32 bits).

Return type

None

reset(remove_all_forces=False)[source]

Reset the simulator.

It resets the simulation time to zero, and generate a new random model of the robot. If one wants to get exactly the same result as before, either set the randomness of the model and sensors to zero, or set the seed once again to reinitialize the random number generator.

Parameters

remove_all_forces (bool) – Whether or not to remove already registered external forces. Note that it can also be done separately by calling remove_all_forces method. Optional: Do not remove by default.

start(q_init, v_init, a_init=None, is_state_theoretical=False)[source]

Initialize a simulation, starting from (q_init, v_init) at t=0.

Parameters
  • q_init (numpy.ndarray) – Initial configuration.

  • v_init (numpy.ndarray) – Initial velocity.

  • a_init (Optional[numpy.ndarray]) – Initial acceleration. It is only used by acceleration dependent sensors and controllers, such as IMU and force sensors.

  • is_state_theoretical (bool) – Whether or not the initial state is associated with the actual or theoretical model of the robot.

Return type

None

step(step_dt=- 1)[source]

Integrate system dynamics from current state for a given duration.

Parameters

step_dt (float) – Duration for which to integrate. -1 to use default duration, namely until the next breakpoint if any, or ‘engine_options[“stepper”][“dtMax”]’.

Return type

None

simulate(t_end, q_init, v_init, a_init=None, is_state_theoretical=True, log_path=None, show_progress_bar=True)[source]

Run a simulation, starting from x0=(q0,v0) at t=0 up to tf.

Note

Optionally, log the result of the simulation.

Parameters
  • t_end (float) – Simulation end time.

  • q_init (numpy.ndarray) – Initial configuration.

  • v_init (numpy.ndarray) – Initial velocity.

  • a_init (Optional[numpy.ndarray]) – Initial acceleration.

  • is_state_theoretical (bool) – Whether or not the initial state is associated with the actual or theoretical model of the robot.

  • log_path (Optional[str]) – Save log data to this location. Disable if None. Note that the format extension ‘.data’ is enforced. Optional, disable by default.

  • show_progress_bar (bool) – Whether or not to display a progress bar during the simulation. None to enable only if available. Optional: None by default.

Return type

None

render(return_rgb_array=False, width=None, height=None, camera_xyzrpy=None, **kwargs)[source]
Render the current state of the simulation. One can display it

or return an RGB array instead.

Note

Gepetto-gui supports parallel rendering, which means that one can display multiple simulations at the same time in different tabs.

Parameters
  • return_rgb_array (bool) – Whether or not to return the current frame as an rgb array.

  • width (Optional[int]) – Width of the returned RGB frame, if enabled.

  • height (Optional[int]) – Height of the returned RGB frame, if enabled.

  • camera_xyzrpy (Optional[Tuple[Union[Tuple[float, float, float], numpy.ndarray], Union[Tuple[float, float, float], numpy.ndarray]]]) – Tuple position [X, Y, Z], rotation [Roll, Pitch, Yaw] corresponding to the absolute pose of the camera. None to disable. Optional:None by default.

  • kwargs (Any) – Extra keyword arguments to forward at Viewer initialization.

Returns

Rendering as an RGB array (3D numpy array), if enabled, None otherwise.

Return type

Optional[numpy.ndarray]

replay(extra_logs_files=(), extra_trajectories=(), **kwargs)[source]

Replay the current episode until now.

Parameters
  • kwargs (Any) – Extra keyword arguments for delegation to replay.play_trajectories method.

  • extra_logs_files (Sequence[Dict[str, numpy.ndarray]]) –

  • extra_trajectories (Sequence[jiminy_py.log.TrajectoryDataType]) –

Return type

None

close()[source]

Close the connection with the renderer.

Return type

None

plot(enable_flexiblity_data=False, **kwargs)[source]

Display common simulation data over time.

The figure features several tabs:

  • Subplots with robot configuration

  • Subplots with robot velocity

  • Subplots with robot acceleration

  • Subplots with motors torques

  • Subplots with raw sensor data (one tab for each type of sensor)

Parameters
  • enable_flexiblity_data (bool) – Enable display of flexible joints in robot’s configuration, velocity and acceleration subplots. Optional: False by default.

  • kwargs (Any) – Extra keyword arguments to forward to TabbedFigure.

Return type

None

get_controller_options()[source]

Getter of the options of Jiminy Controller.

Return type

dict

set_controller_options(options)[source]

Setter of the options of Jiminy Controller.

Parameters

options (dict) –

Return type

None

get_options()[source]

Get the options of robot (including controller), and engine.

Return type

Dict[str, Dict[str, Dict[str, Any]]]

set_options(options)[source]

Set the options of robot (including controller), and engine.

Parameters

options (Dict[str, Dict[str, Dict[str, Any]]]) –

Return type

None

export_options(config_path=None)[source]

Export the full configuration, ie the options of the robot ( including controller), and the engine.

Note

the configuration can be imported thereafter using import_options method.

Parameters

config_path (Optional[Union[str, os.PathLike]]) –

Return type

None

import_options(config_path=None)[source]

Import the full configuration, ie the options of the robot ( including controller), and the engine.

Note

Configuration can be exported beforehand using export_options method.

Parameters

config_path (Optional[Union[str, os.PathLike]]) –

Return type

None