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
Read how the existing scenarios are built.
sed -n 1,80p src/threevn_control/threevn_control/scenarios/arm.pyAdd a
Waveclass toarm.py, registered with@register, withname = 'wave'. Get the joint fromself.robot.arm_joints(), useself.robot.move_joint(...)for the action andself.robot.get_joint_state()in the check.Run it against the mock.
make mock make scenario NAME=waveRun it against Gazebo.
make stop make sim make scenario NAME=waveBreak your check on purpose — compare against the wrong angle — and confirm the step fails after its timeout rather than immediately. Then fix it.
Hold it to the project's style rules.
make lint
Done when
make scenario NAME=wavepasses 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 lintexits 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.