Moving a Token
Learning Objectives
- You can execute a list of prepared poses in order.
- You can collect position records after completed movements.
- You can combine movement with grabbing and releasing a token.
A pose describes one destination for the joints. A list of poses describes a route. We will first visit such a route, then carry a token between two prepared poses. The simulator still supplies all geometry; our program chooses the operation order.
Sequences of Poses
A list can store movements in order. The scene supplies a pickup pose beside the token and a rest pose:
def program(arm, scene): steps = [ {"pose": scene["pickup"], "seconds": 1}, {"pose": scene["rest"], "seconds": 2} ] for step in steps: arm.move_to(step["pose"], duration=step["seconds"]) print(arm.positions())Each call finishes before the next begins. Changing a duration changes the movement time; changing the list order changes the route. The token stays in place because neither movement grabs it. Printing arm.positions() after each movement shows its result. Each call returns a fresh record, so collecting those records gives a history of the completed visits.
Run main.py below to inspect the route and its printed positions. Right arrow completes the next command, Space plays or pauses, and R resets playback. After editing program, Run main.py again.
The following exercise collects that history while visiting a supplied sequence. Use each step’s own duration rather than the same duration for the whole list.
Visiting a Sequence of Poses
0 / 25 points
Write visit_poses(arm, steps) in main.py. Each record in steps contains a full two-joint "pose" and a "seconds" duration. Visit them in list order with arm.move_to, using each record’s duration.
After each completed movement, collect a fresh arm.positions() record. Return the collected records in order. An empty list gives an empty result; repeated poses are still separate visits.
Keep the supplied records unchanged. Poses and nonnegative durations are valid for the simulator. Run the preview to see the movements and printed position records.
Grabbing and Moving a Token
arm.grab() attaches the token when it is within 0.15 metres of the gripper. Otherwise, the simulator reports that the token is out of reach. Once attached, the token follows the gripper until arm.release() leaves it at the current endpoint.
This is a view from above: a released token stays where it is placed. The simulation has no falling or gravity.
Moving between prepared poses carries the token only while it is attached. Reach the pickup pose before grabbing, keep the token attached during the move to destination, and release after that move finishes.
Implement this sequence in move_token(arm, pickup, destination, seconds). The caller supplies both poses and the duration to use for each movement. Return None and preserve the supplied dictionaries.
Move a Token
0 / 25 points
Write move_token(arm, pickup, destination, seconds) in main.py. Move to pickup over seconds, grab the token, move to destination over the same duration, and release it.
Use the supplied arm and both prepared pose dictionaries without changing the dictionaries. Poses and nonnegative durations are valid. A zero-duration move_to reaches its pose immediately. Return None.
Run the supplied preview to inspect the transfer.
Run the exercise’s main.py to inspect your transfer. While the token is attached, it follows the curved route of the gripper rather than moving directly between two screen coordinates.
Check Your Understanding
- Why should a position record be collected after its movement, rather than before it?
- How do changing a step’s duration and changing the list order affect a pose sequence differently?
- Which operations must surround a movement for the token to travel with the gripper and remain at the destination?