Helpers

TODO: Write documentation.

gym_jiminy.common.utils.helpers.is_breakpoint(t, dt, eps)[source]

Check if ‘t’ is multiple of ‘dt’ at a given precision ‘eps’.

Parameters
  • t (float) – Current time.

  • dt (float) – Timestep.

  • eps (float) – Precision.

Return type

bool

gym_jiminy.common.utils.helpers.get_fieldnames(space, namespace='')[source]

Get generic fieldnames from gym.spaces.Space, so that it can be used in conjunction with register_variables, to register any value from gym Space to the telemetry conveniently.

Parameters
  • space (gym.spaces.space.Space) – Gym.Space on which to operate.

  • namespace (str) – Namespace used to prepend fields, using ‘.’ delimiter. Empty string to disable. Optional: Disabled by default.

Return type

Union[Dict[str, FieldDictNested], List[Union[str, ListStrRecursive]]]

gym_jiminy.common.utils.helpers.register_variables(controller, fields, data, namespace='')[source]

Register data from Gym.Space to the telemetry of a controller.

Warning

Variables are registered by reference. Consequently, the user is responsible to manage the lifetime of the data to avoid it being garbage collected, and to make sure the variables are updated when necessary, and only when it is.

Parameters
  • controller (jiminy_py.core.AbstractController) – Robot’s controller of the simulator used to register variables to the telemetry.

  • field – Nested variable names, as returned by get_fieldnames method. It can be a nested list or/and dict. The leaf are str corresponding to the name of each scalar data.

  • data (Union[Dict[str, SpaceDictNested], numpy.ndarray]) – Data from gym.spaces.Space to register. Note that the telemetry stores pointers to the underlying memory, so it only supports np.float64, and make sure to reassign data using np.copyto or [:] operator (faster).

  • namespace (str) – Namespace used to prepend fields, using ‘.’ delimiter. Empty string to disable. Optional: Disabled by default.

  • fields (Union[ValuesView[Union[Dict[str, FieldDictNested], List[Union[str, ListStrRecursive]]]], Dict[str, FieldDictNested], List[Union[str, ListStrRecursive]]]) –

Returns

Whether or not the registration has been successful.

Return type

bool