Stage 12 · Lesson 01/16

Robot Simulation & Digital Twin · Lesson 01

Why Robots Need Simulation

Est. 45–60 min

Why

Why this lesson matters

Pilots do the same thing. Before a new pilot ever flies a real Airbus, she spends many hours in a flight simulator — a cockpit on the ground where engine failures, storms and bad landings can be practised again and again without risking a single life. Robot engineers rehearse in the same way. A robot simulator is a computer model of the robot and its world where you can try code, break things and learn — and only then move the real metal.

Stages 7–11 gave our arm kinematics, trajectories, ROS 2 and vision. Stage 12 gives it a rehearsal stage and, later, a digital twin — a live model that mirrors the real arm. In this first lesson you will tune a joint in a Python simulation, discover that a “perfect” simulated gain crashes on a messier arm, fix that by testing many versions, and build a DRY RUN / LIVE switch on the Arduino so “simulate first” becomes a habit of your hands, not just your head.

Concept

What a simulator really is

1. A simulator is a model plus a clock

Every simulator — from a 40-line Python file to Gazebo or NVIDIA Isaac Sim — does the same thing in a loop: take the current state (angles, speeds, positions), work out the forces and commands, move time forward by a small step dt, and compute the new state. A flight simulator solves the aircraft’s equations of motion 50 or 60 times every second. Our toy joint in the code lab takes 1 ms steps.

  1. State

    What is true now: joint angle θ, speed ω, where the block is.

  2. Inputs

    What your controller code commands: torque, target angle, gripper open/close.

  3. Physics

    Rules that turn inputs into change: inertia, friction, gravity, contacts, motor limits.

  4. Step

    Move time forward by dt and compute the new state. Repeat thousands of times.

2. Why rehearse? Five big wins

A robotics simulator lets you build and debug a robot application without depending on the physical machine, saving cost and time.
WinWhat it means on our benchReal-world version
SafetyA wild gain hits a virtual shelf, not your handPilots practise engine failures; cars are crash-tested with dummies
CostNo stripped gears, burnt drivers or bent bracketsFactories program robot cells off-line, so the line keeps running
Speed24 s of arm motion simulated in a fraction of a secondSimulators can run headless and faster than real time
RepeatabilityExactly the same start every time — fair comparisonRegression tests run the same scene after every code change
Edge casesTry “sensor 30 ms late” or “weak motor” on purposeTest rare failures that are dangerous to create for real

3. The catch: the reality gap

A simulator only knows what you told it. If your model has no friction, no sensor delay and an endlessly strong motor, it will happily tell you a gain is “perfect” that crashes on the real arm. This difference between the model and the real robot is called the reality gap (or sim-to-real gap). Sensor-based behaviour is especially hard to simulate, because real readings depend on light, noise and timing.

4. The simulator family you will meet

Gazebo uses physics engines such as ODE, Bullet, Simbody and DART; Webots uses its own fork of ODE.
SimulatorKnown forNotes
Gazebo (Gazebo Sim)Open-source robot simulator from Open Robotics, tight ROS 2 linksWorlds and robots described in SDF; also loads URDF; can run headless with gz sim -s
WebotsOpen-source simulator by Cyberbotics, many ready robot modelsControllers in C, C++, Python, Java, MATLAB or ROS
NVIDIA Isaac SimPhoto-realistic scenes and GPU physics for AI and visionNeeds a strong NVIDIA GPU
MuJoCo, PyBulletFast physics engines popular in research and learningOften used for many quick trials
Our browser sims + PythonLearning the ideas in this stageEducational approximations — not a replacement for the tools above
Screenshot of the Webots robot simulator: a 3D view of a small wheeled robot in an arena, with a side window showing the robot’s sensor values
The Webots simulator: a 3D world, a robot inside it, and a robot window showing what its sensors report. Every number is computed by the model step by step.Photo: Cyberbotics Ltd. · CC BY-SA 3.0 · Source: Wikimedia Commons · resized, converted to WebP

Visual

Visualise it: the value of rehearsal

