Run Simple Agents#
Run Isaac Lab’s zero and random agents to check that the robot loads and responds correctly. Both agents send 14 numbers on each control step, one joint-angle offset per servo. Watch what happens when all offsets stay at zero, then when the offsets change every step.
Compare Zero and Random Actions#
Both agents run the passive task from lesson 3. The robot’s body is free to move, and the environment has no reward terms. Run the commands from the IsaacLabTutorial repository root. You can watch the robot move in your browser.
Run the Zero Agent#
A zero action requests zero offset from each default joint position. The motors remain active and try to hold that nominal pose.
uv run --extra viser isaaclab zero_agent \
--task Course-Microduck-Passive-v0 --num_envs 16 --viz viser
Open the Live Viser Viewer#
Wait for Viser to print its startup URL in the terminal. Keep the agent running while you open the viewer.
Open the URL printed in the terminal. If you’re running on a remote GPU host, forward the Viser port over SSH and open the forwarded address in your local browser.
Refresh the viewer after starting a new simulation.
After observing a few resets, press Ctrl+C in the terminal before starting the next agent.
This six-second recording shows all four automatic resets. The red label marks where the simulator returns the robot to its starting pose. Watch the body tilt before each reset. Your randomized run can differ.
Run the Random Agent#
The random agent picks new offsets for all 14 joints at each control step.
uv run --extra viser isaaclab random_agent \
--task Course-Microduck-Passive-v0 --num_envs 16 --viz viser
Random joint targets change every 20 ms without using feedback. Press Ctrl+C to stop the random agent after observing a few resets.
Both built-in agents run the same line at each control step:
env.step(action_policy())
The inner call chooses the actions, and the outer call applies them and advances
the simulation. With 16 ducks and 14 servos each, the action tensor has shape
(16, 14). For the full code, see Isaac Lab’s shared control
loop
and the random and zero action
policies.
Turn the Head (Optional)#
Feel free to skip this section and move to the next lesson where you’ll start training the Microduck to balance. If you want to see how the head moves, run the head-yaw agent. It uses a sine wave to actuate the head joint while the robot’s root is fixed.
Run scripts/head_agent.py from the root of your IsaacLabTutorial checkout. The
script uses a fixed-root duck. Open Viser using the viewer instructions.
uv run --extra viser python scripts/head_agent.py --steps 1500 --real-time --viz viser
How Does the Head-Yaw Agent Work?#
Start the simulation. The script disables Warp gradient generation before
loading the simulator modules. It reads the step count, real-time pacing flag,
observation-printing flag, and Isaac Lab launcher options (including --viz).
It requires at least two steps to measure motion. These two lines serve the
same purpose as --task and --num_envs in the zero-agent command:
cfg, _ = resolve_task_config("Course-Microduck-Inspect-v0", "", overrides=[])
cfg.scene.num_envs = 1
Find the joint. Inside launch_simulation, the script creates the Gymnasium
environment and resets it. It looks up the head twice. The first index selects
the measured angle in the simulated robot. The second selects the target in
the policy’s 14-entry action vector. The robot and policy store joints in
different orders.
joint_ids, _ = robot.find_joints("head_yaw")
action_index = MICRODUCK_JOINT_NAMES.index("head_yaw")
Choose an action and advance one step. Each pass through the loop starts with the zero agent’s offsets for one duck. The next line changes only column 7, requesting a sine wave with an amplitude of 0.15 rad and a period of two simulated seconds. The random agent would sample all 14 entries here. All three agents pass their chosen actions to the same environment interface.
action = torch.zeros((1, 14), device=env.unwrapped.device)
action[:, action_index] = 0.15 * math.sin(2 * math.pi * step * env.unwrapped.step_dt / 2.0)
observations, _, _, _, _ = env.step(action)
Read the response. After each step, the script records the actual head
angle. For --inspect-observations, it uses the observation manager’s term
names and shapes to locate each signal in the actor vector. It prints the
actor and critic term names, then reports the head angle, its offset from
home, the actor’s head-yaw reading, projected gravity, and velocity command
every 25 steps.
readings.append(robot.data.joint_pos.torch[0, joint_ids[0]].item())
Check that the head moved. With --real-time, the loop sleeps for the
remaining time in each control interval so you can follow the motion in Viser.
At the end, the script computes the range from the highest and lowest
angle readings. The check fails if the range is under 0.005 rad or any
reading is infinite or NaN. If it passes, the script prints the measured
range and the step count. The finally block closes the
environment even if the check fails.
span = max(readings) - min(readings)