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.

Lab 2 Problems: Feetech Motor Control Using Python

This notebook assumes you’ve completed Lab2 Part 1 - Single Motor Control.ipynb and Lab2 Part 2 - Two Motor Control.ipynb. It contains three open-ended problems that build on the helper functions and hardware setup from those notebooks.

ProblemMotors needed
Problem 1 — Step Response Through Five Angles1 motor
Problem 2 — Differential Drive: Forward and Turn2 motors, re-IDed and daisy-chained (from Part 2)
Problem 3 — Three Motors: Target Angles and Sine Wave Tracking⚠️ 3 motors — you’ll re-ID and daisy-chain a third motor as part of this problem

Problem 1 — Step Response Through Five Angles

Goal: Command the motor to move through the sequence of angles 0° → 45° → 90° → 135° → 180°, record the position response for each move, and plot all five curves on the same axes. From your plot, estimate how long the motor takes to settle at each target.

Background: Each time you send a new position command, the motor executes an internal trapezoidal velocity profile — it accelerates, cruises at peak speed, then decelerates into the target. A larger angular step requires a longer cruise phase, so it takes more time to arrive. This experiment lets you observe and measure that directly.

Steps:

  1. Define the list of target angles: [0, 45, 90, 135, 180]

  2. Connect the motor and send it to 0° first so all moves start from a known position

  3. Loop through each target angle, calling move_to_angle_and_record() to send the command and capture the 3-second response

  4. Disconnect the motor

  5. Plot all five step responses on the same axes; each curve starts near the previous angle and travels to the current one

What to fill in:

  • The call to move_to_angle_and_record(...) inside the loop

  • The plotting loop (one ax.plot call per target)

Discussion question: Does a larger angular step (e.g., 0° → 90°) take more time to settle than a smaller one (e.g., 90° → 135°)? Why or why not?

Look at your plot. For which step does the motor take the longest to settle? Does settling time increase with step size? Can you estimate the settling time (in seconds) for the largest step?

Answer: (write your answer here)

Problem 2 — Differential Drive: Forward and Turn

Goal: Use two motors to simulate a differential-drive wheel robot. In a differential-drive robot the two wheels are driven independently — the difference in speed between the two wheels determines the robot’s motion.

MotionLeft wheel (Motor 1)Right wheel (Motor 2)
Move forward+speed+speed (same magnitude)
Spin left in place−speed+speed
Spin right in place+speed−speed
Gradual turn+slow+fast (or vice versa)

You will run two experiments and plot the commanded speed profile for each:

  1. Forward: both motors at the same positive speed for 3 seconds

  2. Turn: both motors at equal-but-opposite speeds for 3 seconds (spin in place)

Same helpers as before, in velocity mode:

FunctionWhat it does
connect_motors_velocity(port, [id1, id2])Opens a connection to both motors and switches both to velocity (wheel) mode. Returns a bus object.
write_speeds(bus, speed1, speed2)Commands both motors to spin at speed1, speed2 simultaneously.

Steps:

  1. Connect both motors in velocity mode using connect_motors_velocity

  2. For the forward case: send the same speed to both motors, hold for RUN_SEC, stop

  3. For the turn case: send +TURN_SPEED to motor 1 and −TURN_SPEED to motor 2, hold, stop

  4. Disconnect

  5. Plot commanded speed vs. time for both motors in each case

What to fill in:

  • The write_speeds(...) call for the forward case

  • The write_speeds(...) call for the turn case

If you wanted the robot to make a gradual left turn (arc) instead of spinning in place, how would you change the two speed values? What would happen if one speed were zero?

Answer: (write your answer here)


Problem 3 — Three Motors: Target Angles and Sine Wave Tracking

⚠️ This problem requires a third motor. You’ll assign it an ID and daisy-chain it onto the two motors from Part 2.

Goal: Extend the two-motor experiments to three motors. You will first move all three motors to different target angles simultaneously, then command each motor to track its own independent sine wave.

Before you start — assign an ID to the third motor:

  1. Unplug both motors from the bus adapter.

  2. Connect only the third motor to the adapter.

  3. Run the re-ID cell below — it scans the bus to find the motor’s current ID, then prompts you to type the new ID (pick something not already used, e.g. 3).

  4. Power-cycle the motor (unplug and re-plug the 12V supply) to save the new ID.

  5. Reconnect all three motors in a daisy-chain: Adapter → Motor 1 → Motor 2 → Motor 3.

Good news: connect_motors, write_angles, read_angles, and disconnect_motors already work for any number of motors — the same functions you used for one motor in Part 1 and two motors in Part 2. There’s nothing new to write for the connection itself; you just pass a list of three IDs instead of two.

Steps:

  1. Connect all three motors: connect_motors(PORT, [MOTOR_ID_1, MOTOR_ID_2, MOTOR_ID_3])

  2. Move all three motors to different target angles simultaneously and print the actual vs. commanded positions.

  3. Command all three motors to follow independent sine waves (different amplitude and frequency for each). Fill in the parameters for Motor 3.

  4. Plot the tracking results for all three motors.

Key insight: sync_write and sync_read (which write_angles/read_angles use internally) address any number of motor IDs in a single packet. Going from two motors to three took no new code — just a longer list of IDs and one more angle per call.

Re-ID the third motor

This is the same re-ID procedure from Part 2’s Task 3.1, reused here for the third motor, using assign_motor_id from Lab2_helpers.py. It detects the motor’s current ID automatically and prompts you for the new one. Connect only the third motor before running this cell.

Which motor has the largest tracking RMS error? Is it the one with the highest frequency, lowest frequency, or largest amplitude? Why?

Answer: (write your answer here)