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 Part2: Feetech Motor Control Using Python — Two Motors

This notebook continues from Lab2 Part 1 - Single Motor Control.ipynb. Make sure you’ve completed Task 1 (hardware connection) and Task 2 (single motor control) there first — this notebook assumes you already know your COM port and are comfortable with basic position control.

What you will do

Two Motor Control

  1. Assign unique IDs to each motor so they can be addressed independently

  2. Move two motors to different target angles simultaneously

  3. Command each motor to follow a different sine wave and compare the results

When you finish Task 3, close this notebook and open Lab2 Problems.ipynb to work on the problems.

Lab 2 Part 2 ready.

Control Two Motors

Assign a Unique ID to the Second Motor

Every motor on the same bus cable must have a unique ID (a number from 1 to 253). Motors arrive from the factory with ID = 1. Before you can control two motors independently, you need to change one motor’s ID so the two motors no longer share the same number.

Before running the cell below:

  1. Disconnect the first motor from the bus adapter

  2. Connect only the second motor to the adapter

Why connect only one motor at a time? If two motors share the same ID, they both respond to every command — you cannot address them separately. Assigning IDs with a single motor connected prevents this conflict.

The cell below calls assign_motor_id(port, existing_ids) from Lab2_helpers.py. It first scans the bus and reads the motor’s current ID automatically (so you don’t need to already know it), prints it, then prompts you to type the new ID. You can find the prompt on the top of VS code. It refuses to assign an ID that’s already in existing_ids (the other motor’s ID), so you can’t accidentally create the same conflict you’re trying to avoid — it will just ask you to try again.

Under the hood it uses two smaller helpers you can also call directly: scan_motor_id(port) to detect a connected motor’s current ID, and write_motor_id(port, current_id, new_id, existing_ids) to perform the actual write. There’s also a matching read_motor_id(port, motor_id) you can use afterward to double-check which ID a motor is actually using, once you know it.

After running, power-cycle the motor (unplug and re-plug the 12V supply) to save the new ID permanently.

Found motor with ID 2.
Motor ID is already 2. No change made.

Now reconnect both motors in a daisy-chain: the first motor connects to the adapter, and the second motor connects to the first motor’s pass-through port using another 3-pin cable. Only one USB cable goes to your laptop — the bus handles communication to all motors.

This is one of the key advantages of a bus servo system: you can chain many motors together with just two wires and still address each one by its unique ID.

Your setup should look like something shown in the following picture

Two-Motor Control

Two motors on the same bus use the same helper functions from Lab2_helpers.py you already used in Part 1 — you just pass a list of two motor IDs to connect_motors, and two angles to write_angles, instead of one:

FunctionWhat it does
connect_motors(port, [id1, id2])Opens a connection to both motors and enables position control. Returns a shared bus object.
write_angles(bus, deg1, deg2)Commands both motors to their target angles simultaneously in one packet.
read_angles(bus)Reads both motors’ current angles. Returns (angle1, angle2) in degrees.
disconnect_motors(bus)Disables torque on both motors and closes the connection.

Nothing about these functions is specific to “two” — the same calls work for three motors (and beyond) later in the course.

Motor 1: 0.4°
Motor 2: 0.1°
Motors disconnected.
Both motors ready.

Move Two Motors to Different Angles Simultaneously

Both motors receive their target angles in a single command packet — the adapter broadcasts both targets at once so both motors begin moving at exactly the same instant. This is called a synchronous write and is how real robot controllers coordinate multiple joints.

Change TARGET_1 and TARGET_2 to try different combinations. Notice that both motors start and stop simultaneously regardless of how far each one has to travel — the motor with the larger move simply takes longer to arrive.

Motor 1 target : 60.0°
Motor 2 target : -45.0°

Recorded 140 samples over 2.99 s (~47 Hz achieved).
Final positions:
  Motor 1: 59.85°  (target 60.0°)
  Motor 2: -44.91°  (target -45.0°)
Motors disconnected.

The plot below shows both motors’ positions over time. The dashed lines mark the target angles. Things to look for:

  • Both motors start moving at the same instant (synchronous command)

  • Each motor follows a smooth trapezoidal velocity profile — it accelerates, cruises, then decelerates

  • The motor with the larger travel distance takes longer to arrive at its target

<Figure size 1000x500 with 1 Axes>
Plot saved as two_motor_angles.png

Two Motors Following Different Sine Waves

Each motor tracks its own independent sine wave, both commanded in the same write_angles call every 20 ms. This demonstrates real-time coordinated multi-joint control — the same principle the SO-Arm 101 will use when you control it as a complete robot later in the course.

Motor 1Motor 2
Amplitude45°25°
Frequency0.4 Hz0.8 Hz
Period2.5 s1.25 s

Motor 2 oscillates twice as fast with a smaller swing. Because both are commanded in the same packet each step, their motions remain time-synchronized throughout the run.

Motor 1: A=45.0°  f=0.4 Hz  (period = 2.50 s)
Motor 2: A=25.0°  f=0.8 Hz  (period = 1.25 s)
Running — do not interrupt until 'Done' appears...
Motors disconnected.
Done. Recorded 188 samples over 9.97 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 six-panel plot below shows:

  • Top row: reference vs. actual trajectory for each motor

  • Middle row: tracking error for each motor, with the RMS value in the title

  • Bottom row: both motors overlaid on the same axes for direct comparison

Notice that Motor 2 (faster, 0.8 Hz) accumulates larger tracking error than Motor 1 (slower, 0.4 Hz) — a clear demonstration that a higher command frequency demands more from the actuator.

<Figure size 1300x1000 with 5 Axes>
Plot saved as dual_sine_tracking.png

Next Steps

You’ve assigned unique IDs to two motors, moved them to independent targets simultaneously, and tracked two different sine waves at once.

Continue to Lab2 Problems.ipynb to apply what you’ve learned in Parts 1 and 2.