WiFi PID Redbot Robot Webserver

Project Overview

About the Project

This project allows the user to experiment with PID control to match the speed to two DC motors on a robot platform. A webservice hosted on the mBed allows the user to connect to the robot over WiFi, using a webclient such as Firefox, to change PID gains and setpoint.

Note

Prior to using your ESP8266 in this project it must be configured to connect to your router. Read about the ESP8266 and configure it according to the link here: https://developer.mbed.org/users/4180_1/notebook/using-the-esp8266-with-the-mbed-lpc1768/. The link talks about the ESP8266 and provides a program to configure your ESP8266 and a demo mBed webserver program.

Parts List and Vendors

PartSellerPart #
Shadow Robot ChassisSparkfunROB-13301
Gearmotor PairSparkfunROB-13258
Wheels- 65mm PairSparkfunROB-13259
Wheel Encoder KitSparkfunROB-12629
microSD Card BreakoutSparkfunBOB-00544
microSD Card 8GBSparkfunCOM-11609
mBed-LPC1768SparkfunDEV-09564
ESP8266 Wifi ModuleSparkfunWRL-13678
TB6612FNG Dual Motor Driver CarrierPololu713
High Current 3.3V Power Supply
High Current 5V Power Supply

Information

Find assembly instructions for the robot chassis and encoders here: https://learn.sparkfun.com/tutorials/assembly-guide-for-redbot-with-shadow-chassis

Pin Connection Tables

mBedESP8266330uF Cap
p26Reset
p13Rx
p14Tx
Vcc - 3v3+
GND - gnd-
mBedTB6612
p24PWMA
p17AIN2
p18AIN1
STBY -> 3v3
p20BIN1
p19BIN2
p25PWMB
AO1 -> Left Motor (+)
AO2 -> Left Motor (-)
BO2 -> Right Motor (+)
BO1 -> Right Motor (-)
VMOT -> 5V supply
VCC -> 3v3
GND -> gnd
mBedmicroSD Breakout
CD -> NC
p6DO
GND -> gnd
p7SCK
Vcc -> 3v3
p5DI
p8CS
mBedLeft Encoder
p22Output
Vcc -> 3v3
GND -> gnd
mBedRight Encoder
p21Output
Vcc -> 3v3
GND -> gnd

Information

The ESP8266 can draw a peak current of 500mA and 250mA during RF Bursts. Ensure the 3v3 supply can handle this while still supplying other components. You may consider using a separate supply. Likewise, the Motors draw 200mA (each), and can stall at up to 3A.

Code

The program code can be imported from here:

Import programESP8266_pid_redbot_webserver

WiFi Webserver Robot with PID Motor Control

Webpage and microSD Card

The webpage is loaded into the mBed from the microSD card. You will need to copy and paste the webpage HTML text into a HTML file and save to the SD card with the given file name.

Information

The HTML text can be found in the project's "main.cpp" file. Simply copy and paste the HTML text, line 656 through 683, to a HTML file named "pid_bot.html" and save to your micorSD card.

PID Control

This project uses motor shaft encoders to provide feedback to a PID controller to set the speed to the given setpoint.

Introduction/Overview of PID Controls

Proportional, Integral, Derivative (PID) Control is one of the most common control schemes used in industry. Arguably, the greatest feature of PID control is its robustness. This robustness arises form the fact that the controller does not have to have a completely accurate plant model, in fact we can know little about the plant and tune the controller to the plant through trial and error. For an introduction to PID see Brian Douglas's Introduction to PID https://www.youtube.com/watch?v=UR0hOmjaHp0 and also Brian's PID Example's https://www.youtube.com/watch?v=XfAt6hNV8XM

Tuning PID Controller

Many papers and methods have been developed on the topic of PID tuning. There is no perfect method for tuning that has yet been developed, and tuning remains largely empirical. A quick web search on the topic will produce many results on the subject, simple to advanced. For quick and dirty approach the steps below can be followed:

  • Set all gains to zero
  • Increase the Proportional gain at small increments until suitable rise time is achieved with little oscillations (acceptable overshoot is application dependent).
  • Once the Proportional gain is set apply the same approach to the Integral gain. The Integral gain should be selected such it eliminates small errors that cannot be overcome by the Proportional gain. The Integral gain should be such that it does not introduce undamped oscillations and maintains steady- state tracking.
  • Lastly, once the Proportional and Integral gains are selected, use the same approach to select the Derivative gain. The Derivative gain seeks to damp overshoot and oscillations to reach steady- state tracking more quickly.

Information

It is not always necessary to use all three gains. Often a PI or PD controller will suite the application. Experiment with different gain values and combinations. A great MatLab Tutorial on PID and the effects of each term can be found here: http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=ControlPID

About the Code

The PID controller code is based on Brett Beaugard's Arduino PID Library. An in depth explanation of the PID code development can be found here: http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/

Networking

Warning

This project was developed using Firefox 42.0. Google Chrome and Microsoft Explorer where found to NOT play well with this program... so it is HIGHLY suggested to use Firefox as your webclient platform.

About the Code

The webserver code is based on the project here: https://developer.mbed.org/users/4180_1/notebook/using-the-esp8266-with-the-mbed-lpc1768/. Two methods in this new project handle receiving and parsing user input and updating the webpage, these are "parseInput()" and "updateWebpage()". These two methods are custom to the webpage. Should you desire to change the webpage at all, i.e. add new user input/output blocks, you will need to modify these methods.The code is well commented and serves as a template.

Information

Use the listed web link above to read about configuring your ESP8266 to connect with your router or hotspot. The configuration code for you ESP8266 and demo mBed webserver program are included in the link.

Information

HTML User input data is received by the mBed in a string generated by a "POST" request. When adding new inputs in HTML ensure the new input has a "name" attribute. The "POST" request only includes data from inputs a name. This string can be seen in a serial terminal program following "+IPD...", where "+IPD" is appended by the ESP8266 to indicate it is received data.

Results

Open- Loop Control

When in open- loop mode the PID controllers are turned off and no feedback is used in setting speed of the motor. Because no two motors are exactly the same one may turn at a different rate, even with the same applied voltage/ PWM Duty Cycle. This causes the robot to travel in a curve path.

Closed- Loop Control with PID

By using PID control and matching the setpoints of each motor, feedback is used by the PID controllers which command the output to the setpoint. By doing this we can match the speeds of both motors resulting in straight line travel.


Please log in to post comments.