PID Controller application in robotics. Victor Abreu A /5/2013. Executive Summary:

Similar documents
Engineering 58-Control Theory and Design. Final Project-Ball Balancing Beam. Kyle Knapp, David Nahmias & Daniel Kowalyshyn

Robotics Adventure Book Scouter manual STEM 1

Part A: Monitoring the Rotational Sensors of the Motor

MS4SSA Robotics Module:

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

HUB-ee BMD-S Arduino Proto Shield V1.0

MICROMOUSE ALGORITHMS. Navigation, Path finding, and Maze Encoding

Program your face off

Experiment 4.A. Speed and Position Control. ECEN 2270 Electronics Design Laboratory 1

Deseo KNX Manual. Deseo KNX. Manual. basalte bvba hundelgemsesteenweg 1a 9820 merelbeke belgium. 1 / 65 v basalte

Making a One Degree Motor Arm with Potentiometer and PID

Lab 7: PID Control with Trajectory Following

Appendix C: HVAC PRO Modules

micromax R Getting Started Guide

Lab 1: Move the Mobile Robot Wheels: Motor Velocity Control 2.12: Introduction to Robotics Fall 2016

U90 Ladder Software Manual. Version 3.50, 6/03

ROS Interface with Low Level Control - Arduino

Procedure: Determine the polarity of the LED. Use the following image to help:

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

ARDUINO UNO R3 BASED 20A ROBOT CONTROL BOARD [RKI-1580] Page 1

APPLICATION NOTE /20/02 Getting started using IPM240-5E with a brushless motor

Lab 2.2 Ohm s Law and Introduction to Arduinos

GUIDE TO SP STARTER SHIELD (V3.0)

NXT Programming for Beginners Project 9: Automatic Sensor Calibration

EV3 Programming Workshop for FLL Coaches

Victor BB Comprehensive Guide Preliminary. Revision 1.3

HUB-ee BMD-S Arduino Proto Shield V1.1

Sensors and Motors Lab

APPLICATION NOTE IDM.101

Interrupts, timers and counters

BLD04A Brushless DC Motor Driver

Fall Harris & Harris

2G Actuator Communications Protocol Document Rotary & Linear Actuators

USER MANUAL ARDUINO I/O EXPANSION SHIELD

PDF of this portion of workshop notes:

keyestudio Keyestudio MEGA 2560 R3 Board

Build and Test Plan: IGV Team

ENGR101 T Engineering Technology. Arthur Roberts. School of Engineering and Computer Science Victoria University of Wellington

Closed Loop Step Response

IRF90 - Rotating Focuser

Quantum Phase Isochromatic Pluckeasy

Advanced Activities - Information and Ideas

Safety Instructions 1-1 Avoid unintended Start General Description 2-2

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

Arduino IDE Friday, 26 October 2018

Object 18 - PID. PID Summary

TB264 (Rev2) - Delta ASDA-A2 Precision Mode Setup With Optic Direct

COMP 161 Lecture Notes 16 Analyzing Search and Sort

Rover 5. Explorer kit

UM2119 User manual. Graphical user interface (GUI) for EVAL-L9907-H. Introduction

AndyMark Arduino Tutorial

General Description. The TETRIX MAX DC Motor Expansion Controller features the following:

NXShield Interface Specifications

TB267 (Rev4) - CNC11 Yaskawa Sigma5 Precision Mode Setup

21. PID control The theory of PID control

Arduino 101 AN INTRODUCTION TO ARDUINO BY WOMEN IN ENGINEERING FT T I NA A ND AW E S O ME ME NTO R S

Automation System TROVIS 5400 District Heating Controller TROVIS 5475

ExiGo Pump LabVIEW Manual

Arduino Programming and Interfacing

FIRE SENSOR ROBOT USING ATMEGA8L

If you note any errors, typos, etc. with this manual or our software libraries, let us know at

