Skip to content
Programming Robots

Coordinating Movements and the Gripper


Learning Objectives

  • You can translate an absolute gripper opening into a relative change.
  • You can compose controller methods into a transfer procedure.
  • You can distinguish returning to an initial pose from shutting down.
  • You can explain what a simulated motion record does and does not show.

We now add gripper control to ArmController and combine it with joint movements.

The gripper must open before approaching an object, close before lifting, and release only after reaching the destination. A supplied movement plan describes the joint movements for those steps.

Opening and Closing the Gripper

The gripper uses a percentage of its allowed opening range. Zero is the closed end of that range and 100 is the open end. An object between the fingers can prevent a physical gripper from reaching a requested opening.

gripper_open(amount) increases the opening by a number of percentage points. gripper_close(amount) decreases it by that amount. For an arm starting at an opening of 40, predict the two readings:

arm.gripper_open(10)
print(arm.get_positions()["gripper"])
arm.gripper_close(5)
print(arm.get_positions()["gripper"])

They are 50 and 45 in the ideal model. Opening by ten percentage points adds ten to the opening; it does not multiply the current value by 1.10. The result must remain between 0 and 100.

Gripper Amounts

0 / 5 points

The simulated gripper starts at an opening of 40. What does this program print?

arm.gripper_open(15)
arm.gripper_close(5)
print(arm.get_positions()["gripper"])

An absolute request, such as opening to 60, requires a comparison with the current reading. From 40, open by 20. From 75, close by 15. If the current reading is already 60, no movement is needed.

Implement set_opening(opening) using gripper_open and gripper_close. Do not use the API’s direct set_gripper method in this exercise. Validate the requested opening before moving, and return the final position dictionary.

Setting the Gripper Opening

0 / 25 points

Complete set_opening(self, opening) in ArmController. The argument is the desired gripper opening, from 0 to 100. It is a finite number.

Read the current opening with self.arm.get_positions(). If the desired opening is larger, use gripper_open with the difference. If it is smaller, use gripper_close with the difference. An equal opening needs no movement. Use these relative commands rather than set_gripper.

Reject an opening outside 0–100 by raising ValueError before any movement. Return a fresh position dictionary read from the arm after the operation. Leave the body joints unchanged.

The constructor and demonstration are provided. Run check.py to try a few checks without a physical arm.

A Prepared Transfer Plan

A transfer plan combines joint sequences and gripper openings. The supplied plan has these fields:

FieldContents
approachMovement records leading toward the pickup area
pickupMovement records positioning the gripper at the pickup point
liftMovement records lifting away from that point
destinationMovement records leading to the release point
retractMovement records leading away after release
openThe opening used before pickup and after transfer
closedThe smaller opening used during transfer

Each movement list uses the joint, angle, and seconds records from the previous chapter.

The next starter includes working set_opening and play_sequence methods. Another method inside ArmController could combine them to open the gripper and follow one route:

def prepare(self, moves, opening):
self.set_opening(opening)
self.play_sequence(moves, 1)
return self.arm.get_positions()

Here, self.set_opening and self.play_sequence call methods on the controller. self.arm.get_positions calls a method on its arm. Given a controller and a plan, a caller could use the new method like this:

positions = controller.prepare(plan["approach"], plan["open"])
print(positions["gripper"])

The gripper reaches plan["open"] before the approach route starts. The 1 requests one execution of that route. A complete transfer combines more steps, in this order:

  1. Set the opening to plan["open"].
  2. Run the approach and pickup sequences once each.
  3. Set the opening to plan["closed"].
  4. Run the lift and destination sequences once each.
  5. Set the opening to plan["open"] again.
  6. Run the retract sequence once, then call finish().

Before writing the method, trace where the arm and gripper would be after step 3. What would go wrong if the lift sequence ran before the closing operation? What if the release happened before the destination sequence?

Check your trace

After step 3, the arm is at the pickup point and the gripper has closed to the requested opening. On a physical arm, lifting before closing could leave the object behind; releasing early could drop it before the destination.

The starter supplies a valid plan and working play_sequence and set_opening methods. Implement transfer(plan) by calling them in order, then return a fresh position dictionary.

A Transfer Controller

0 / 25 points

Complete transfer(self, plan) in ArmController, using the supplied play_sequence and set_opening methods.

First set the gripper to plan["open"]. Play "approach" and "pickup", then set the gripper to plan["closed"]. Play "lift" and "destination", open the gripper to plan["open"], and play "retract". Finally call self.arm.finish() and return a fresh position dictionary from the arm. Play each sequence once, including empty sequences.

The plan is valid. Each named route is a list of movement records, and the two opening values are between 0 and 100. Keep the plan unchanged.

This program demonstrates the order of a transfer procedure. The simulator records joint and gripper movements; it does not simulate an object being gripped. Run check.py to check the procedure without a physical arm.

After attempting the exercise, run the worked program and compare its operation order with yours. Change the supplied scene values and compare the printed positions.

Edit main.py; the supporting API files are provided.

No files opened Select a file to edit

Returning and Shutting Down

finish() moves the arm to the position saved when it was initialized. That includes the gripper. The method completes before returning, and the physical arm continues holding its position. The prepared retract route runs first so the transfer procedure does not jump directly from the release point to the initial pose.

The return is a joint movement. It does not calculate a vertical lift or choose a route around obstacles. For laboratory use, staff choose an initial pose and a retract route suitable for the scene.

Shutdown is separate: the launcher cleans up the connection after the program. On a physical arm, that can release the motors’ holding force. When a movement error causes the API to stop accepting commands, it reports SHUTDOWN and raises the error.

Inspecting a Simulated Run

The SO101 simulator keeps modeled joint positions, applies the API’s limits, and advances a virtual clock during movement. It can record a list of motion samples. Each sample object has a time in seconds and a positions record:

arm.rotate("wrist_roll", 15, duration=1)
history = arm.motion_history
last = history[-1]
print(last.time)
print(last.positions["wrist_roll"])

The recording includes intermediate steps, so its length need not equal the number of method calls. The returned list is a copy, and the sample records are read-only. Compare their times and joint values when checking how a sequence changed the arm.

The simulator does not model gravity, collisions or grasping. The transfer exercise checks that the required operations occur in order.

Simulation and a Physical Arm

0 / 5 points

A student’s ArmController completes the simulated transfer procedure. The teacher wants to try that controller with a physical SO101 arm. Which statement is correct?

Check Your Understanding

  1. Starting at an opening of 30, how far should the gripper open to reach 55?
  2. Why can transfer use play_sequence and set_opening instead of containing their implementation again?
  3. What happens to the gripper when finish() returns the arm to its saved initial pose, and how does that differ from shutting down?
  4. Why can a correct simulated transfer still need adjustment before a physical demonstration?