BaseObject#

safety_gymnasium.bases.base_object#

class safety_gymnasium.bases.base_object.BaseObject(type: str | None = None, name: str | None = None, engine: Engine | None = None, random_generator: RandomGenerator | None = None, agent: BaseAgent | None = None)#

Base class for obstacles.

Methods:

  • cal_cost(): Calculate the cost of the object, only when the object can be constrained, it is needed to be implemented.

  • set_agent(): Set the agent instance, only called once for each object in one environment.

  • set_engine(): Set the engine instance, only called once in safety_gymnasium.World.

  • set_random_generator(): Set the random generator instance, only called once in one environment.

  • process_config(): Process the config, used to fill the configuration dictionary which used to generate mujoco instance xml string of environments.

  • _specific_agent_config(): Modify properties according to specific agent.

  • get_config(): Define how to generate config of different objects, it will be called in process_config.

Attributes:

Methods#

safety_gymnasium.bases.base_object.BaseObject.__init__(self, type: str | None = None, name: str | None = None, engine: Engine | None = None, random_generator: RandomGenerator | None = None, agent: BaseAgent | None = None) None#

Initialize self. See help(type(self)) for accurate signature.

safety_gymnasium.bases.base_object.BaseObject.cal_cost(self) dict#

Calculate the cost of the obstacle.

Returns:

dict – Cost of the object in current environments at this timestep.

safety_gymnasium.bases.base_object.BaseObject.set_agent(self, agent: BaseAgent) None#

Set the agent instance.

Note

This method will be called only once in one environment, that is when the object is instantiated.

Parameters:

agent (BaseAgent) – Agent instance in current environment.

safety_gymnasium.bases.base_object.BaseObject.set_engine(self, engine: Engine) None#

Set the engine instance.

Note

This method will be called only once in one environment, that is when the whole environment is instantiated in safety_gymnasium.World.bind_engine().

Parameters:

engine (Engine) – Physical engine instance.

safety_gymnasium.bases.base_object.BaseObject.set_random_generator(self, random_generator: RandomGenerator) None#

Set the random generator instance.

Parameters:

random_generator (RandomGenerator) – Random generator instance.

safety_gymnasium.bases.base_object.BaseObject.process_config(self, config: dict, layout: dict, rots: float) None#

Process the config.

Note

This method is called in safety_gymnasium.bases.base_task._build_world_config() to fill the configuration dictionary which used to generate mujoco instance xml string of environments in safety_gymnasium.World.build().

safety_gymnasium.bases.base_object.BaseObject._specific_agent_config(self) None#

Modify properties according to specific agent.

Note

This method will be called only once in one environment, that is when set_agent() is called.

safety_gymnasium.bases.base_object.BaseObject.get_config(self, xy_pos: ndarray, rot: float)#

Get the config of the obstacle.

Returns:

dict – Configuration of this type of object in current environment.

Additional Methods#

abstract property BaseObject.pos: ndarray#

Get the position of the obstacle.

Returns:

np.ndarray – Position of the obstacle.