Lab 1 - Hello PID

Mini-lecture - Actuators and PD Control

Actuators and PD control lecture by Stuart Bowers, April 10, 2023.

Lab Instructions

Goal: Build two robot arms that mirror each other’s motion.

[Insert GIF of completed robot arms]

Step 0. Setup

  1. Install VSCode

  2. Install the PlatformIO extension for VSCode. (Might take several minutes on Windows - check the bottom bar in VSCode for status)


Step 1. Assembly motor to base


Step 2. Fasten feet to base


  • Ignore that there’s a whole robot arm attached in the video.

Step 3. Attach dial to motor


Step 4. Connect and calibrate electronics

ELECTRONICS SAFETY: Make sure to separate the PCB from the metal base before turning on the power, otherwise the circuit will short! Either elevate the PCB above the base with the screws provided, or place the PCB next to the metal base on the table.


  1. Turn on the system: press the power button on the PCB shield.

  2. Calibrate: Press and hold the button on the C610 motor controller until the motor starts moving and release.

  3. Wait until the C610 motor controller restarts.

  4. Set ID: Click the button on the C610 controller, then a little while later (half second or so) press the button again. The light should flash green.

  5. The light should now flash once every 2 seconds or so. The number of blinks indicates which ID it is. For example two blinks every 2 seconds indicates ID=2.

Important: To set a motor controller to a certain ID, click (short press) press to put the motor controller into id-setting mode, then click N more times in quick succession, where N is the desired ID. Eg, for a desired ID of 3, press 3 more times after the first click.

Step 4. Run the starter code

  1. Git clone the starter code, open in VSCode, and upload to Teensy.

  1. Examine where in the code the motor angle and velocity are read in src/main.cpp. Examine where the motor is commanded.

  2. Upload starter code to Teensy (right arrow icon in blue bar of VSCode or click the ant icon, then upload)

  3. Open the serial monitor in VSCode (icon that looks like a plug in bottom bar of VSCode or click ant icon, then monitor)

  4. Click into the serial monitor area and then press the key s to make the Teensy start printing out the angle and velocity of the connected motor.

  5. Press s again to stop the program. If you want to rerun the code, upload again or unplug and replug your computer from the Teensy.

../_images/example-output.png

Example output from serial monitor.

Step 5. Run bang-bang control

  1. Uncomment the bang-bang code in src/main.cpp and upload.

  2. Observe the effects of changing the current command to something else.

  3. FEEL how the controller behaves. Move the dial by hand and see how the controller reacts.

Example bang-bang control.


Step 6. Write PD position control

  1. Comment out the bang-bang controller.

  2. Complete the pd_control function in src/main.cpp. Your function should return a current command (100mA, 200mA etc) using the PD control law tau = Kp * (target - theta) + Kd * (-omega).

  3. Use Kp = 1000.0 and Kd = 0.0 to start. Don’t forget the negative signs!

  4. Upload code to Teensy

  5. FEEL the effect of the PD controller.

  6. What happens when you rotate the disc just a little bit away from the target position? What happens when you rotate it a lot away from the target position? Do you feel the motor torque increase and then flatten out as you rotate the disc?

[Insert gif of proper PD joint control]

Step 7. Experiment with different parameters

Note: Some of these steps will cause the output disc to go unstable and violently shake, be prepared!

For each of these situations (except the ones that go unstable), rotate the disc around with your hand to get a physical sense for the PD behavior.

  1. Keeping Kd constant (0), experiment with Kp = -100 and Kp = 5000. Discuss with your partner how each feels. How are Kp and stiffness related?

  2. Keeping Kp constant (1000), experiment with different Kd values from -10 to 1000

  3. See what happens when Kp is too high. Try Kp=50000 and Kd=100.

  4. See what happens when Kd is too high. Try Kp=0 and Kd=100000.

  5. See what happens with just moderate damping. Try Kp=0 and Kd=100.

The expected behavior is that higher Kp values will make the position control more stiff while higher Kd values will make the motor slower to achieve the desired position. If either gain is too high or is negative, the motor will go unstable.

[Insert gif of some instability]

Step 8. Experiment with different loop rates

  1. Examine where the code is checking if it’s time to issue another control update.

  2. Change the update rate to 4Hz with Kp=1000 and Kd=100 to observe instability.

Step 9. Program periodic motion

  1. Set the update rate back to 200Hz (5ms interval).

  2. Program the motor to track a sinusoidal position, like the psuedocode below.

float time = millis() / 1000.0
position_target = sin(time)
  1. Play around with different frequencies. How high can you raise the frequency before the motor no longer moves as much as you expect?

Fun fact, the maximum frequency you can go before the motor moves to only 71% (-3dB) of the intended motion is called the bandwidth.

[Insert gif of sinusoidal motion]

(Old) Mini-lecture - Joint Control