Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lab2 Part1: Feetech Motor Control Using Python — Single Motor

In this lab we will use Python to control Feetech STS3215 servo motors — the same motors used in the SO-Arm 101 robot you will build later in the course. This notebook covers wiring up one motor and learning to control it directly.

This lab is split across three notebooks:

  • Part 1 (this notebook) — connect one motor; position control, trajectory tracking, speed control

  • Part 2 (Lab2 Part2 - Two Motor Control.ipynb) — add a second motor and coordinate both simultaneously

  • Problems (Lab2 Problems.ipynb) — open-ended exercises built on Parts 1 and 2

In this part, you will

Task 1 — Connect the Hardware

Set up the motor, power supply, and USB adapter.

Task 2 — Single Motor Control

  1. Move the motor to a target angle and read back the actual position

  2. Command the motor to track a sine wave trajectory and measure how closely it follows

  3. Control motor speed in wheel mode

When you finish Task 2, close this notebook and open Lab2 Part2 - Two Motor Control.ipynb.

Task 1: Hardware Connection

You need four components for this lab:

ComponentPurpose
Feetech STS3215 motor (12V, C018)The actuator — same motor used in SO-Arm 101. Order link
12V / 8A power adapterPowers the motor. Order link. Others will work as long as it provide 12V and at least 8A
Bus Servo AdapterTranslates USB commands into the motor’s serial protocol. Order link
USB-C cableConnects your laptop to the adapter.

⚠️ If you damage your motor, power supply, or the Bus Servo Adapter, you are responsible for replacing it.

Important: There are several versions of the STS3215 servo. The one used in this lab is the 12V version (part number: ST-3215-C018).

Wiring steps

Step 1 — Motor to adapter (3-pin cable)
Match the wire colors: Black → G (Ground), Red → V (Voltage), White → D (Data).
Set the adapter’s mode switch to USB-SERVO (B Mode).

Step 2 — USB cable
Plug the USB-C cable from the adapter into your laptop.

Step 3 — Power supply
Connect the 12V supply to the adapter and switch it on.
You should see red LEDs light up on both the adapter and the motor.

Your setup should look like this

Find your COM port

The motor communicates through a serial (COM) port. You need to know which port your adapter is assigned to. Open Anaconda, first activate the course environment

activate me416

Then run the port-finder tool

lerobot-find-port

You will see output like COM3 or COM5. The following is an example showing COM4

Revise the following code to the correct COM based on your connection.

Important: If you reconnect the adapter to a different USB port on your computer, run the port-finder tool again. The adapter may be assigned a different COM port number. In this case, it is good to mark it on your laptop using a pencile so that you don’t need to do this next time when you connect to the same USB port.

Lab2 Part1 ready.

Task 2 — Single Motor Control

Task 2.1 — Move the Motor to a Target Angle

We’ll control the motor with four helper functions from Lab2_helpers.py (already imported in the session-setup cell). These same functions also work with two or more motors later in the course — you just pass more angles or IDs.

FunctionWhat it does
connect_motors(port, motor_id)Opens a connection to the motor over the USB adapter, sets position control mode, and enables torque. Returns a bus object.
write_angles(bus, deg)Commands the motor to move to a target angle (degrees) and hold it there.
read_angles(bus)Reads back the motor’s current angle (degrees).
disconnect_motors(bus)Disables torque and closes the connection, releasing the COM port.

Internally, the motor measures position in integer steps called ticks (4096 ticks = one full revolution; 2048 ticks = 0°) — write_angles and read_angles handle that degrees ↔ ticks conversion for you.

Try it: change TARGET_DEG to different values such as 30, 90, or −45 and re-run the cell. Notice that the measured position always matches the target closely once the motor has had time to settle.

Curious what happens inside these functions? Open Lab2_helpers.py to see the raw FeetechMotorsBus commands they wrap.

Target  : 90.0°
Measured: 89.7°
Motor disconnected.

Try it: To see the angle change more obviously, put one of the metal disk horn in the motor package onto motor shaft. You can use your pen to draw a line on this horn.

Task 2.2 — Follow a Sine Wave Trajectory

So far the motor moved to a fixed angle and stopped. Now we will command it to continuously track a moving target. Instead of sending one position command, we send a new position command every 20 ms, where each new target follows a sine wave:

θref(t)=Asin⁡(2πft)[degrees]\theta_{\text{ref}}(t) = A \sin(2\pi f t) \quad [\text{degrees}]
  • A = amplitude — how far the motor swings to each side (degrees)

  • f = frequency — how many complete back-and-forth cycles per second (Hz)

The code records both the reference (commanded) and actual (measured) angle 50 times per second. After the run finishes, the next cell plots the two signals and computes the tracking error.

Try it: After running once at SINE_FREQUENCY_HZ = 0.5, change the frequency to 1.0 or 2.0 and run again. Think about what will happen at higher frequencies and verify it on the motor. Why this happens?

Sine wave parameters:
  Amplitude : ±45.0°
  Frequency : 5 Hz  (period = 0.2 s)
  Duration  : 6.0 s

Running — do not interrupt until 'Done' appears...
Motor disconnected.
Done. Recorded 114 samples over 5.96 s (~19 Hz achieved vs. 50 Hz requested -- write+read round trips over the bus are the limiting factor).
Run the next cell to plot the results.

The plot below shows two panels:

  • Top: reference (blue dashed) vs. actual (red solid) angle. Good tracking means the two lines overlap. At higher frequencies you will see the red line lag behind and shrink in amplitude.

  • Bottom: tracking error (actual − reference). The RMS value summarises the average error over the entire run.

A smaller RMS error and tighter overlap in the top panel means the motor is tracking well.

<Figure size 1100x700 with 2 Axes>
RMS tracking error: 33.64°
Plot saved as sine_tracking_single.png

Task 2.3 — Speed Control (Wheel Mode)

So far we have used position control: you specify a target angle and the motor drives itself there. The STS3215 also supports speed control (also called wheel mode), where you specify a rotational speed instead of a target angle. The motor spins continuously at that speed until you send a new command.

Position controlSpeed control
You specifyTarget angle (°)Rotational speed
Motor doesMoves to target and holdsSpins continuously
Stops whenIt reaches the targetYou command speed = 0

Two more helper functions from Lab2_helpers.py handle wheel mode, mirroring connect_motors/write_angles from Task 2.1:

FunctionWhat it does
connect_motors_velocity(port, motor_id)Opens a connection to the motor and switches it to velocity (wheel) mode instead of position mode. Returns a bus object.
write_speeds(bus, speed)Commands the motor to spin continuously at speed.

Speed values for STS3215:

  • 0 → stop

  • Positive values (e.g. 300, 600, 1000) → rotate in one direction

  • Negative values (e.g. -300, -600, -1000) → rotate in the opposite direction

  • ±1000 ≈ maximum speed (~50 RPM at 12V)

⚠️ In speed mode the motor spins without a position limit. Keep the motor shaft free of any load or attachment when running this task.

Spinning at speed -300 for 3.0 s ...
Motor disconnected.
Done.

Next Steps

You’ve moved a single motor to a target angle, tracked a sine wave trajectory, and driven it in speed (wheel) mode.

Continue to Lab2 Part 2 - Two Motor Control.ipynb to assign a second motor its own ID and control both motors together.