Assemble the Environment#
Connect the scene, actions, and commands in microduck/env_cfg.py so you can
run the robot in simulation. Start with an empty reward configuration. The
first exercises use simple agents, so you’ll add rewards when you start
training.
The classes in managers.py fill in the rest. ObservationsCfg gives the actor
61 inputs and the critic 76. EventsCfg handles resets and varies physical
properties between runs or episodes. TerminationsCfg ends an episode if time
runs out, the robot tilts too far, or the simulation enters an invalid state.
Append to env_cfg.py:
from isaaclab.envs import ManagerBasedRLEnvCfg
from isaaclab.sim import SimulationCfg
from isaaclab.utils.configclass import configclass
from isaaclab.visualizers import VisualizerCfg
from isaaclab_newton.physics import MJWarpSolverCfg, NewtonCfg, NewtonCollisionPipelineCfg, NewtonShapeCfg
from .managers import EventsCfg, ObservationsCfg, TerminationsCfg
from .control import ActionsCfg, CommandsCfg
from .scene import DuckSceneCfg
@configclass
class NoTermsCfg:
"""No reward or curriculum terms until the corresponding lesson adds them."""
Append the base environment to connect your configurations to the managers.
For the first exercises, __post_init__ holds commands at zero and disables
pushes. configure_simulation sets 200 physics steps per second and one action
every four steps, giving 50 policy decisions per second. The Newton settings
use the reference values for the fitted BAM motors.
Append to env_cfg.py:
@configclass
class BaseEnvCfg(ManagerBasedRLEnvCfg):
"""The runnable scene, control loop, and reset rules, before adding a reward."""
ngpus: int | None = None
nnodes: int | None = None
sim = SimulationCfg(
physics=NewtonCfg(
solver_cfg=MJWarpSolverCfg(
njmax=96,
nconmax=16,
iterations=100,
ls_iterations=50,
cone="pyramidal",
impratio=1.0,
integrator="implicitfast",
use_mujoco_contacts=False,
),
collision_cfg=NewtonCollisionPipelineCfg(max_triangle_pairs=2500000),
default_shape_cfg=NewtonShapeCfg(margin=0.0),
num_substeps=1,
)
)
scene = DuckSceneCfg(num_envs=4096, env_spacing=2.0)
actions = ActionsCfg()
observations = ObservationsCfg()
commands = CommandsCfg()
rewards = NoTermsCfg()
events = EventsCfg()
terminations = TerminationsCfg()
curriculum = NoTermsCfg()
def __post_init__(self):
self.configure_simulation()
cmd = self.commands.base_velocity
cmd.ranges.lin_vel_x = (0.0, 0.0)
cmd.ranges.lin_vel_y = (0.0, 0.0)
cmd.ranges.ang_vel_z = (0.0, 0.0)
cmd.rel_standing_envs = 1.0
cmd.rel_forward_envs = 0.0
cmd.rel_turn_in_place_envs = 0.0
self.commands.head_pose.ranges = ((0.0, 0.0),) * 4
self.commands.body_pose.ranges = ((0.0, 0.0),) * 6
self.events.push_robot = None
def configure_simulation(self):
self.decimation = 4
self.episode_length_s = 20.0
self.sim.dt = 0.005
self.sim.use_newton_actuators = True
self.sim.render_interval = self.decimation
self.sim.physics_material = self.scene.terrain.physics_material
self.scene.contact_forces.update_period = self.sim.dt
self.scene.self_collision.update_period = self.sim.dt
self.sim.default_visualizer_cfg = VisualizerCfg(eye=(0.8, 0.8, 0.4), lookat=(0.0, 0.0, 0.1))
def play_mode(self):
super().play_mode()
self.events.push_robot = None
Append the inspection variant. Fixing the robot’s root holds its body in place
for the first head-turning check. BaseEnvCfg leaves the body free to move for
the zero and random agents.
Append to env_cfg.py:
@configclass
class InspectEnvCfg(BaseEnvCfg):
"""Hold the base for the first joint actuation exercise, not for learning balance."""
def __post_init__(self):
super().__post_init__()
self.scene.robot.spawn.fix_root_link = True
self.events.encoder_bias = None
self.events.randomize_com = None
self.events.randomize_head_com = None
self.events.randomize_joint_friction = None
self.events.randomize_armature = None
Understand the Time Scales#
Select each row to connect physics, decisions, training batches, and episodes.
The robot gets a new action every four physics steps, or every 20 ms. Before each update, the runner collects 24 transitions in each environment. That’s 0.48 seconds of simulated time. An episode can last up to 20 seconds, or 1,000 control steps, so it can continue across many updates. The time needed to train or run a policy depends on the machine.
If you double the number of parallel environments while keeping these settings, which changes: the simulated interval per rollout, the total transitions in the batch, or the episode time limit? Connect your answer to One PPO Iteration in Isaac Lab.
Register the First Tasks#
Define the PPO runner for the two tasks. It collects 24 actions per environment per rollout and writes training logs under course_microduck_balance.
Append to agents/rsl_rl_ppo_cfg.py:
from isaaclab.utils.configclass import configclass
from isaaclab_rl.rsl_rl import RslRlMLPModelCfg, RslRlOnPolicyRunnerCfg, RslRlPpoAlgorithmCfg
@configclass
class BalancePPORunnerCfg(RslRlOnPolicyRunnerCfg):
"""PPO runner for the MicroDuck velocity-tracking tasks."""
num_steps_per_env = 24
max_iterations = 2000
save_interval = 250
experiment_name = "course_microduck_balance"
obs_groups = {"actor": ["policy"], "critic": ["critic"]}
actor = RslRlMLPModelCfg(
hidden_dims=[512, 256, 128],
activation="elu",
obs_normalization=True,
distribution_cfg=RslRlMLPModelCfg.GaussianDistributionCfg(init_std=1.0, std_type="scalar"),
)
critic = RslRlMLPModelCfg(hidden_dims=[512, 256, 128], activation="elu", obs_normalization=True)
algorithm = RslRlPpoAlgorithmCfg(
value_loss_coef=1.0,
use_clipped_value_loss=True,
clip_param=0.2,
entropy_coef=0.01,
num_learning_epochs=5,
num_mini_batches=4,
learning_rate=0.001,
schedule="adaptive",
gamma=0.99,
lam=0.95,
desired_kl=0.01,
max_grad_norm=1.0,
)
Register the tasks in the Microduck package. register_task connects a task name to your
environment and runner classes. Later lessons will append one registration at
a time to this same file.
Append to microduck/__init__.py:
import gymnasium as gym
def register_task(name, env_cfg, agent_cfg):
gym.register(
id=f"Course-Microduck-{name}-v0",
entry_point="isaaclab.envs:ManagerBasedRLEnv",
disable_env_checker=True,
kwargs={
"default_agent": "rsl_rl",
"env_cfg_entry_point": f"{__name__}.env_cfg:{env_cfg}",
"rsl_rl_cfg_entry_point": f"{__name__}.agents.rsl_rl_ppo_cfg:{agent_cfg}",
},
)
register_task("Inspect", "InspectEnvCfg", "BalancePPORunnerCfg")
register_task("Passive", "BaseEnvCfg", "BalancePPORunnerCfg")
Check Your Progress#
Check that your project can find both registered tasks:
uv run isaaclab list_envs
Look for Course-Microduck-Inspect-v0 and Course-Microduck-Passive-v0 alongside the other registered tasks. Both use RSL-RL. Inspect selects InspectEnvCfg, which fixes the root, and Passive selects BaseEnvCfg, which lets the robot move freely.
For a new timing configuration, halve the physics time step while keeping decimation at 4 and the rollout at 24 control steps. Work out the new control frequency and simulated rollout duration. Explain why those changes alone do not determine the wall-clock time of a policy update.