Module: MJObject

template<typename mjsObjectType>
class MJObject
#include <MJObject.h>

A wrapper class for managing a MuJoCo object.

This class provides functionality for configuring and accessing a MuJoCo object, including name and ID retrieval. It also assigns a default name to nameless objects.

Template Parameters:

mjsObjectType – The MuJoCo object type.

Public Functions

inline MJObject(mjsObjectType *mjsObject)

Constructs an MJObject with a given MuJoCo object pointer.

Initializes the MuJoCo object’s name, setting it to a unique default name if it is unnamed.

Parameters:

mjsObject – Pointer to the MuJoCo object.

inline void configure(const mjModel *mujocoModel)

Configures the MJObject by linking it to the given MuJoCo model.

Sets the object’s ID by searching for its name within the MuJoCo model. Throws an exception if the object cannot be found.

Parameters:

mujocoModel – Pointer to the MuJoCo model to configure the object with.

Throws:

std::runtime_error – If the object name cannot be found in the model.

inline const std::string &getName() const

Retrieves the name of the MJObject.

Returns:

The object’s name.

inline size_t getId() const

Retrieves the ID of the MJObject.

Throws:

std::runtime_error – If the object has not been configured yet.

Returns:

The object’s ID.

Protected Attributes

std::string name

The name of the MJObject.

std::optional<size_t> id

The ID of the MJObject, set during configuration.

mjsObjectType *mjsObject

Pointer to the underlying MuJoCo object.