# Module 6.2: Physics Simulation for Robot Learning

- Course: [Course 6: Modern Robot Learning & Embodied AI](https://roboticsconcepts.dev/courses/modern-robot-learning-embodied-ai.md)
- HTML Page: https://roboticsconcepts.dev/courses/modern-robot-learning-embodied-ai/physics-simulation-for-robot-learning/
- Key Concepts: Vectorized parallel rollouts, Observation space design, Action space selection (joint vs. EEF deltas)

Training a robot policy directly on physical hardware is slow and nerve-wracking — a single bad exploration step can snap a 3D-printed finger or trip a breaker. Fast physics simulators let us trade wall-clock waiting for parallel compute, running thousands of robots at once before touching a single real screw.

## Vectorized contact simulation on GPUs

If you've ever watched one robot fail a grasp fifty times in a row, you know how painful single-threaded data collection feels. Modern simulators like MuJoCo MJX and Isaac Lab solve this by vectorizing physics: instead of stepping one robot on one CPU core, they pack 4,096 copies of the environment into GPU arrays and step all of them in lockstep.

At 50,000+ simulated frames per second, an afternoon of real-world practice turns into years of robotic trial and error before your coffee gets cold. The catch is that simulation only helps if you design clean observations and pick the right action space.

## Designing observations and picking an action space

A clean observation vector gives the policy everything it needs to act without tempting it to memorize irrelevant quirks. For manipulation or locomotion, that usually means joint positions, joint velocities, the previous action (so the policy knows what it just asked for), and goal offsets expressed in a local frame.

Choosing the action space is just as important, and it ties directly back to Course 1 coordinate frames and Course 4 PD controllers. You're usually picking between three options:

- Joint Space deltas: output Δq for each hinge, fed to a joint PD controller. Fast and simple, but tied to one robot geometry and sensitive to workspace shifts.
- Base-Frame EEF deltas: output [Δx, Δy, Δz] in the robot's base frame and let IK convert to joint angles. Cleaner paths, though world-anchored shifts still require re-aiming.
- Wrist-Frame deltas: express motion relative to the gripper or wrist camera ('move 2 cm toward what I see ahead'). Shifts in table position barely faze it because local geometry stays invariant.

## Interactive Sandbox: Action Space Comparison Arena

Switch between Joint Space, Base Frame EEF Δ, and Wrist Frame Δ in the Action Space Arena below. Slide Table shift (m) away from zero and toggle between 10 Hz and 50 Hz to watch how coordinate frames and control rate shape both error and smoothness.

## Why frequency and frames show up together

Notice in the arena what happens when you drop Policy frequency from 50 Hz down to 10 Hz. Each policy command gets held constant for 100 milliseconds while the underlying PD loop keeps stepping, producing visible corner-cutting and choppy accelerations. Running the exact same policy at 50 Hz smooths out those kinks immediately.

At the same time, look at the Table shift slider: Joint Space blindly replays old joint targets and misses the shifted mug by nearly the full table offset, whereas Wrist Frame Δ stays locked onto the local target relative to the gripper. Picking the right frame gives you generalization for free before you even collect extra training data.

## Action space as a low-level PD target

```text
q_target = q + Δq   (Joint)   |   q_target = IK(T_base←eef · ΔT_wrist)   (Wrist Δ)
```

Even when policies act in Cartesian or wrist coordinates, a Course 4 joint PD controller (τ = Kp(q_target − q) − Kd q̇) ultimately drives the motors.

## Check Your Intuition

**Question:** You train a tabletop wiping policy using only a wrist-mounted camera, and then someone rolls the table 25 cm to the left. Which action representation breaks the least without retraining?

- [ ] Absolute joint angles recorded from the original table position
- [✓] Wrist-frame end-effector deltas relative to the gripper
- [ ] Open-loop motor torque pulses in world coordinates

**Explanation:** Wrist-frame deltas describe motion relative to the gripper and wrist camera themselves, so translating the table leaves the local sensor-to-action relationship intact.

## Where You'll See This in Modern Robotics

In production VLA and teleoperation stacks, policies almost never output raw torques; they output either delta joint positions or delta end-effector poses at 20–50 Hz into a damped IK/PD controller.

## Companion Python Notebook: 02 · Vectorized Rollouts & Action Space Selection

Step hundreds of parallel reaching environments in NumPy and compare Joint Space, Base EEF Delta, and Wrist-Frame action spaces.

- Open in molab (WASM): https://molab.marimo.io/github/alchemicduncan/robotics-concepts-dev/blob/main/notebooks/course-6/02_physics_sim_action_spaces.py/wasm
- Open in Google Colab: https://colab.research.google.com/github/alchemicduncan/robotics-concepts-dev/blob/main/notebooks/colab/course-6/02_physics_sim_action_spaces.ipynb
- Download .py: https://roboticsconcepts.dev/downloads/notebooks/course-6/02_physics_sim_action_spaces.py
- Download .ipynb: https://roboticsconcepts.dev/downloads/notebooks/colab/course-6/02_physics_sim_action_spaces.ipynb
- Run locally: `uvx marimo edit --sandbox notebooks/course-6/02_physics_sim_action_spaces.py`
