gym_gz.randomizers#

gym_gz.randomizers.abc#

class gym_gz.randomizers.abc.ModelDescriptionRandomizer#

Bases: ABC

abstract randomize_model_description(task, **kwargs)#

Randomize the model description.

Parameters:

task (Task) – The task that operates on the model description to randomize.

Return type:

str

Returns:

A string with the randomized model description.

class gym_gz.randomizers.abc.ModelRandomizer#

Bases: ABC

abstract randomize_model(task, **kwargs)#

Randomize the model.

Parameters:

task (Task) – The task that operates on the model to randomize.

Return type:

Model

Returns:

The randomized model.

class gym_gz.randomizers.abc.PhysicsRandomizer(randomize_after_rollouts_num=0)#

Bases: ABC

Abstract class that provides the machinery for randomizing the physics of a Task.

Parameters:

randomize_after_rollouts_num (int) – defines after many rollouts physics should be randomized (i.e. the amount of times gym.Env.reset() is called).

abstract get_engine()#

Return the physics engine to use for the rollout.

Note

Supported physics engines:

Returns:

The desired physics engine to set in the world.

increase_rollout_counter()#

Increase the rollouts counter.

Return type:

None

physics_expired()#

Checks if the physics needs to be randomized.

Return type:

bool

Returns:

True if the physics has expired, false otherwise.

abstract randomize_physics(task, **kwargs)#

Method that insert and configures the physics of a Task’s world.

By default this method loads a plugin that uses DART with no randomizations. Randomizing physics engine parameters or changing physics engine backend could be done by redefining this method and passing it to GazeboRuntime.

Parameters:

task (Task) – A task containing a world object without physics.

Return type:

None

class gym_gz.randomizers.abc.TaskRandomizer#

Bases: ABC

abstract randomize_task(task, **kwargs)#

Randomize a Task instance.

Parameters:

task (Task) – the task to randomize.

Return type:

None

Note

Note that each task has a world property that provides access to the simulated scenario.bindings.core.World.

gym_gz.randomizers.gazebo_env_randomizer#

class gym_gz.randomizers.gazebo_env_randomizer.GazeboEnvRandomizer(env, physics_randomizer=<gym_gz.randomizers.physics.dart.DART object>, **kwargs)#

Bases: Wrapper, TaskRandomizer, ABC

Base class to implement an environment randomizer for Gz sim.

The randomizer is a gym.Wrapper that extends the gym.Env.reset() method. Objects that inherit from this class are used to setup the environment for the handled Task.

In its simplest form, a randomizer populates the world with all the models that need to be part of the simulation. The task could then operate on them from a Model object.

More complex environments may require to randomize one or more simulated entities. Concrete classes that implement a randomizer could use SDFRandomizer to randomize the model and PhysicsRandomizer to randomize the physics.

Parameters:
  • env (Union[str, Callable[[Optional[Dict]], Env]]) – Defines the environment to handle. This argument could be either the string id if the environment does not need to be registered or a function that returns an environment object.

  • physics_randomizer (PhysicsRandomizer) – Object that randomizes physics. The default physics engine is DART with no randomizations.

Note

In order to randomize physics, the handled scenario.gazebo.GazeboSimulator is destroyed and created again. This operation is demanding, consider randomizing physics at a low rate.

reset(seed=None, options={}, **kwargs)#

Uses the reset() of the env that can be overwritten to change the returned data.

Return type:

tuple[ndarray, dict]