IME-100 ECE. Lab 4. Electrical and Computer Engineering Department Kettering University. G. Tewolde, IME100-ECE,

XX. User manual

A Simple Introduction to Omni Roller Robots (3rd April 2015)

Learning Recursion. Recursion [ Why is it important?] ~7 easy marks in Exam Paper. Step 1. Understand Code. Step 2. Understand Execution

MS4SSA Robotics Module:

APPLICATION NOTE

Advanced Debugging I. Equipment Required. Preliminary Discussion. Basic System Bring-up. Hardware Bring-up, Section Plan

Create moving images in forward and reverse with your Arduino when you connect a motor to an H-bridge and some still images BATTERY POTENTIOMETER

CONSTRUCTION GUIDE The pendulumrobot. Robobox. Level X

Introduction to Programming. Writing an Arduino Program

Prototyping & Engineering Electronics Kits Basic Kit Guide

SP 713 Slide Rule Practice for our MIT Museum visit By Alva Couch and Elizabeth Cavicchi

5.5 Completing the Square for the Vertex

SPARTAN ROBOTICS FRC 971

ConText "Control by Text"

Alessandra de Vitis. Arduino

The Beginners Guide to ROBOTC. Volume 2, 3 rd Edition Written by George Gillard Published: 18-July-2016

PID Control Application Guide

Colin Harman and Jonathan Kim

what is an algorithm? analysis of algorithms classic algorithm example: search

BLWS23MDCUSB Series. Programmable Brushless DC Motor Controller. User s Guide

ABSTRACT BACKGROUND PSIG 05B3

Din Rail 4 Output Module BO04A01KNX

Project Proposal Guide MATHWORKS TRACK Disclaimer:

University of Portland EE 271 Electrical Circuits Laboratory. Experiment: Arduino

Hot X: Algebra Exposed

Robotics 2c. The Programming Interface

contents Page 1 of 6 Field Programming Software User Guide Rev. A 10/16

SHOCKANALYZER V1.7 USER S MANUAL. Copyright 2012

EEL 5666C FALL Robot Name: DogBot. Author: Valerie Serluco. Date: December 08, Instructor(s): Dr. Arroyo. Dr. Schwartz. TA(s): Andrew Gray

R7426A TEMPERATURE CONTROLLER WITHOUT REAL-TIME CLOCK. MicroniK 200. Order Numbers

Chapter 1: Getting Started

Table of Contents 1. Overview Installation...6

Introduction to ARDUINO/SIMULINK

EVShield Interface Specifications

Date 18/05/17. Operation and maintenance instructions for driver configurator QSet

TETRIX PRIZM Robotics Controller Quick-Start Guide and Specifications

Plotting Points. By Francine Wolfe Professor Susan Rodger Duke University June 2010

Fundamentals of lambda tuning

Transcription:

PID Controller application in robotics Victor Abreu A42379353 4/5/2013 Executive Summary: The proportional integral derivative controller is a generic control loop feedback mechanism that is widely used in industrial control systems. This application note intends to demonstrate how to calculate a PID controller into a modern mobile robot. This will be done by use of sensors to gather the desired input and use that to create a feedback system enabling for creation of a more desired output. Introduction: A PID controller calculates an error value as the difference between a measured process variable and a desired set point. The controller attempts to minimize the error by adjusting the process control inputs. The PID controller calculation involves three separate constant parameters, and is accordingly sometimes called three- term control: the proportional, the integral and derivative values. P depends on the present error, I on the accumulation of the past errors, and D is a prediction of future errors. This is all based on current rate of change. The weighted sum of these three actions is used to adjust the process via a control element such as the position of a control valve, a damper, or the power supplied to a heating element. In the absence of knowledge of the underlying process, a PID controller has historically been considered to be the best controller. By tuning the three parameters in the PID controller algorithm, the controller can provide control action designed for specific process requirements. The response of the controller can be described in terms of the responsiveness of the controller to an error, the degree to which the controller overshoots the set point and the degree of system oscillation. Objetive: To create a PID controller using a wheel encoders input to create a control system for the robots movement. Hardware Needed: Wheel/Optical Encoder Arduino UNO Board https://www.sparkfun.com/products/9208 https://arduino.cc/en/main/arduinoboarduno