Educational why-simulate explorer: rehearsal value, the cost of skipping simulation and the sim-to-real gap. (A browser sim, not Gazebo / Isaac / MuJoCo.)

Interactive · Robot simulation explorer · Educational

Why robots need simulation overviewDigital twin concept diagram

Practice motions, debug logic, and catch bad joint limits before you bend a real servo horn.

Educational value score

57

Toy metric — teaches tradeoffs, not a real KPI.

PlanSimReal

Browser educational sim — not Gazebo / not Isaac Sim / not MuJoCo / not a real-time physics engine.

Code lab

Code lab: crash it in simulation first

rehearsal_sim.py needs only plain Python 3 (no libraries). It models one shoulder joint: a link with inertia, a motor driven by a PD controller (torque = kp × error − kd × speed), and a shelf at 100°. The task is to swing from 0° to 90°. Touching 100° is a crash. Run python3 rehearsal_sim.py.

rehearsal_sim.py · Python
"""rehearsal_sim.py - Stage 12 Lesson 1: why robots rehearse in simulation.

A toy shoulder joint (one link, one motor) must swing from 0 deg to 90 deg.
A shelf sits at 100 deg: if the link overshoots past it, that is a CRASH.

Part A  tune the controller gain in simulation (many trials, no broken parts)
Part B  run the "best" gain on a messier 'real' arm (friction + delay + weak motor)
Part C  test every gain on several messy versions and pick a SAFE gain
Only Python's standard library is needed:  python3 rehearsal_sim.py
"""
import time

DT = 0.001          # simulation step: 1 ms
T_END = 3.0         # simulate 3 s for each trial
TARGET = 90.0       # deg
SHELF = 100.0       # deg - touching this is a crash
TOL = 3.0           # deg - "arrived" means within 3 deg of the target
INERTIA = 0.02      # kg m^2 (toy value for a small link)


def run_trial(kp, kd=0.25, friction=0.0, delay_s=0.0, max_torque=10.0, damping=0.002):
    """Simulate one move. Returns (crashed, peak_deg, settle_s or None)."""
    theta, omega = 0.0, 0.0                    # deg, deg/s
    delay_steps = int(round(delay_s / DT))
    history = [0.0] * (delay_steps + 1)          # what the controller 'sees' (late)
    peak, settle_t, inside_since = 0.0, None, None
    steps = int(T_END / DT)
    for i in range(steps):
        seen = history[0]                        # delayed measurement
        error = TARGET - seen
        torque = kp * error / 57.2958 - kd * omega / 57.2958   # N m (deg -> rad)
        torque = max(-max_torque, min(max_torque, torque))     # motor limit
        # Coulomb friction opposes motion (or holds the link still if torque is small)
        if abs(omega) < 1e-6 and abs(torque) <= friction:
            alpha = 0.0
        else:
            direction = 1.0 if omega > 0 else -1.0 if omega < 0 else (1.0 if torque > 0 else -1.0)
            alpha = (torque - friction * direction - damping * omega / 57.2958) / INERTIA
        omega += alpha * 57.2958 * DT          # rad/s^2 -> deg/s
        theta += omega * DT
        history.append(theta)
        history.pop(0)
        peak = max(peak, theta)
        if theta >= SHELF:
            return True, theta, None
        t = (i + 1) * DT
        if abs(theta - TARGET) <= TOL:
            if inside_since is None:
                inside_since = t
        else:
            inside_since = None
    settle_t = inside_since
    return False, peak, settle_t


def fmt(result):
    crashed, peak, settle = result
    if crashed:
        return "CRASH into shelf"
    s = f"{settle:.2f} s" if settle is not None else "not within 3 deg after 3 s"
    return f"peak {peak:6.1f} deg, settles {s}"


GAINS = [0.25, 0.5, 1, 1.5, 2, 3, 4, 6]

print("PART A - tune in simulation (clean model: no friction, no delay)")
start = time.perf_counter()
clean = {}
for kp in GAINS:
    clean[kp] = run_trial(kp)
    print(f"  kp = {kp:4}  ->  {fmt(clean[kp])}")
