Theme
Stage 3 · lesson 6 of 7 · 35 min

One command, two backends

You will: Send an identical goal to a physics simulation and to a mock, unchanged, and get the same answer.

Builds on The decision everything else rests on and Topics, services and actions.

This is the lesson the course is arranged around, and it takes two launches to demonstrate.

The same action goal, the same controllers, the same command line. One run talks to a physics simulation; the other talks to a mock that simply reports back whatever it was told. Neither the client nor the controllers know which.

Be precise about what each one proves. Success on the mock proves the interface contract — the action exists, the joint names are right, the controllers accept and complete the goal — with no physics at all, in seconds. Success in Gazebo adds gravity, inertia, contact and controller tuning. Neither proves the real arm works. But when the servos arrive they are a third implementation behind the same interface, and this exact command is the first thing you run against them. Tier 5 runs it against a simulated servo bus first.

The SO-101 is itself the strongest test of the claim. Nobody here designed it: it is somebody else's arm, with five joints, a revolute jaw and nothing of this project in its description. It was spawned under these controllers and driven unchanged. Joint discovery, state, limits, trajectories and the gripper all worked. One hardcoded constant, the named poses, had to move into the robot's profile.

Two habits come out of that, and both are in the steps. Ask, do not assume: code that needs the arm's joints asks the controller which joints it drives, rather than carrying a list that is right for one robot. And read joints by name, never by position: /joint_states lists them in its own order, which is not the controller's.

In the simulation

Send this lesson's goal, [0.4, -0.3, 0.5, 0.2, 0.0], by hand. Like the mock, this page reports back what it was told, with no physics. Its inspector lists joints in the controller's order; the real /joint_states uses its own, which is why code reads them by name.

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. Open Inspect, then /joint_states, and set shoulder_pan to 0.4 rad (about 23°) with its slider.
  2. Set shoulder_lift to -0.3 rad (about -17°).
  3. Set elbow_flex to 0.5 rad (about 29°).
  4. Set wrist_flex to 0.2 rad (about 11°), and read the five positions in the inspector by name.

Do it

  1. Start the arm on the mock backend.

    make mock
    
  2. In a second terminal, send a trajectory goal.

    make shell
    ros2 action send_goal /arm_controller/follow_joint_trajectory \
      control_msgs/action/FollowJointTrajectory \
      "{trajectory: {joint_names: [shoulder_pan, shoulder_lift, elbow_flex, wrist_flex, wrist_roll], points: [{positions: [0.4, -0.3, 0.5, 0.2, 0.0], time_from_start: {sec: 2}}]}}"
    

    Expect: Goal finished with status: SUCCEEDED.

  3. Read where the joints ended up.

    ros2 topic echo /joint_states --once --field position
    

    Expect: 0.5, 0.0, -0.3, 0.4, 0.2, 0.0. The numbers you sent, in a different order: /joint_states is ordered elbow_flex, gripper, shoulder_lift, shoulder_pan, wrist_flex, wrist_roll, and the mock reports each command straight back.

  4. Stop the mock and start Gazebo with the same arm. Exit the shell first.

    make stop
    make sim
    
  5. Send exactly the same goal again, from a new make shell, and read the positions.

    Expect: SUCCEEDED again — same bytes, different physics. The positions match to about nine decimal places: 0.49999999…, with gravity and a controller in between.

  6. Ask the controller which joints it drives. This is how code should find out, rather than assuming.

    ros2 param get /arm_controller joints
    

    Expect: ['shoulder_pan', 'shoulder_lift', 'elbow_flex', 'wrist_flex', 'wrist_roll'], in the order the controller wants them.

You will know it worked when: Both backends report SUCCEEDED for byte-identical goals.

When it goes wrong

The goal is rejected immediately.

Why: The joint names do not match the controller's: a typo, or a goal written for a different robot.

Fix: ros2 param get /arm_controller joints and use those names. In code, ask the controller rather than hardcoding a list.

You read /joint_states by index and got the wrong joint.

Why: /joint_states lists joints in its own order, which is not the controller's or the URDF's.

Fix: Match on name, always. The robot client builds a name-to-position map for exactly this reason.

make sim fails with a pluginlib error saying mock_components/GenericSystem is not a Gazebo plugin.

Why: A robot_state_publisher left over from make mock published the mock robot, and something took the description from that topic.

Fix: make stop first — every run target does it for you. The launch file also spawns from the same substitution rather than the topic, which closes the hole.

Terms

Mock hardware
mock_components/GenericSystem: a hardware plugin that reports every command straight back as state. Exercises the whole control stack with no physics.
Action goal status
The final verdict on an action goal — SUCCEEDED, ABORTED or CANCELED. Note that it reports what the controller did, not whether the robot ended up somewhere useful.

Every term in the course: glossary.

Check yourself

Answer in your head first, then open it.

The mock reports every command back as the measured state. So what does SUCCEEDED on the mock actually prove?

That the interface contract holds: the action exists, the names and types are right, the controllers accept, execute and complete the goal. Nothing about physics.

Why should code ask the controller for its joints instead of carrying a list?

A list is right for one robot. The SO-101's joints are not the names this project's first robot used, and a hardcoded list would have stopped every scenario on it. The controller's own parameter is, by definition, the list it will act on.

Stretch

Send a goal with shoulder_pan at 3.0 rad — far beyond its 110° limit — to the mock, then read /joint_states. Where did the joint end up, and what status did the goal report? Hold on to the answer; Tier 5 is built on it.

One way to do it

The joint stops at 1.9199 rad, its limit, because the controller manager clamps commands — and the goal still reports SUCCEEDED. A clamped motion is a "successful" motion to somewhere you did not ask for.

Going deeper