Mobile Robot Getting Started: Initially you have to set a Wheel/Optical Encoder in order to measure the speed of the mobile robot. This is done by mounting the encoder on the shaft of the rotating object. A light source (LED) and a light sensor (Phototransistor) are used with the wheel between them such that light from the LED falls on the phototransistor only when the hole in the wheel comes in between. With this you can measure one electrical pulse produced by the phototransistor for one revolution of the wheel. You can then count the pulses in a counter for a unit period of time like a second or a minute to get rotations per second or rotations per minute. Using this input you can begin to create a PID controller within the arduino microcontroller software. Installing Arduino Drivers: The software for the Arduino can be found in the IDE software from http://arduino.cc/en/main/software. The software must be downloaded to create a means of communication between the windows computer and the microprocessor. This will allow us to program the Arduino manually. First you must plug the board onto a USB port and wait for the windows to begin the driver installation process. If an error is displayed then the Arduino will need to be configured manually. From the PC click Start, Control Panel, and System & Security. Click on the tab System and open the Device Manager. In the Ports (COM) subtab right click on the port named Arduino UNO (COMxx), and choose Update Driver Software. Choose Browse my computer for Driver Software and navigate to the Uno driver file named ArduinoUno.inf in the Drivers folder from the Arduino IDE software that was downloaded. Setting up the Arduino IDE: Open the Sketch editor by opening the Arduino application. Sketch is where you apply your code and programming to the arduino board. Select the proper board by clicking tools, board, Arduino Uno. The serial ports the Arduino is using through its USB connection must be discovered. On the Arduino IDE, navigate to Tools, Serial Port. Disconnect the arduino board and re open the menu in order to discover what serial port the arduino is connected to. Whichever entry was previously selected that disappeared will be the correct serial port. Creating the PID Code:

/*working variables*/ double Input, Output, Setpoint; double errsum, lasterr; /*How long since we last calculated*/ double timechange = (double)(now - lasttime); errsum += (error * timechange); double derr = (error - lasterr) / timechange; Output = kp * error + ki * errsum + kd * derr; lasterr = error; lasttime = now; void SetTunings(double Kp, double Ki, double Kd) kp = Kp; ki = Ki; kd = Kd; Compute() is called either regularly or irregularly, and it works pretty well. To turn this into industrial PID controllers there are a few things that must be addressed. The sample time allows for the PID algorithm to function best if it is evaluated at a regular interval. The beginners PID is designed to be called irregularly and it keeps the PID with inconsistent behavior. Addiontionally the program will need to compute extra math in the derivative and integral. To fix this is to specify that the compute function gets called every cycle. This can be done in such a fashion. /*working variables*/ double Input, Output, Setpoint; double errsum, lasterr; int SampleTime = 1000; //1 sec int timechange = (now - lasttime); if(timechange>=sampletime)

errsum += error; double derr = (error - lasterr); Output = kp * error + ki * errsum + kd * derr; lasterr = error; lasttime = now; void SetTunings(double Kp, double Ki, double Kd) double SampleTimeInSec = ((double)sampletime)/1000; kp = Kp; ki = Ki * SampleTimeInSec; kd = Kd / SampleTimeInSec; void SetSampleTime(int NewSampleTime) if (NewSampleTime > 0) double ratio = (double)newsampletime / (double)sampletime; ki *= ratio; kd /= ratio; SampleTime = (unsigned long)newsampletime; Additionally you will have to add the Derivative kick in order to fix the problems associated with the derivative term. Since error=setpoint- Input any change in Setpoint causes an instantaneous change in errore. The derivative of this change is infinity. This number gets fed into the pid equation giving undesirable spikes in the output. To solve for this problem it turns out that the derivative of the Error is equal to negative derivative of input, except when the Setpoint is changing. This ends up being a perfect solution. Instead of adding, we subtract. Additional components in the code are inputted as follows /*working variables*/ double Input, Output, Setpoint; double errsum, lastinput; int SampleTime = 1000; //1 sec int timechange = (now - lasttime); if(timechange>=sampletime)