elapsed = time.perf_counter() - start
sim_time = len(GAINS) * T_END
print(f"  simulated {sim_time:.0f} s of arm motion; computer time well under real time: {elapsed < sim_time}")
ok = [k for k in GAINS if not clean[k][0] and clean[k][2] is not None]
best = min(ok, key=lambda k: clean[k][2])
print(f"  fastest gain that does not crash: kp = {best}  ({fmt(clean[best])})")
print(f"  crashes found without breaking anything: {sum(1 for k in GAINS if clean[k][0])}")

print()
print("PART B - same gain on a messier 'real' arm (reality gap)")
messy = dict(friction=0.05, delay_s=0.03, max_torque=0.6)
print(f"  'real' arm adds: friction {messy['friction']} N m, sensor delay {messy['delay_s']*1000:.0f} ms, motor limit {messy['max_torque']} N m")
print(f"  kp = {best} on clean sim : {fmt(clean[best])}")
print(f"  kp = {best} on 'real' arm: {fmt(run_trial(best, **messy))}")

print()
print("PART C - test every gain on 4 messy versions, keep only gains that pass ALL")
VERSIONS = [
    dict(friction=0.00, delay_s=0.00, max_torque=10.0),
    dict(friction=0.05, delay_s=0.03, max_torque=0.6),
    dict(friction=0.10, delay_s=0.02, max_torque=0.8),
    dict(friction=0.03, delay_s=0.05, max_torque=1.0),
]
safe = []
for kd in (0.25, 0.5):
    print(f"  damping kd = {kd}")
    for kp in GAINS:
        results = [run_trial(kp, kd=kd, **v) for v in VERSIONS]
        good = [(not r[0]) and r[2] is not None and r[2] <= 2.5 for r in results]
        worst_peak = max(r[1] for r in results)
        marks = " ".join("ok" if g else ("CRASH" if r[0] else "slow") for g, r in zip(good, results))
        print(f"    kp = {kp:4}  ->  {marks:24s} worst peak {worst_peak:6.1f} deg  {'PASS' if all(good) else 'fail'}")
        if all(good):
            safe.append((worst_peak, kp, kd))
if safe:
    print(f"  (kp, kd) pairs that pass every version: {[(kp, kd) for _, kp, kd in safe]}")
    peak, kp, kd = min(safe)                     # biggest gap to the shelf wins
    print(f"  choose kp = {kp}, kd = {kd}: worst peak {peak:.1f} deg = {SHELF - peak:.1f} deg away from the shelf")
    print("  then still try it slowly on the real arm, with a hand on the servo power switch")
else:
    print("  no gain passes every version -> change the design before touching hardware")

Output (run with python3 rehearsal_sim.py)

PART A - tune in simulation (clean model: no friction, no delay)
  kp = 0.25  ->  peak   86.2 deg, settles not within 3 deg after 3 s
  kp =  0.5  ->  peak   89.9 deg, settles 1.49 s
  kp =    1  ->  peak   90.2 deg, settles 0.60 s
  kp =  1.5  ->  peak   93.1 deg, settles 0.57 s
  kp =    2  ->  peak   96.9 deg, settles 0.56 s
  kp =    3  ->  CRASH into shelf
  kp =    4  ->  CRASH into shelf
  kp =    6  ->  CRASH into shelf
  simulated 24 s of arm motion; computer time well under real time: True
  fastest gain that does not crash: kp = 2  (peak   96.9 deg, settles 0.56 s)
  crashes found without breaking anything: 3

PART B - same gain on a messier 'real' arm (reality gap)
  'real' arm adds: friction 0.05 N m, sensor delay 30 ms, motor limit 0.6 N m
  kp = 2 on clean sim : peak   96.9 deg, settles 0.56 s
  kp = 2 on 'real' arm: CRASH into shelf

