MuJoCo Visualizer#
JAXsim provides a simple interface with MuJoCo’s visualizer. The visualizer is a separate process that communicates with the main simulation process. This allows for the simulation to run at full speed while the visualizer can run at a different frame rate.
Loaders#
- class jaxsim.mujoco.loaders.MujocoCamera(mode='fixed', target=None, fovy='45', pos='0 0 0', quat=None, axisangle=None, xyaxes=None, zaxis=None, euler=None, name=None)[source]#
Helper class storing parameters of a Mujoco camera.
Refer to the official documentation for more details: https://mujoco.readthedocs.io/en/stable/XMLreference.html#body-camera
- Parameters:
mode (str)
target (str | None)
fovy (str)
pos (str)
quat (str | None)
axisangle (str | None)
xyaxes (str | None)
zaxis (str | None)
euler (str | None)
name (str | None)
- static build_from_target_view(camera_name, lookat=(0, 0, 0), distance=3, azimut=90, elevation=-45, fovy=45, degrees=True, **kwargs)[source]#
Create a custom camera that looks at a target point.
Note
The choice of the parameters is easier if we imagine to consider a target frame T whose origin is located over the lookat point and having the same orientation of the world frame W. We also introduce a camera frame C whose origin is located over the lower-left corner of the image, and having the x-axis pointing right and the y-axis pointing up in image coordinates. The camera renders what it sees in the -z direction of frame C.
- Parameters:
camera_name (
str
) – The name of the camera.lookat (
Sequence
[float
|int
] |ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]) – The target point to look at (origin of T).distance (
float
|int
|ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]) – The distance from the target point (displacement between the origins of T and C).azimut (
float
|int
|ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]) – The rotation around z of the camera. With an angle of 0, the camera would loot at the target point towards the positive x-axis of T.elevation (
float
|int
|ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]) – The rotation around the x-axis of the camera frame C. Note that if you want to lift the view angle, the elevation is negative.fovy (
float
|int
|ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]) – The field of view of the camera.degrees (
bool
) – Whether the angles are in degrees or radians.**kwargs – Additional camera parameters.
- Return type:
- Returns:
The custom camera.
- jaxsim.mujoco.loaders.load_rod_model(model_description, is_urdf=None, model_name=None)[source]#
Loads a ROD model from a URDF/SDF file or a ROD model.
- Parameters:
model_description (
str
|Path
|Model
) – The URDF/SDF file or ROD model to load.is_urdf (
bool
|None
) – Whether the model description is a URDF file.model_name (
str
|None
) – The name of the model to load from the resource.
- Returns:
The loaded ROD model.
- Return type:
rod.Model
Model#
- class jaxsim.mujoco.model.MujocoModelHelper(model, data=None)[source]#
Helper class to create and interact with Mujoco models and data objects.
- Parameters:
model (mj.MjModel)
data (mj.MjData | None)
- base_orientation(dcm=False)[source]#
Return the orientation of the base link.
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]- Parameters:
dcm (bool)
- base_position()[source]#
Return the 3D position of the base link.
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]
- body_orientation(body_name, dcm=False)[source]#
Returns the orientation of a body.
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]- Parameters:
body_name (str)
dcm (bool)
- body_position(body_name)[source]#
Returns the position of a body.
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]- Parameters:
body_name (str)
- static build_from_xml(mjcf_description, assets=None, heightmap=None, heightmap_name='terrain', heightmap_radius_xy=(1.0, 1.0))[source]#
Build a Mujoco model from an MJCF description.
- Parameters:
mjcf_description (
str
|Path
) – A string containing the XML description of the Mujoco model or a path to a file containing the XML description.assets (
dict
[str
,Any
] |None
) – An optional dictionary containing the assets of the model.heightmap (
Callable
[[Union
[float
,Array
,ndarray
,bool
,number
,bool
,int
,complex
],Union
[float
,Array
,ndarray
,bool
,number
,bool
,int
,complex
]],Union
[float
,Array
,ndarray
,bool
,number
,bool
,int
,complex
]] |None
) – A function in two variables that returns the height of a terrain in the specified coordinate point.heightmap_name (
str
) – The default name of the heightmap in the MJCF description to load the corresponding configuration.heightmap_radius_xy (
tuple
[float
,float
]) – The extension of the heightmap in the x-y surface corresponding to the plane over which the grid of the sampled heightmap is generated.
- Return type:
- Returns:
A MujocoModelHelper object.
- geometry_orientation(geometry_name, dcm=False)[source]#
Returns the orientation of a geometry.
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]- Parameters:
geometry_name (str)
dcm (bool)
- geometry_position(geometry_name)[source]#
Returns the position of a geometry.
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]- Parameters:
geometry_name (str)
- gravity()[source]#
Return the 3D gravity vector.
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]
- joint_dofs(joint_name)[source]#
Returns the number of DoFs of a joint.
- Return type:
int
- Parameters:
joint_name (str)
- joint_position(joint_name)[source]#
Returns the position of a joint.
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]- Parameters:
joint_name (str)
- joint_positions(joint_names=None)[source]#
Returns the positions of the joints.
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]- Parameters:
joint_names (list[str] | None)
- set_base_orientation(orientation, dcm=False)[source]#
Set the 3D position of the base link.
- Return type:
None
- Parameters:
orientation (ndarray[Any, dtype[_ScalarType_co]])
dcm (bool)
- set_base_position(position)[source]#
Set the 3D position of the base link.
- Return type:
None
- Parameters:
position (ndarray[Any, dtype[_ScalarType_co]])
- set_joint_position(joint_name, position)[source]#
Sets the position of a joint.
- Return type:
None
- Parameters:
joint_name (str)
position (ndarray[Any, dtype[_ScalarType_co]] | float)
- jaxsim.mujoco.model.generate_hfield(heightmap, samples_xy=(11, 11), radius_xy=(1.0, 1.0))[source]#
Generate an array with elevation points sampled from a heightmap function.
The map will have the following format:
` heightmap[0, 0] heightmap[0, 1] ... heightmap[0, size[1]-1] heightmap[1, 0] heightmap[1, 1] ... heightmap[1, size[1]-1] ... heightmap[size[0]-1, 0] heightmap[size[0]-1, 1] ... heightmap[size[0]-1, size[1]-1] `
- Parameters:
heightmap (
Callable
[[Union
[float
,Array
,ndarray
,bool
,number
,bool
,int
,complex
],Union
[float
,Array
,ndarray
,bool
,number
,bool
,int
,complex
]],Union
[float
,Array
,ndarray
,bool
,number
,bool
,int
,complex
]]) – A function that takes two arguments (x, y) and returns the height at that point.samples_xy (
tuple
[int
,int
]) – A tuple of two integers representing the size of the grid.radius_xy (
tuple
[float
,float
]) – A tuple of two floats representing extension of the heightmap in the x-y surface corresponding to the area over which the grid of the sampled heightmap is generated.
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]- Returns:
A flat array of the sampled terrain heightmap.