errsum += error; double dinput = (Input - lastinput); Output = kp * error + ki * errsum - kd * dinput; lastinput = Input Reset windup occurs when the PID thinks it can do something it can t. For example, the PWM output on an Arduino accepts values from 0-255. By default the PID doesn t know this. If it thinks that 300-400- 500 will work, its going to try those values expecting to get what it needs. The way to fix this is to actually tell the PID what the output limits are. In the code below you ll see theres now a SetOutputLimit function. Once either limit is reached, the pid stops summing (integrating.) It knows theres nothing to be done; since the output doesn t wind- up, we get an immediate response when the setpoint drops into a range where we can do something. void SetOutputLimits(double Min, double Max) if(min > Max) return; outmin = Min; outmax = Max; if(output > outmax) Output = outmax; else if(output < outmin) Output = outmin; if(iterm> outmax) ITerm= outmax; else if(iterm< outmin) ITerm= outmin; At some point in the program you want to force the output to a certain value so you could certainly do this in the calling routine. Void loop() Compute() Output=0 This way, no matter what the PID says, you will just overwrite its value. The way to fix this is to have a way to turn the PID off and on manually. Example code is displayed below /*working variables*/

double Input, Output, Setpoint; double ITerm, lastinput; int SampleTime = 1000; //1 sec double outmin, outmax; bool inauto = false; #define MANUAL 0 #define AUTOMATIC 1 if(!inauto) return; int timechange = (now - lasttime); if(timechange>=sampletime) ITerm+= (ki * error); if(iterm> outmax) ITerm= outmax; else if(iterm< outmin) ITerm= outmin; double dinput = (Input - lastinput); Output = kp * error + ITerm- kd * dinput; if(output > outmax) Output = outmax; else if(output < outmin) Output = outmin; lastinput = Input; lasttime = now; void SetMode(int Mode) inauto = (Mode == AUTOMATIC); In the last section we implemented the ability to turn the PID off and on. We turned it off, but now when you turn it back on the PID jumps back to the last output value it sent, then starts adjusting from there. This results in an input bump that we d rather not have. The solutiuon to this is to intitialize things for a smooth transition. That means massaging the 2 stored working variables (ITerm & lastinput) to keep the output from jumping. The example code is as follows. bool newauto = (Mode == AUTOMATIC); if(newauto &&!inauto) /*we just went from manual to auto*/ Initialize(); inauto = newauto;

void Initialize() lastinput = Input; ITerm = Output; if(iterm> outmax) ITerm= outmax; else if(iterm< outmin) ITerm= outmin; Now to create the PID controller to work in the reverse process the signs kp, ki, and kd all must be negative. To make the process a little simpler, it helps to require that kp, ki, and kd all be >=0. If the user is connected to a reverse process, they specify that separately using the SetControllerDirection function. This ensures that the parameters all have the same sign, and hopefully makes things more intuitive. Sample codes are as follows #define DIRECT 0 #define REVERSE 1 int controllerdirection = DIRECT; if (Kp<0 Ki<0 Kd<0) return; if(controllerdirection ==REVERSE) kp = (0 - kp); ki = (0 - ki); kd = (0 - kd); void SetControllerDirection(int Direction) controllerdirection = Direction; With this last addition the PID controller is complete. Now with this apply your inputs as the motor you would like to control in order to control its movement and the robot will become autonomous.