Interacting with an articulation#
This tutorial shows how to interact with an articulated robot in the simulation. It is a continuation of the Interacting with a rigid object tutorial, where we learned how to interact with a rigid object. On top of setting the root state, we will see how to set the joint state and apply commands to the articulated robot.
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 ./isaaclab.sh -p scripts/tutorials/01_assets/run_articulation.py
12
13"""
14
15"""Launch Isaac Sim Simulator first."""
16
17
18import argparse
19
20from isaaclab.app import AppLauncher
21
22# add argparse arguments
23parser = argparse.ArgumentParser(description="Tutorial on spawning and interacting with an articulation.")
24# append AppLauncher cli args
25AppLauncher.add_app_launcher_args(parser)
26# parse the arguments
27args_cli = parser.parse_args()
28
29# launch omniverse app
30app_launcher = AppLauncher(args_cli)
31simulation_app = app_launcher.app
32
33"""Rest everything follows."""
34
35import torch
36import warp as wp
37
38import isaaclab.sim as sim_utils
39from isaaclab.assets import Articulation
40from isaaclab.sim import SimulationContext
41
42##
43# Pre-defined configs
44##
45from isaaclab_assets import CARTPOLE_CFG # isort:skip
46
47
48def design_scene() -> tuple[dict, list[list[float]]]:
49 """Designs the scene."""
50 # Ground-plane
51 cfg = sim_utils.GroundPlaneCfg()
52 cfg.func("/World/defaultGroundPlane", cfg)
53 # Lights
54 cfg = sim_utils.DomeLightCfg(intensity=3000.0, color=(0.75, 0.75, 0.75))
55 cfg.func("/World/Light", cfg)
56
57 # Create separate groups called "Origin1", "Origin2"
58 # Each group will have a robot in it
59 origins = [[0.0, 0.0, 0.0], [-1.0, 0.0, 0.0]]
60 # Origin 1
61 sim_utils.create_prim("/World/Origin1", "Xform", translation=origins[0])
62 # Origin 2
63 sim_utils.create_prim("/World/Origin2", "Xform", translation=origins[1])
64
65 # Articulation
66 cartpole_cfg = CARTPOLE_CFG.copy()
67 cartpole_cfg.prim_path = "/World/Origin.*/Robot"
68 cartpole = Articulation(cfg=cartpole_cfg)
69
70 # return the scene information
71 scene_entities = {"cartpole": cartpole}
72 return scene_entities, origins
73
74
75def run_simulator(sim: sim_utils.SimulationContext, entities: dict[str, Articulation], origins: torch.Tensor):
76 """Runs the simulation loop."""
77 # Extract scene entities
78 # note: we only do this here for readability. In general, it is better to access the entities directly from
79 # the dictionary. This dictionary is replaced by the InteractiveScene class in the next tutorial.
80 robot = entities["cartpole"]
81 # Define simulation stepping
82 sim_dt = sim.get_physics_dt()
83 count = 0
84 # Simulation loop
85 while simulation_app.is_running():
86 # Reset
87 if count % 500 == 0:
88 # reset counter
89 count = 0
90 # reset the scene entities
91 # root state
92 # we offset the root state by the origin since the states are written in simulation world frame
93 # if this is not done, then the robots will be spawned at the (0, 0, 0) of the simulation world
94 root_pose = wp.to_torch(robot.data.default_root_pose).clone()
95 root_pose[:, :3] += origins
96 robot.write_root_pose_to_sim_index(root_pose=root_pose)
97 root_vel = wp.to_torch(robot.data.default_root_vel).clone()
98 robot.write_root_velocity_to_sim_index(root_velocity=root_vel)
99 # set joint positions with some noise
100 joint_pos, joint_vel = (
101 wp.to_torch(robot.data.default_joint_pos).clone(),
102 wp.to_torch(robot.data.default_joint_vel).clone(),
103 )
104 joint_pos += torch.rand_like(joint_pos) * 0.1
105 robot.write_joint_position_to_sim_index(position=joint_pos)
106 robot.write_joint_velocity_to_sim_index(velocity=joint_vel)
107 # clear internal buffers
108 robot.reset()
109 print("[INFO]: Resetting robot state...")
110 # Apply random action
111 # -- generate random joint efforts
112 efforts = torch.randn_like(wp.to_torch(robot.data.joint_pos)) * 5.0
113 # -- apply action to the robot
114 robot.set_joint_effort_target_index(target=efforts)
115 # -- write data to sim
116 robot.write_data_to_sim()
117 # Perform step
118 sim.step()
119 # Increment counter
120 count += 1
121 # Update buffers
122 robot.update(sim_dt)
123
124
125def main():
126 """Main function."""
127 # Load kit helper
128 sim_cfg = sim_utils.SimulationCfg(device=args_cli.device)
129 sim = SimulationContext(sim_cfg)
130 # Set main camera
131 sim.set_camera_view([2.5, 0.0, 4.0], [0.0, 0.0, 2.0])
132 # Design scene
133 scene_entities, scene_origins = design_scene()
134 scene_origins = torch.tensor(scene_origins, device=sim.device)
135 # Play the simulator
136 sim.reset()
137 # Now we are ready!
138 print("[INFO]: Setup complete...")
139 # Run the simulator
140 run_simulator(sim, scene_entities, scene_origins)
141
142
143if __name__ == "__main__":
144 # run the main function
145 main()
146 # close sim app
147 simulation_app.close()
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 Writing an Asset 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 = CARTPOLE_CFG.copy()
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 Articulation.write_root_pose_to_sim() and Articulation.write_root_velocity_to_sim()
methods. Similarly, we set the joint states by calling the Articulation.write_joint_state_to_sim() method.
Finally, we call the Articulation.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 = wp.to_torch(robot.data.default_root_pose).clone()
root_pose[:, :3] += origins
robot.write_root_pose_to_sim_index(root_pose=root_pose)
root_vel = wp.to_torch(robot.data.default_root_vel).clone()
robot.write_root_velocity_to_sim_index(root_velocity=root_vel)
# set joint positions with some noise
joint_pos, joint_vel = (
wp.to_torch(robot.data.default_joint_pos).clone(),
wp.to_torch(robot.data.default_joint_vel).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 the joint targets: This sets the desired joint position, velocity, or effort targets for the articulation.
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 PhysX buffer.
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 to the articulation by calling the
Articulation.set_joint_effort_target() method. After setting the targets, we call the
Articulation.write_data_to_sim() method to write the data to the PhysX buffer. Finally, we step
the simulation.
# Apply random action
# -- generate random joint efforts
efforts = torch.randn_like(wp.to_torch(robot.data.joint_pos)) * 5.0
# -- apply action to the robot
robot.set_joint_effort_target_index(target=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#
To run the code and see the results, let’s run the script from the terminal:
./isaaclab.sh -p scripts/tutorials/01_assets/run_articulation.py
This command should open a stage with a ground plane, lights, and two cart-poles that are moving around randomly.
To stop the simulation, you can either close the window, or press Ctrl+C in the terminal.
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.
In addition to this tutorial, we also provide a few other scripts that spawn different robots. These are included
in the scripts/demos directory. You can run these scripts as:
# Spawn many different single-arm manipulators
./isaaclab.sh -p scripts/demos/arms.py
# Spawn many different quadrupeds
./isaaclab.sh -p scripts/demos/quadrupeds.py