PART C - test every gain on 4 messy versions, keep only gains that pass ALL
  damping kd = 0.25
    kp = 0.25  ->  slow slow slow slow      worst peak   86.2 deg  fail
    kp =  0.5  ->  ok slow slow slow        worst peak   89.9 deg  fail
    kp =    1  ->  ok ok slow ok            worst peak   92.5 deg  fail
    kp =  1.5  ->  ok ok ok CRASH           worst peak  100.1 deg  fail
    kp =    2  ->  ok CRASH ok CRASH        worst peak  100.1 deg  fail
    kp =    3  ->  CRASH CRASH CRASH CRASH  worst peak  100.3 deg  fail
    kp =    4  ->  CRASH CRASH CRASH CRASH  worst peak  100.3 deg  fail
    kp =    6  ->  CRASH CRASH CRASH CRASH  worst peak  100.4 deg  fail
  damping kd = 0.5
    kp = 0.25  ->  slow slow slow slow      worst peak   70.0 deg  fail
    kp =  0.5  ->  slow slow slow slow      worst peak   85.8 deg  fail
    kp =    1  ->  ok slow slow ok          worst peak   89.9 deg  fail
    kp =  1.5  ->  ok ok slow ok            worst peak   90.0 deg  fail
    kp =    2  ->  ok ok ok ok              worst peak   90.0 deg  PASS
    kp =    3  ->  ok ok ok ok              worst peak   94.2 deg  PASS
    kp =    4  ->  ok ok ok CRASH           worst peak  100.1 deg  fail
    kp =    6  ->  ok CRASH CRASH CRASH     worst peak  100.2 deg  fail
  (kp, kd) pairs that pass every version: [(2, 0.5), (3, 0.5)]
  choose kp = 2, kd = 0.5: worst peak 90.0 deg = 10.0 deg away from the shelf
  then still try it slowly on the real arm, with a hand on the servo power switch

Try it: switch between “Why simulate”, “Cost of skipping” and “Sim ≠ real”, and move the risk and iteration sliders. (An educational browser sim, not Gazebo or Isaac.)

Interactive · Robot simulation explorer · Educational

Why robots need simulation overviewDigital twin concept diagram

Practice motions, debug logic, and catch bad joint limits before you bend a real servo horn.

Educational value score

57

Toy metric — teaches tradeoffs, not a real KPI.

PlanSimReal

Browser educational sim — not Gazebo / not Isaac Sim / not MuJoCo / not a real-time physics engine.

Bench build: a DRY RUN / LIVE switch

The simplest simulation of all is a dry run: the robot computes its whole plan and prints it, but the motor stays switched off. CNC machines and 3D printers have the same idea. dry_run_first.ino reads a toggle switch. In DRY RUN (the default) the servo is detached and every planned angle is printed. In LIVE the same plan moves the servo. Targets outside 10–170° are refused in both modes, and flipping the switch mid-move stops the move.

Never power a servo from a GPIO pin or the Arduino 5 V pin: a stalled servo can pull far more current than the board can give, and the Arduino resets or gets damaged.
PartConnectionNote
Toggle switchD2 → switch → GNDINPUT_PULLUP: open = DRY RUN, closed = LIVE
On-board LEDD13 (built in)ON = LIVE, so you can see the mode from across the bench
SG90 / MG90S servo signalD9orange/yellow wire
Servo powerseparate 5–6 V supply (4×AA or a 5 V 2 A adapter)red to supply +, brown to supply −
Common groundsupply − to Arduino GNDneeded so the signal has a reference
dry_run_first.ino · Arduino C++
// dry_run_first.ino - Stage 12 Lesson 1: "simulate first" habit on a real bench
// A toggle switch picks DRY RUN (default, safe) or LIVE.
//   DRY RUN: the sketch plans the move and PRINTS every servo angle - the servo is detached.
//   LIVE   : the same plan is sent to the servo.
// Serial Monitor at 115200 baud, send:  M 120   (move to 120 deg)
// Wiring:
//   D2  -> toggle switch -> GND  (INPUT_PULLUP: open = DRY RUN, closed = LIVE)
//   D13 -> on-board LED (ON = LIVE)
//   D9  -> servo signal. Servo red/brown on a SEPARATE 5-6 V supply, grounds joined.
//          Never power a servo from a GPIO pin or the Arduino 5 V pin.
#include <Servo.h>

