FastRobots

ECE4160/5160-MAE 4190/5190: Fast Robots course, offered at Cornell University in Spring 2024

This project is maintained by FastRobotsCornell

Fast Robots @ Cornell

Return to main page

Lab 5: Linear PID control and Linear interpolation

Objective

The purpose of this lab is to get experience with PID control. The lab is fairly open ended, you can pick whatever controller works best for your system. 4000-level students can choose between P, PI, PID, PD; 5000-level students can choose between PI and PID controllers. Your hand-in will be judged upon your demonstrated understanding of PID control and practical implementation constraints, and the quality of your solution.

This lab is part of a series of labs (5-8) on PID control, sensor fusion, and stunts. This week you will do position control.

Parts Required

Prelab / BLE

No matter which task you take on, it will be essential that you first setup a good system for debugging.

Please attempt to implement this before your lab session. Feel free to discuss the best strategy with your team mate.

A good technique will be to:

  1. Have the robot controller start on an input from your computer sent over Bluetooth
  2. Execute PID control over a fixed amount of time (e.g. 5s) while storing debugging data in arrays.
    • Remember to have a hard stop implemented directly on your Artemis, so that your robot will stop even if the Bluetooth connection fails.
  3. Upon completion of the behavior, send the debugging data back to the computer over Bluetooth.

Debugging data may for example include sensor data with time stamps similar to what you implemented in lab 2-3, output from the individual branches of your PID controller, and/or the input that you are sending to your motors. Remember, however, the storage cannot exceed the internal RAM of 384kB. If you plan to do a lot of tweaking of your gains, you can also consider writing a Bluetooth command that lets you update the gains without having to reprogram the Artemis.

Lab Procedure

Position Control

For this task, you will have your robot drive as fast as possible (given the quality of your controller) towards a wall, then stop when it is exactly 1ft (=304mm=1 floor tile in the lab) away from the wall using feedback from the time of flight sensor. Your solution should be robust to changing conditions, such as the starting distance from the wall (2-4m). If you attempt to do this at home, you could also show that your solution is robust to changing floor surface, e.g. linoleum or carpet. The catch is that any overshoot or processing delay may lead to crashing into the wall.

Beyond the considerations mentioned above, think about the following:

Below you can see an example of a simple PI controller acting on the TOF signal.

Tips and tricks:

Corresponding videos are here:

Solution 1 Solution 2.

Extrapolation

In Lab 7, you will learn how the Kalman Filter works, you could implement this on your robot and use it to speed up sampling of the estimated distance-to-the-wall. However, getting the Kalman Filter to work in practice takes time. A simple but less accurate alternative is a data extrapolator.

Write a function to extrapolate new TOF values based on recent sensor values, such that you can drive your robot quickly towards the wall with high accuracy. Be sure to demonstrate that your solution works by uploading videos and by plotting corresponding raw and estimated data in the same graph.

Instructions:

  1. Determine the frequency at which the ToF sensor is returning new data.
    • This is likely the rate at which your PID control loop is running as well. We want to decouple these two rates.
  2. Change your loop to calulate the PID control every loop, even if there is no new data from the ToF sensor.
    • Check if new data from the ToF sensor is ready. If it is, update the variable that PID controller is using to estimate the motor speed.
    • If a new datapoint isn’t ready, recalculate the PID control using using the last saved datapoint.
    • The net effect this should have on your system should be the same. You PID control should now be running faster than your ToF sensor is generating new data.
  3. How fast is the PID control loop running? Compare this rate to ToF sensor rate.
  4. Rather than use an old datapoint to calulate the PID control, extrapolate an estimate for the car’s distance to the wall using the last two datareadings from the ToF sensor.
    • Calcuate the slope from the last two datapoint, and extrapolate the current distance based on the ammount of time that has passed since the last reading and the slope.
    • This is a simple linear extrapolation algorithm. Everytime you get a new ToF reading, use it along with the previous reading to estimate the current distance to the wall untill a new reading is recieved. If you have any questions about this, please ask one of the TAs for clarification.

Tasks for 5000-level students

Implement wind-up protection for your integrator. Argue for why this is necessary (you may for example demonstrate how your controller works reasonably independent of floor surface). Demonstrate your system with and without wind-up protection.

Write-up

Word Limit: < 800 words

Webpage Sections

This is not a strict requirement, but may be helpful in understanding what should be included in your webpage. It also helps with the flow of your report to show your understanding to the lab graders. This lab is more open ended in terms of the steps taken to reach the end goal, so just make sure to document your process you take to complete your task, including testing and debugging steps!

  1. Prelab
    • Clearly describe how you handle sending and receiving data over Bluetooth
    • Consider adding code snippets as necessary to showcase how you implemented this on Arduino and Python
  2. Lab Tasks
    • P/I/D discussion (Kp/Ki/Kd values chosen, why you chose a combination of controllers, etc.)
    • Range/Sampling time discussion
    • Graphs, code, videos, images, discussion of reaching task goal
    • Graph data should include Tof vs time and Motor input vs time (and whatever helps with debugging)
    • (5000) Wind-up implementation and discussion

Add code (consider using GitHub Gists) where you think is relevant (DO NOT paste your entire code).