← Robot workspaceSO-101 CLASSROOM

PYTHON REFERENCE

Write a movement. Check what it does.

Start with two positions. Then use variables, loops, and functions to build longer sequences.

Run your first program

  1. In Move, choose Return simulation to reference pose before trying these examples.
  2. Open Python. Use Expand editor for more room.
  3. Copy this program into the editor, then choose Build sequence (Ctrl/⌘ + Enter also works).
  4. Read the output. Use Check, then Run simulation to watch the movement.
import robot

robot.move(shoulder_pan=10, duration=2, name="Turn")
robot.wait(1)
robot.move(shoulder_pan=0, duration=2, name="Return")
print("Two positions are ready.")

shoulder_pan=10 sets an absolute target of 10°. It does not add 10° to the previous angle. duration=2 gives the movement two seconds. name labels the saved position.

Commands provided by this app

Begin with import robot. The robot module belongs to SO-101 Classroom; it is not part of standard Python or the LeRobot API.

Command What it records Example
robot.move(...) One position with any combination of the six joint targets. Default duration: 2 seconds. robot.move(elbow_flex=5, duration=2)
robot.grip(opening, duration=2) Gripper opening as a percentage, from 0 closed to 100 open. This is not grip force. robot.grip(70, duration=4)
robot.wait(seconds=1) A pause after the last recorded movement. A wait before any movement creates a short hold position first. robot.wait(0.5)
robot.position() A dictionary containing the last requested pose in the script. It is not a sensor measurement. print(robot.position())

Several joint targets in one move change together over the same duration. Values are joint angles, not X/Y/Z coordinates. Use plain numbers, without a degree sign.

Movement time: 0.25–60 seconds per position. Pause: at most 30 seconds per position, including repeated waits. A project may contain at most 300 positions and 10 minutes of movement and pauses. Joint limits appear in the workspace. The teacher station also checks the actual arm's calibration and limits.

Match the code to the arm

Workspace label Python name Units
Base rotation shoulder_pan degrees
Shoulder shoulder_lift degrees
Elbow elbow_flex degrees
Wrist bend wrist_flex degrees
Wrist rotation wrist_roll degrees
Gripper gripper percent open

Click a robot part in the 3D view to see its joint name. Drag the part or rotation ring to explore its direction. Dragging the background turns the camera. When the ring is edge-on, drag horizontally. Press Escape during a drag to restore the starting angle.

Try the robot dance

In the Python workspace, choose Play dance to load and run a short sway, wave, and bow. Use Stop to end it. The button runs only the simulation. For a physical arm, inspect the saved sequence in the teacher station and use its existing calibration and enable controls.

Download the dance program. It uses the app's robot module. Open it with Open .py file, then build the sequence. Change beat to adjust the timing, or turns to repeat the sway. Compare the requested and measured angles.

Build up your program

1. Change a variable

Predict the effect of doubling travel_time. Does the endpoint change, or just the speed?

import robot

angle = 12
travel_time = 3
robot.move(shoulder_pan=angle, duration=travel_time)
robot.move(shoulder_pan=0, duration=travel_time)
print("Requested base angle:", robot.position()["shoulder_pan"])

2. Repeat with a loop

The loop visits each angle in the list. Its indented lines run once for each angle. Add another angle within the joint's range.

import robot

for angle in [12, 0, -12, 0]:
    robot.move(shoulder_pan=angle, duration=2)
    robot.wait(0.5)
    print("Saved target:", angle)

3. Name a useful group of commands

A function lets you reuse a procedure. Change the pause in one place, then rebuild the sequence.

import robot

def turn_and_pause(angle):
    robot.move(shoulder_pan=angle, duration=3)
    robot.wait(1)

turn_and_pause(10)
turn_and_pause(-10)
turn_and_pause(0)

In Teach, Show sequence as Python converts saved positions into code. Compare that code with the sequence you made by hand.

Find and fix an error

  1. Read the last line of the output for the error type and explanation.
  2. Choose Go to line… above the output to select the line in your program.
  3. Check that line and the one before it. Fix one issue, then build again.
Message What to check
SyntaxError Missing colon after for or def; unmatched quotes or parentheses.
IndentationError Use consistent spaces for the commands inside a loop or function. The examples use four spaces.
NameError Missing import robot, a misspelled variable, or a variable used before it was assigned.
ValueError Joint name, joint limit, duration, pause, or sequence size. Follow the explanation after the error type.
TypeError Argument names or kinds of values. Pass numbers as numbers, such as duration=2, not text.
Program does not finish Use Cancel. Check the condition of a while loop. Browser execution also stops after 60 seconds.

Use print() to inspect a variable or robot.position() while building. This editor shows output and error lines; it does not yet provide breakpoints or step-by-step Python execution.

A successful build can still create an unsuitable path. Use the simulation checks and inspect the motion before transferring a project to the teacher station.

Learn standard Python

These official references explain the language features used above. The robot.move commands are documented on this page.

The browser includes Python and its standard library. Installing extra packages is not part of this interface. The teacher's trusted local Python runs on the Mac and may have different installed libraries.