Theme
Stage 3 · project · about 1½ hours

Project: Write a scenario that runs on both backends

Add a scenario called wave to the robot's scenario library: swing the arm's first joint left and right three times, then return home. Every step must assert a post-condition, and it must pass against the mock and Gazebo with no change between them.

This is the smallest complete contribution to the project: real code, behind the real interface, verified on two backends, held to the project's own lint rules. Like the scenarios already there, it should name no joint: ask the robot client.

Tasks

  1. Read how the existing scenarios are built.

    sed -n 1,80p src/threevn_control/threevn_control/scenarios/arm.py
    
  2. Add a Wave class to arm.py, registered with @register, with name = 'wave'. Get the joint from self.robot.arm_joints(), use self.robot.move_joint(...) for the action and self.robot.get_joint_state() in the check.

  3. Run it against the mock.

    make mock
    make scenario NAME=wave
    
  4. Run it against Gazebo.

    make stop
    make sim
    make scenario NAME=wave
    
  5. Break your check on purpose — compare against the wrong angle — and confirm the step fails after its timeout rather than immediately. Then fix it.

  6. Hold it to the project's style rules.

    make lint
    

Done when

  • make scenario NAME=wave passes against the mock and against Gazebo, with no edit in between.
  • Every step in your scenario has a post-condition.
  • You saw your check fail when it should, and pass when it should.
  • make lint exits 0.
A starting point
@register
class Wave(Scenario):
    """Swing the first joint left and right, then home."""

    name = 'wave'
    description = 'Swing the arm left and right three times.'

    def run(self):
        """Wave, checking every swing."""
        joint = self.robot.arm_joints()[0]
        self.step('home first', lambda: self.robot.home(),
                  lambda: self.robot.at_pose(self.robot.pose('home')))
        for i in range(3):
            for target in (0.6, -0.6):
                self.step(
                    f'swing {i + 1} to {target:+.1f}',
                    lambda t=target: self.robot.move_joint(joint, t),
                    lambda t=target: abs(
                        self.robot.get_joint_state()[joint] - t) < 0.02)

Note the t=target default arguments. Without them, every lambda captures the same loop variable and checks the last value.

The style rules that usually bite

Single quotes for strings; the docstring summary on the line after the opening quotes; lines under 99 characters. make lint names the rule and the line.

Going deeper