💾 Data#
In the previous chapter, we learned that SceneModel is used to describe the static physical model. This chapter focuses on the creation and usage of SceneData.
Basic Concepts#
SceneData is the dynamic data container in the MotrixSim simulation system, storing all variables that change during runtime. These data include not only joint positions and velocities, but also the spatial positions and orientations of objects, sensor values, and more.
State updates in SceneData require calling kinematic functions to update the system state.
Creating Data#
Basic Creation#
# tag::load_model_from_file[]
# The scene description file
path = "examples/assets/empty.xml"
# Load the scene model
model = load_model(path)
# end::load_model_from_file[]
# Create the render instance of the model
render.launch(model)
# Create the physics data of the model
data = SceneData(model)
For the complete example, see examples/getting_started/empty.py.
Multiple Data Instances#
MotrixSim supports creating multiple independent data instances based on the same SceneModel. Each data instance is isolated and can be updated independently, making it suitable for scenarios such as parallel simulation in multiple environments.
For more details, see the Parallel Simulation section.
State Access#
Direct Array Access#
SceneData provides direct access to system state arrays:
pos = data.dof_pos_array
vel = data.dof_vel_array
For detailed SceneData attributes, see: API Quick Reference - SceneData
Access via Components#
Combined with the Named Access of SceneModel, you can access or set specific states through component objects:
# Get position from body directly
dof_pos = cube_fb.get_dof_pos(data)
# Get velocity from body directly
dof_vel = cube_fb.get_dof_vel(data)
# Get position and rotation directly
# Note: This data will be delayed by one frame
pose = cube.get_pose(data)
print(f"dof_pos is : {dof_pos}")
print(f"dof_vel is : {dof_vel}")
print(f"pose is {pose}")
For the complete example, see examples/physics/body.py.
API Reference#
For more APIs related to SceneData, see SceneData API