const int SWITCH_PIN = 2;
const int LED_PIN = 13;
const int SERVO_PIN = 9;
const int MIN_DEG = 10;     // soft limits: stay away from the end stops
const int MAX_DEG = 170;
const int STEP_DEG = 2;     // move in small steps ...
const int STEP_MS = 20;     // ... every 20 ms = 100 deg/s max

Servo joint;
int currentDeg = 90;
bool wasLive = false;

bool liveMode() { return digitalRead(SWITCH_PIN) == LOW; }

void setup() {
  pinMode(SWITCH_PIN, INPUT_PULLUP);
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(115200);
  Serial.println(F("dry_run_first ready. Send: M <deg>"));
  Serial.println(liveMode() ? F("Mode: LIVE") : F("Mode: DRY RUN"));
}

void runMove(int target) {
  bool live = liveMode();
  if (target < MIN_DEG || target > MAX_DEG) {
    Serial.print(F("REFUSED: ")); Serial.print(target);
    Serial.print(F(" is outside ")); Serial.print(MIN_DEG);
    Serial.print('-'); Serial.println(MAX_DEG);
    return;
  }
  int steps = abs(target - currentDeg) / STEP_DEG;
  Serial.print(live ? F("LIVE move ") : F("DRY RUN move "));
  Serial.print(currentDeg); Serial.print(F(" -> ")); Serial.print(target);
  Serial.print(F(" in ")); Serial.print((long)steps * STEP_MS); Serial.println(F(" ms"));
  int dir = (target > currentDeg) ? 1 : -1;
  while (currentDeg != target) {
    if (liveMode() != live) {              // switch flipped mid-move: stop where we are
      Serial.println(F("MODE CHANGED - move stopped"));
      return;
    }
    int next = currentDeg + dir * STEP_DEG;
    if ((dir > 0 && next > target) || (dir < 0 && next < target)) next = target;
    currentDeg = next;
    if (live) {
      joint.write(currentDeg);
    } else {
      Serial.print(F("  plan ")); Serial.println(currentDeg);
    }
    delay(STEP_MS);
  }
  Serial.println(F("done"));
}

void loop() {
  bool live = liveMode();
  if (live != wasLive) {                   // attach only in LIVE mode
    if (live) { joint.attach(SERVO_PIN); joint.write(currentDeg); }
    else { joint.detach(); }
    digitalWrite(LED_PIN, live ? HIGH : LOW);
    Serial.println(live ? F("Mode: LIVE") : F("Mode: DRY RUN"));
    wasLive = live;
  }
  if (Serial.available()) {
    char c = Serial.read();
    if (c == 'M' || c == 'm') {
      int target = Serial.parseInt();
      runMove(target);
    }
  }
}
Serial Monitor (115200 baud) — what a dry run looks like · Text
Mode: DRY RUN
M 100
DRY RUN move 90 -> 100 in 100 ms
  plan 92
  plan 94
  plan 96
  plan 98
  plan 100
done
M 200
REFUSED: 200 is outside 10-170

Debugging

SymptomLikely causeFix
Python: every gain crasheskd too small for the inertiaRaise kd (more damping) and run again
Python: every gain is “slow”friction too high for a pure P/PD controllerRaise kp carefully, or loosen TOL; later lessons add integral action
Sketch always says DRY RUNswitch wired to 5 V instead of GND, or wrong pinWire D2 → switch → GND; the pin reads LOW when closed
Servo jitters or Arduino resets in LIVEservo powered from the Arduino 5 V pinUse a separate 5–6 V supply and join the grounds
Servo does not move but LIVE LED is onno common groundConnect supply − to Arduino GND
M 120 does nothingSerial Monitor line ending or baud mismatchSet 115200 baud; type M 120 and press Send

Real world

