Interacting with an articulation#
Set a robot’s root and joint states, then apply joint commands during simulation. This example builds on Interacting with a rigid object and uses an existing robot configuration. To create a configuration, see Robot and articulation configuration; to adapt its spawn properties to PhysX or Newton, see Choosing shared and backend-specific settings.
The Code#
The tutorial corresponds to the run_articulation.py script in the scripts/tutorials/01_assets
directory.
Code for run_articulation.py
1# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
2# All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5
6"""This script demonstrates how to spawn a cart-pole and interact with it.
7
8.. code-block:: bash
9
10 # Usage
11 uv run --extra ov python scripts/tutorials/01_assets/run_articulation.py
12
13"""
14
15"""Parse the command-line arguments first."""
16
17
18import argparse
19from types import SimpleNamespace
20
21from isaaclab_ov.physics import OvPhysxCfg
22
23from isaaclab.app import add_launcher_args, launch_simulation
24from isaaclab.scene import InteractiveSceneCfg
25from isaaclab.utils import clone, instantiate
26
27# add argparse arguments
28parser = argparse.ArgumentParser(description="Tutorial on spawning and interacting with an articulation.")
29# append simulation launcher cli args
30add_launcher_args(parser)
31parser.set_defaults(visualizer=["newton_rtx"])
32# parse the arguments
33args_cli = parser.parse_args()
34
35"""Rest everything follows."""
36
37import torch
38
39import isaaclab.sim as sim_utils
40from isaaclab.assets import Articulation, AssetBaseCfg
41from isaaclab.sim import SimulationContext
42
43##
44# Pre-defined configs
45##
46from isaaclab_assets import CARTPOLE_CFG # isort:skip
47
48
49def design_scene() -> tuple[dict, list[list[float]]]:
50 """Designs the scene."""
51 # Ground-plane
52 cfg = sim_utils.GroundPlaneCfg()
53 cfg.func("/World/defaultGroundPlane", cfg)
54 # Lights
55 cfg = sim_utils.DomeLightCfg(intensity=3000.0, color=(0.75, 0.75, 0.75))
56 cfg.func("/World/Light", cfg)
57
58 # Create separate groups called "Origin1", "Origin2"
59 # Each group will have a robot in it
60 origins = [[0.0, 0.0, 0.0], [-1.0, 0.0, 0.0]]
61 # Origin 1
62 sim_utils.create_prim("/World/Origin1", "Xform", translation=origins[0])
63 # Origin 2
64 sim_utils.create_prim("/World/Origin2", "Xform", translation=origins[1])
65
66 # Articulation
67 cartpole_cfg = clone(CARTPOLE_CFG)
68 cartpole_cfg.prim_path = "/World/Origin.*/Robot"
69 cartpole = Articulation(cfg=cartpole_cfg)
70
71 # return the scene information
72 scene_entities = {"cartpole": cartpole}
73 return scene_entities, origins
74
75
76def run_simulator(sim: sim_utils.SimulationContext, entities: dict[str, Articulation], origins: torch.Tensor):
77 """Runs the simulation loop."""
78 # Extract scene entities
79 # note: we only do this here for readability. In general, it is better to access the entities directly from
80 # the dictionary. This dictionary is replaced by the InteractiveScene class in the next tutorial.
81 robot = entities["cartpole"]
82 # Define simulation stepping
83 sim_dt = sim.get_physics_dt()
84 count = 0
85 # Simulation loop
86 while sim.is_running():
87 # Reset
88 if count % 500 == 0:
89 # reset counter
90 count = 0
91 # reset the scene entities
92 # root state
93 # we offset the root state by the origin since the states are written in simulation world frame
94 # if this is not done, then the robots will be spawned at the (0, 0, 0) of the simulation world
95 root_pose = robot.data.default_root_pose.torch.clone()
96 root_pose[:, :3] += origins
97 robot.write_root_pose_to_sim_index(root_pose=root_pose)
98 root_vel = robot.data.default_root_vel.torch.clone()
99 robot.write_root_velocity_to_sim_index(root_velocity=root_vel)
100 # set joint positions with some noise
101 joint_pos, joint_vel = (
102 robot.data.default_joint_pos.torch.clone(),
103 robot.data.default_joint_vel.torch.clone(),
104 )
105 joint_pos += torch.rand_like(joint_pos) * 0.1
106 robot.write_joint_position_to_sim_index(position=joint_pos)
107 robot.write_joint_velocity_to_sim_index(velocity=joint_vel)
108 # clear internal buffers
109 robot.reset()
110 print("[INFO]: Resetting robot state...")
111 # Apply random action
112 # -- generate random joint efforts
113 efforts = torch.randn_like(robot.data.joint_pos.torch) * 5.0
114 # -- apply action to the robot
115 robot.actuators.target_command.set_effort_index(value=efforts)
116 # -- write data to sim
117 robot.write_data_to_sim()
118 # Perform step
119 sim.step()
120 # Increment counter
121 count += 1
122 # Update buffers
123 robot.update(sim_dt)
124
125
126def main():
127 """Main function."""
128 # Configure the simulation
129 sim_cfg = sim_utils.SimulationCfg(
130 physics=OvPhysxCfg(),
131 device=args_cli.device,
132 )
133 # Launch the simulator runtime that the configuration needs
134 scene_cfg = InteractiveSceneCfg(num_envs=1, env_spacing=0.0)
135 scene_cfg.world = AssetBaseCfg(prim_path="/World")
136 with launch_simulation(SimpleNamespace(sim=sim_cfg, scene=scene_cfg), args_cli):
137 # Initialize the simulation context
138 sim = SimulationContext(sim_cfg)
139 # Set main camera
140 sim.set_camera_view([2.5, 0.0, 4.0], [0.0, 0.0, 2.0])
141 # Design scene
142 scene_entities, scene_origins = design_scene()
143 scene_origins = torch.tensor(scene_origins, device=sim.device)
144 _scene = instantiate(scene_cfg)
145 # Play the simulator
146 sim.reset()
147 # Now we are ready!
148 print("[INFO]: Setup complete...")
149 # Run the simulator
150 run_simulator(sim, scene_entities, scene_origins)
151
152
153if __name__ == "__main__":
154 # run the main function
155 main()
The Code Explained#
Designing the scene#
Similar to the previous tutorial, we populate the scene with a ground plane and a distant light. Instead of spawning rigid objects, we now spawn a cart-pole articulation from its USD file. The cart-pole is a simple robot consisting of a cart and a pole attached to it. The cart is free to move along the x-axis, and the pole is free to rotate about the cart. The USD file for the cart-pole contains the robot’s geometry, joints, and other physical properties.
For the cart-pole, we use its pre-defined configuration object, which is an instance of the
assets.ArticulationCfg class. This class contains information about the articulation’s spawning strategy,
default initial state, actuator models for different joints, and other meta-information. A deeper-dive into how to
create this configuration object is provided in the Robot and articulation configuration tutorial.
As seen in the previous tutorial, we can spawn the articulation into the scene in a similar fashion by creating
an instance of the assets.Articulation class by passing the configuration object to its constructor.
# Create separate groups called "Origin1", "Origin2"
# Each group will have a robot in it
origins = [[0.0, 0.0, 0.0], [-1.0, 0.0, 0.0]]
# Origin 1
sim_utils.create_prim("/World/Origin1", "Xform", translation=origins[0])
# Origin 2
sim_utils.create_prim("/World/Origin2", "Xform", translation=origins[1])
# Articulation
cartpole_cfg = clone(CARTPOLE_CFG)
cartpole_cfg.prim_path = "/World/Origin.*/Robot"
cartpole = Articulation(cfg=cartpole_cfg)
Running the simulation loop#
Continuing from the previous tutorial, we reset the simulation at regular intervals, set commands to the articulation, step the simulation, and update the articulation’s internal buffers.
Resetting the simulation#
Similar to a rigid object, an articulation also has a root state. This state corresponds to the root body in the articulation tree. On top of the root state, an articulation also has joint states. These states correspond to the joint positions and velocities.
To reset the articulation, we first set the root state by calling the
write_root_pose_to_sim_index() and
write_root_velocity_to_sim_index() methods. Similarly, we set the joint states by
calling the write_joint_position_to_sim_index() and
write_joint_velocity_to_sim_index() methods.
Finally, we call the reset() method to reset any internal buffers and caches.
# reset the scene entities
# root state
# we offset the root state by the origin since the states are written in simulation world frame
# if this is not done, then the robots will be spawned at the (0, 0, 0) of the simulation world
root_pose = robot.data.default_root_pose.torch.clone()
root_pose[:, :3] += origins
robot.write_root_pose_to_sim_index(root_pose=root_pose)
root_vel = robot.data.default_root_vel.torch.clone()
robot.write_root_velocity_to_sim_index(root_velocity=root_vel)
# set joint positions with some noise
joint_pos, joint_vel = (
robot.data.default_joint_pos.torch.clone(),
robot.data.default_joint_vel.torch.clone(),
)
joint_pos += torch.rand_like(joint_pos) * 0.1
robot.write_joint_position_to_sim_index(position=joint_pos)
robot.write_joint_velocity_to_sim_index(velocity=joint_vel)
# clear internal buffers
robot.reset()
Stepping the simulation#
Applying commands to the articulation involves two steps:
Setting actuator commands: This provides desired position, velocity, or effort values to the actuator models in joint-side coordinates.
Writing the data to the simulation: Based on the articulation’s configuration, this step handles any actuation conversions and writes the converted values to the simulation buffers.
In this tutorial, we control the articulation using joint effort commands. For this to work, we need to set the articulation’s stiffness and damping parameters to zero. This is done a-priori inside the cart-pole’s pre-defined configuration object.
At every step, we randomly sample joint efforts and set them on the articulation’s actuator collection
by calling robot.actuators.target_command.set_effort_index. After setting the commands,
we call the write_data_to_sim() method to write the data to the simulation buffers.
Finally, we step the simulation.
# Apply random action
# -- generate random joint efforts
efforts = torch.randn_like(robot.data.joint_pos.torch) * 5.0
# -- apply action to the robot
robot.actuators.target_command.set_effort_index(value=efforts)
# -- write data to sim
robot.write_data_to_sim()
Updating the state#
Every articulation class contains a assets.ArticulationData object. This stores the state of the
articulation. To update the state inside the buffer, we call the assets.Articulation.update() method.
# Update buffers
robot.update(sim_dt)
The Code Execution#
This script uses OvPhysX and the Newton RTX visualizer without Isaac Sim. Install the ov extra
and run the command below:
uv run --extra ov isaaclab -p scripts/tutorials/01_assets/run_articulation.py --viz newton_rtx
This command should open a stage with a ground plane, lights, and two cart-poles that are moving around randomly.
Press Ctrl+C in the terminal to stop the simulation.
In this tutorial, we learned how to create and interact with a simple articulation. We saw how to set the state of an articulation (its root and joint state) and how to apply commands to it. We also saw how to update its buffers to read the latest state from the simulation.
The packaged Zoo demo also animates several robot families in one scene:
uv run --extra isaacsim isaaclab demo zoo --viz kit