Theme
Stage 3 · lesson 7 of 7 · 35 min

Scenarios are tests you can watch

You will: Run scenarios that serve as tests and demos at once, against either backend.

Builds on One command, two backends.

A scenario is a named sequence of steps. Each step does something to the robot and then asserts what should be true afterwards — polling until it is, as the clocks lesson showed. Scenarios are written against one robot client and nothing else, so the same scenario runs against the mock, against Gazebo and, with Tier 5, against the servos.

They are tests and demos at once, on purpose. make test-sim runs them and fails the build; make scenario runs them for you to watch. Writing them once for both is what stops the demo drifting away from what is actually verified — the failure mode where the conference demo works and the test suite checks something else.

Six exist: home, move_joint, move_to_position, gripper, safety_limit and pick_and_place. None of them names a joint, a pose's numbers or a gripper width. They ask the robot client, which reads the profile, so they run unchanged on any arm with a profile.

A scenario must pass on both backends. One that passes in Gazebo and fails on the mock means the abstraction has quietly become simulator-specific. That is exactly how safety_limit found out that nothing below the seam enforced joint limits: green in simulation, red on the mock, with identical robot software. Gazebo had only clamped because its physics joint has a hard stop. Tier 5 follows that thread.

And it works the other way too. On the SO-101, move_joint passed on the mock and, in Gazebo, drove the gripper into the bench: its jogs added up, which the mock, with no bench and no gravity, could not show. Each joint now returns before the next one moves.

One honest note about pick_and_place. It moves through named poses and opens and closes the gripper — and its "close the gripper" step has no post-condition, on purpose: with an object in the jaw, the jaw is meant to stop short of closed, and the scenario does not know whether there is one. Its release step does have a check, and that check found a real bug: in Gazebo, closing with the gripper pointing down ran the jaw onto its hard stop, where it stuck, and the old scenario passed on a gripper that would never open again. But it means this arm has never been proven to pick anything up. Tier 6 takes that on. A step with no check asserts nothing.

In the simulation

Run pick_and_place by hand, through its named poses, and record it. The replay is the demo; the poses and the jaw are what the scenario checks. Nothing here checks that anything was carried, and in the scenario nothing does either.

Kinematic: joints move at their real speed limit, but there is no gravity, no load and no physics. That is what the steps below are for.

The SO-101 loads as you reach it.

In this lesson

  1. Press Record, then pick.
  2. Press place, and open the jaw with [ at least two quarters. The release is the step with a check.
  3. Press h (or home), then press Record again to stop.
  4. Press Replay and watch the same setpoints again.

Do it

  1. List the scenarios.

    make shell
    ros2 run threevn_control run_scenario --list
    
  2. Start the SO-101 on mock hardware, then run every scenario against it from another terminal.

    make mock
    make scenario NAME=all
    

    Expect: A report per scenario, each step with a time, each ending PASS, then 6/6 scenarios passed.

  3. Stop it, start the SO-101 in Gazebo, and run the same set.

    make stop
    make sim
    make scenario NAME=all
    

    Expect: 6/6 scenarios passed again, more slowly.

  4. Read the gripper scenario. Notice that it names no joint and no width: it asks the robot client for the jaw's travel, which comes from the profile.

    grep -n -A50 "class Gripper" src/threevn_control/threevn_control/scenarios/arm.py
    
You will know it worked when: Every scenario passes against the mock and against Gazebo, with no change in between.

When it goes wrong

A step fails with "post-condition not met within 15s".

Why: Either the step is genuinely wrong, or the simulator is running so slowly that the motion has not finished.

Fix: Check the real-time factor first. If it is reasonable, the step is telling you the truth.

Terms

Scenario
A named sequence of action-then-assert steps, written against the robot client alone, so it runs on any backend.
Post-condition
What must be true after a step. A step without one is recorded but proves nothing.

Every term in the course: glossary.

Check yourself

Answer in your head first, then open it.

A scenario passes in Gazebo and fails on the mock. What does that tell you?

The scenario — or the code under it — is relying on something the simulator provides and the abstraction does not promise. Here, it was Gazebo's physical joint stops standing in for limit enforcement.

What is wrong with a step that has no post-condition?

It records that an action was attempted, not that it worked. A suite of such steps can pass while the robot does nothing useful.

Stretch

Find the step in pick_and_place with no post-condition. Write down the check it would need to become a real test — and what that check would need to know that the robot cannot measure about itself.

Hint

Closing the gripper on nothing and closing it on an object leave the finger in different places. But "is the object coming with us" is a different question from "did the fingers stop early".

Going deeper