cambrian.eyes.eye

Defines the MjCambrianEye class, which is used to define an eye for the cambrian environment. The eye is essentially a camera that is attached to a body in the environment. The eye can render images and provide observations to the agent.

Classes

MjCambrianEyeConfig

Defines the config for an eye. Used for type hinting.

MjCambrianEye

Defines an eye for the cambrian environment. It essentially wraps a mujoco Camera

Module Contents

class MjCambrianEyeConfig[source]

Bases: hydra_config.HydraContainerConfig

Defines the config for an eye. Used for type hinting.

Variables:
  • instance (Callable[[Self, str], MjCambrianEye]) – The class instance to use when creating the eye. Takes the config and the name of the eye as arguments.

  • fov (Tuple[float, float]) – Independent of the fovy field in the MJCF xml. Used to calculate the sensorsize field. Specified in degrees. Mutually exclusive with fovy. If focal is unset, it is set to 1, 1. Will override sensorsize, if set. Fmt: fovy fovx.

  • focal (Tuple[float, float]) – The focal length of the camera. Fmt: focal_y focal_x.

  • sensorsize (Tuple[float, float]) – The size of the sensor. Fmt: height width.

  • resolution (Tuple[int, int]) – The width and height of the rendered image. Fmt: height width.

  • coord (Tuple[float, float]) – The x and y coordinates of the eye. This is used to determine the placement of the eye on the agent. Specified in degrees. This attr isn’t actually used by eye, but by the agent. The eye has no knowledge of the geometry it’s trying to be placed on. Fmt: lat lon

  • orthographic (bool) – Whether the camera is orthographic

  • renderer (MjCambrianRendererConfig) – The renderer config to use for the underlying renderer.

class MjCambrianEye(config, name, *, disable_render=False)[source]

Defines an eye for the cambrian environment. It essentially wraps a mujoco Camera object and provides some helper methods for rendering and generating the XML. The eye is attached to the parent body such that movement of the parent body will move the eye.

Parameters:
  • config (MjCambrianEyeConfig) – The configuration for the eye.

  • name (str) – The name of the eye.

Keyword Arguments:

disable_render (bool) – Whether to disable rendering. Defaults to False. This is useful for derived classes which don’t intend to use the default rendering mechanism.

generate_xml(parent_xml, geom, parent_body_name=None, parent=None)[source]

Generate the xml for the eye.

In order to combine the xml for an eye with the xml for the agent that it’s attached to, we need to replicate the path with which we want to attach the eye. For instance, if the body with which we want to attach the eye to is at mujoco/worldbody/torso, then we need to replicate that path in the new xml. This is kind of difficult with the xml library, but we’ll utilize the CambrianXML helpers for this.

Parameters:
  • parent_xml (MjCambrianXML) – The xml of the parent body. Used as a reference to extract the path of the parent body.

  • geom (MjCambrianGeometry) – The geometry of the parent body. Used to calculate the pos and quat of the eye.

  • parent_body_name (Optional[str]) – The name of the parent body. Will search for the body tag with this name, i.e. <body name=”<parent_body_name>” …>. Either this or parent must be set.

  • parent (Optional[List[Element] | Element]) – The parent element to attach the eye to. If set, parent_body_name will be ignored. Either this or parent_body_name must be set.

reset(spec)[source]

Sets up the camera for rendering. This should be called before rendering the first time.

step(obs=None)[source]

Simply calls render and sets the last observation. See render() for more information.

Parameters:

obs (Optional[ObsType]) – The observation to set. Defaults to None. This can be used by derived classes to set the observation directly.

render()[source]

Render the image from the camera. Will always only return the rgb array.

This differs from step in that this is a debug method. The rendered image here will be used to visualize the eye in the viewer.

property config: MjCambrianEyeConfig[source]

The config for the eye.

property name: str[source]

The name of the eye.

property observation_space: gymnasium.spaces.Box[source]

Constructs the observation space for the eye. The observation space is a spaces.Box with the shape of the resolution of the eye.

property prev_obs: torch.Tensor[source]

The last observation returned by self.render().