Simulation in the real world

  • Pilot training: flight simulators re-create the aircraft’s behaviour and its environment so pilots can practise procedures and emergencies on the ground. Some simulator hours can even be credited towards a pilot licence.
  • Robot challenges in simulation: in NASA’s Space Robotics Challenge, teams programmed the Valkyrie humanoid robot inside the Gazebo simulator to solve tasks on a virtual Mars base — no real robot was put at risk.
  • Factories: robot cells are programmed and checked off-line in simulation, so the real assembly line does not stop while engineers try ideas.
  • Crash testing: car makers use crash test dummies so that a dangerous test teaches engineers without hurting a person. Simulation does the same for robots, even more cheaply.
An Airbus A350 full flight simulator: a large white cabin on hydraulic legs inside a training building
An Airbus A350-900 full flight simulator at Hong Kong. The cabin on legs moves to give real motion cues while pilots practise on the ground.Photo: Ilari Kousa · CC BY-SA 4.0 · Source: Wikimedia Commons · resized, converted to WebP
Screenshot from the Gazebo simulator showing NASA’s Valkyrie humanoid robot inside a virtual Mars habitat during a challenge task
NASA’s Valkyrie humanoid solving Task 2 of the Space Robotics Challenge — entirely inside the Gazebo simulator.Photo: Chapulinaaa · CC BY-SA 4.0 · Source: Wikimedia Commons · resized, converted to WebP
Several crash test dummies of different sizes standing in a row at a testing laboratory
Crash test dummies at a US government lab. They take the hits so people do not — the same idea as crashing a simulated arm before a real one.Photo: National Institute of Standards and Technology · Public domain · Source: Wikimedia Commons · resized, converted to WebP

Think

Think about it

Think

Your gain passes all four versions of the model in Part C. Your friend says: “Then we can skip the slow first test on the real arm.” Is your friend right?

Experiment

Try it in the lab

About 45 minutes. The Python part needs only Python 3. The bench part needs an Arduino UNO, one SG90/MG90S servo, a toggle switch and a separate 5–6 V servo supply.

Experiment

Tune, crash, close the gap

You will need

  • `rehearsal_sim.py` (Python 3, no libraries)
  • Robot simulation explorer (in your browser)
  • Optional bench: Arduino UNO, SG90 servo, toggle switch, 4×AA holder or 5 V 2 A adapter, jumper wires

Steps

  1. Run `rehearsal_sim.py`. Note which gains crash in Part A.
  2. Move the shelf: set `SHELF = 95`. Which gains crash now? Which pairs survive Part C?
  3. Make the sensor slower: change the 30 ms delay in Part B to 60 ms. Does `kp = 1.5` still survive?
  4. Add a fifth version to `VERSIONS` with `friction=0.15`. Do any pairs still pass? What would you change?
  5. In the browser explorer, find the setting where skipping simulation “costs” the most.
  6. Bench: upload `dry_run_first.ino`. Send `M 120` in DRY RUN and read the plan. Then flip to LIVE and send it again.

Interactive · Robot simulation explorer · Educational

Why robots need simulation overviewDigital twin concept diagram

Practice motions, debug logic, and catch bad joint limits before you bend a real servo horn.

Educational value score

57

Toy metric — teaches tradeoffs, not a real KPI.

PlanSimReal

Browser educational sim — not Gazebo / not Isaac Sim / not MuJoCo / not a real-time physics engine.

A clean model finds the obvious crashes for free. A model with friction and delay finds the sneaky ones. Testing many versions picks a gain with margin. And a dry run on the real bench is the last, cheapest rehearsal before the motor moves.

Knowledge check

Check your understanding

Knowledge check

1. A primary reason to simulate before using hardware is…

2. Every simulator repeats which loop?

3. In the code lab, kp = 2 passed the clean model but crashed on the messier arm. This is an example of…

4. Which change made gains pass every version in Part C?

5. Simulation often under-represents…

6. In `dry_run_first.ino`, what does DRY RUN mode do?

7. Where should the servo take its power from?

Mini assignment

Hands-on assignment

Mini assignment

