๐Ÿ“š Example Programs#

Tip

For models and code, see the MotrixSim Docs repository.

Before running the examples, please refer to ๐Ÿ› ๏ธ Environment Setup to complete the environment setup.

We provide a series of example programs to help you master the use of MotrixSim from scratch.

On all platforms (Linux, Windows, MacOS), you can run any example of interest with:

uv run examples/{example_name}.py

Note

Special note for MacOS (aarch64-apple-darwin) platform:

  • If the example uses ๐ŸŽจ Renderer (RenderApp), use:

    uv run mxpython examples/{example_name}.py
    
  • If the example does not use RenderApp (physics simulation only), use uv run which is consistent with other platforms

Most examples requiring visual rendering (such as robotic arm control, robot locomotion, etc.) use RenderApp and need uv run mxpython.

Getting Started#

Preview

File

Description

empty

empty.py

Create an empty scene, equivalent to a Hello World example.

falling_ball

falling_ball.py

A ball falls under gravity, demonstrating how to create a model and data.

API Demonstrations#

Preview

File

Description

actuator

actuator.py

Retrieve and configure actuator parameters.

body

body.py

Usage of body-related APIs; here, body specifically refers to the root world body.

joint

joint.py

Usage of joint-related APIs, including reading and writing dof_position and dof_velocity.

link

link.py

Usage of link-related APIs.

model

model.py

Usage of model-related APIs, including multi-instance scenarios for a single model.

options

options.py

Configure simulator parameters using options.

site_and_sensor

site_and_sensor.py

Usage of site and sensor-related APIs.

friction

friction.py

Scene demonstrating friction configuration.

parallelsim

parallelsim.py

Multi-environment parallel simulation.

inverse kinematics

ik.py

Demonstrates how to use the built-in IK module in MotrixSim for inverse kinematics solving.

load_from_str

load_from_str.py

Load an MJCF model from a string, demonstrating how to create a scene directly from an XML string.

combine_msd

combine_msd.py

Combine multiple MSD models, demonstrating how to use the Scene.attach() method to attach multiple models together, supporting transforms and namespace prefixes.

geom

geom.py

Usage of geometry-related APIs, showing how to access and query geometry position, velocity, and other information.

hfield

hfield.py

Usage of height field APIs, demonstrating how to access terrain height data and perform statistical analysis.

camera_control

camera_control.py

Camera control API usage, showing how to enable/disable system and scene cameras, and get camera poses.

custom_ui

custom_ui.py

Usage of custom UI elements, demonstrating how to add buttons and switches for interaction.

Interactive Control#

Preview

File

Description

keyboard_car

keyboard_car.py

Control a cart using the keyboard; demonstrates keyboard event handling. Use W to move forward, S to move backward. Turning: A to turn left, D to turn right.

mouse_click

mouse_click.py

Move a ball by clicking on the ground with the mouse; demonstrates mouse event handling.

gizmos

gizmos.py

Usage of the 3D gizmo drawing system, demonstrating how to draw spheres, cubes, capsules, arrows, grids, and other visualization helpers.

Physics Simulation#

Preview

File

Description

gyroscope

gyroscope.py

Physical simulation of a gyroscope.

gyroscope_zero_gravity

gyroscope_zero_gravity.py

Gyroscope in a zero-gravity environment, demonstrating conservation of angular momentum.

newton_cradle

newton_cradle.py

Physical simulation of Newtonโ€™s cradle.

slope

slope.py

Simulation of a block rolling down a slope.

local_arm

local_arm.py

A robotic arm composed of simple geometries and joints.

adhesion

adhesion.py

A robotic arm with adhesion actuator.

Robotics Applications#

Preview

File

Description

go1

go1.py

Random motion of the Go1 quadruped robot, demonstrating how to integrate a neural network and use .onnx files.

go2

robot_locomotion.py

Go2 quadruped keyboard control example: arrow keys and WASD control walking and turning. Use uv run examples/robot_locomotion.py --robot go2 to run.

g1

robot_locomotion.py

G1 humanoid keyboard control example: arrow keys and WASD control walking and turning. Use uv run examples/robot_locomotion.py --robot g1 to run.

g1_parlour

robot_locomotion.py

G1 humanoid keyboard control example in an indoor parlour scene: arrow keys and WASD control walking and turning. Use uv run examples/robot_locomotion.py --robot g1 --scene parlour to run.

robotic_arm

robotic_arm.py

The Stanford robotic arm uses a sequence of movement commands to pick and place a ball.

grasp_shaking_test

grasp_mx.py

Grasping and shaking test for the Franka Panda robotic arm, demonstrating how the arm grasps objects and maintains stability. Supports --object parameter to select object type (cube/ball/bottle), --shake parameter to control shaking, and --record parameter to record video.

Rendering & Visualization#

Preview

File

Description

render_settings

render_settings.py

Rendering settings configuration example, demonstrating how to use RenderSettings to configure shadows, screen-space ambient occlusion (SSAO), and other rendering effects.

partial_rendering

partial_rendering.py

Selective rendering control in batch rendering, showing how to dynamically control visibility of specific scenes in multi-environment parallel simulation. Press A/D keys to toggle partial scene visibility, Q/E keys for all scenes.

share_lights_between_envs

share_lights_between_envs.py

Light sharing optimization between environments, demonstrating how to share lights in parallel simulation to improve performance. Use --share_lights=False parameter to disable light sharing.