Your “simulate first” card

Show, with numbers, why a gain must be tested on more than one model before the real arm, and plan your own first safe real test.

Deliverables

  • A five-line “why simulate” card: two wins you saw in the code lab, two reality-gap causes, and one thing simulation cannot tell you.
  • Output of `rehearsal_sim.py` after you change the shelf to 95° and add one version of your own to `VERSIONS`, with the pair you would choose and why.
  • A first-real-test checklist (at least six lines) for the desk arm: DRY RUN, soft limits, separate servo supply, slow speed, hand on power switch, what you will measure.
  • Optional (bench): a screenshot of the DRY RUN plan for `M 150` and a short video of the same move in LIVE.

Do this, step by step

  1. Run rehearsal_sim.py once as shipped and note which gains crash on which version.
  2. Change the shelf to 95° and add one version of your own to VERSIONS (for example more friction or a longer delay).
  3. Run again and pick the gain pair that passes every version; write one line on why.
  4. Write your five-line “why simulate” card and your six-line first-real-test checklist.
  5. Bench (optional): upload dry_run_first.ino, send M 150 in DRY RUN, read the plan, then try LIVE slowly with your hand on the power switch.

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. If every gain now crashes, your new version may be too harsh. Change one thing at a time (only friction, or only delay).
  2. More damping (kd) usually helps a late sensor more than a bigger kp does.
  3. In DRY RUN the servo stays detached. If it moves, check the mode before sending any LIVE command.

Challenges (pick by level)

  • 🟢 Beginner: Change GAINS to include 2.5 and 3.5. Where exactly does the clean model start crashing?
  • 🟡 Intermediate: Make run_trial also return the time of the peak, and print it. Does the messy arm peak later than the clean one? Why?
  • 🟠 Advanced: Add integral action (ki × sum of error × dt) and find a (kp, ki, kd) that removes the “slow” results without any crash.
  • 🔴 Expert: Replace the four fixed VERSIONS with 200 random ones (friction 0–0.12, delay 0–60 ms, motor 0.5–1.5 N·m). Report the pass rate of each pair. This is the idea behind domain randomisation.
  • ⚫ Research: Read the Gazebo “Getting Started” page and write half a page on what gz sim -s shapes.sdf does and why running headless matters for automatic testing.

Next step

You know why robots rehearse. In Lesson 2 — What Is a Digital Twin? the model stops being a one-time rehearsal and becomes a live mirror of the real arm: model + measured state + sync, and how honest a twin must be about what it does not know.

Look back: Stage 11 L16: Capstone — Vision-Guided Pick. Next: Lesson 2: What Is a Digital Twin?. Related: Stage 9 — Trajectory Planning.

Sources

  • Wikipedia — Robotics simulator — definition (develop for a robot without the physical machine, saving cost and time), off-line programming, sensor-based actions harder to simulate, Gazebo (ODE/Bullet/Simbody/DART; SDF/URDF) and Webots (fork of ODE; C/C++/Python/Java/MATLAB/ROS) comparison.
  • Gazebo docs — Getting Started with Gazebo — gz sim shapes.sdf, headless server-only mode with -s, SDF worlds, Gazebo Harmonic recommended with ROS 2 Jazzy on Ubuntu 24.04.
  • Wikipedia — Flight simulator — re-creates aircraft flight for training and design; equations of motion solved 50 or 60 times per second; engineering simulators find errors faster and reduce risk and cost.
  • Arduino Servo library — attach, write, detach; servos draw considerable power, so use a separate supply and connect the grounds.
  • Photos: Wikimedia Commons (credits under each image). Valkyrie screenshot described on Commons as Task 2 of NASA’s Space Robotics Challenge on the Gazebo simulator.

Self-attested for now — keep artifacts in your lab notebook.

Complete

Today's goal

0 of 1 done today

0-day streak
Daily goal:lessons, quizzes or assignments a day

Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).

Stuck somewhere?

Ask a doubt about this lesson

Saved with this lesson's id and your email so we can reply. Privacy · or email contact@aihubstation.in