Data Logging 4 PID Tuning

Slides:



Advertisements
Similar presentations
Unit 4 The Performance of Second Order System Open Loop & Close Loop Open Loop: Close Loop:
Advertisements

PID Control for Embedded Systems
PID Controllers and PID tuning
© 2002 QxDesign, Inc. Building a PI controller This unit discusses Installation of Visual ModelQ The Visual ModelQ default model Placing and configuring.
Operating the Harmonizer
Chapter 4: Basic Properties of Feedback
Add and Use a Sensor & Autonomous For FIRST Robotics
1. 2 LabVIEW for FRC Doug Norman National Instruments January 6, 2012.
PID Control -1 + Professor Walter W. Olson
Loop Shaping Professor Walter W. Olson
Using the NXT Light Sensor. 2 Connect One Light Sensor – 1 From My Files use Left / Right NXT buttons and get to View menu and push Orange button. From.
Calendar Browser is a groupware used for booking all kinds of resources within an organization. Calendar Browser is installed on a file server and in a.
Introduction to Control: How Its Done In Robotics R. Lindeke, Ph. D. ME 4135.
FRC LabVIEW Software Overview Joe Hershberger Staff Software Engineer National Instruments.
Copyright 2003, Paradigm Publishing Inc. CHAPTER 6 BACKNEXTEND 6-1 LINKS TO OBJECTIVES Create and Rename a Folder Create and Rename a Folder Delete Workbooks.
ECE 4951 Lecture 5: PID Control of Processes. PID Control A closed loop (feedback) control system, generally with Single Input-Single Output (SISO) A.
Navigation, Path finding, and Maze Encoding MICROMOUSE ALGORITHMS.
Process Control Instrumentation II
CHE 185 – PROCESS CONTROL AND DYNAMICS CONTROL LOOP ANALYSIS.
Lecture 7: PID Tuning.
بسم الله الرحمن الرحيم PID Controllers
DEMONSTRATION FOR SIGMA DATA ACQUISITION MODULES Tempatron Ltd Data Measurements Division Darwin Close Reading RG2 0TB UK T : +44 (0) F :
ESM Interface Re-Design HCI Undergraduate Project Team Bei Yang Derek Parham Wenyao Ho.
Ch. 6 Single Variable Control
Programming Concepts (Part B) ENGR 10 Introduction to Engineering 1 Hsu/Youssefi.
Robot Sensors Kevin Watson and Rich Petras. Overview ➲ Sensors ● Micro Switch ● Gyro ● Encoders ➲ Command Sequencing ➲ PID Control.
Agenda Path smoothing PID Graph slam.
FRC Robot Framework Labview Made Easy (er) For FIRST Robotics 1.
1 Quality Center 10.0 NOTE: Uninstall the current version of QC before downloading QC All QC 10.0 documents can be located on the BI Shared Services.
Module 10: Monitoring ISA Server Overview Monitoring Overview Configuring Alerts Configuring Session Monitoring Configuring Logging Configuring.
CS 478: Microcontroller Systems University of Wisconsin-Eau Claire Dan Ernst Feedback Control.
Lab 8 Hints. Activity3: Clapping hand near open tube These slides indicate how to set up LoggerPro to “trigger” when you clap your hand.
Model Reference Adaptive Control (MRAC). MRAS The Model-Reference Adaptive system (MRAS) was originally proposed to solve a problem in which the performance.
FRC Robot Programming 1.PID Continued 2.Downloading and Deploying Code 3.Program a 2012 Robot from Spec Basic code For FIRST Robotics.
PID Controller Design and
1 Software Reliability Analysis Tools Joel Henry, Ph.D. University of Montana.
IVR 30/10/2009 Herrmann1 IVR: Control Theory Overview: PID control Steady-state error and the integral method Overshoot and ringing in system with time.
Control systems KON-C2004 Mechatronics Basics Tapio Lantela, Nov 5th, 2015.
Lecture 25: Implementation Complicating factors Control design without a model Implementation of control algorithms ME 431, Lecture 25.
Swerve Drive Software Design. Software Layers Joystick Axis Correction Joystick Response Calculation Field-oriented Angle Adjustment Swerve Drive Steer.
Session 11 Intro to FRC API.
Subsea Control and Communications Systems
Control 3 Keypoints: PID control
Get your software working before putting it on the robot!
1 Logging into the new PCard (PaymentNet) System: PAYMENTNET * Introduction * May use IE 8.0 or greater or Firefox * Do not.
Integrated Hands-On Mechanical System Laboratories Arif Sirinterlikci, Ph.D., Professor of Engineering Tony Kerzmann, Ph.D., Assistant Professor of Mechanical.
SKEE 3143 Control Systems Design Chapter 2 – PID Controllers Design
ABE425 Engineering Measurement Systems ABE425 Engineering Measurement Systems PID Control Dr. Tony E. Grift Dept. of Agricultural & Biological Engineering.
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
EEN-E1040 Measurement and Control of Energy Systems Control I: Control, processes, PID controllers and PID tuning Nov 3rd 2016 If not marked otherwise,
PID Control for Embedded Systems
Salman Bin Abdulaziz University
PID Controllers Jordan smallwood.
Prepared by: Ibrahim Yasin Ibrahim Abdulhaq
T_C_N_L_G_ E D I D I E O Y O H I E B J I R E A A W.
Control Loops Nick Schatz FRC 3184.
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Balanduino Supervisor: Dr. Raed Al-Qadi Prepared by: Nadeen Kalboneh Nardeen Mabrouk.
Basic Design of PID Controller
Interactive Basic Tuning for the SERVOSTAR 600
Systems Design Nursebot
Motors and Position Determination
Dynamical Systems Basics
frclabviewtutorials.com/workshop
Advanced LabVIEW
Advanced LabViEW
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
A Tutorial Overview Proportional Integral Derivative.
PID Line Follower.
Presentation transcript:

Data Logging 4 PID Tuning By Hugh Meyer Red Alert Robotics FRC Team 1741 Center Grove High School Greenwood Indiana October 24, 2015 Welcome to the Data Logging 4 PID Tuning workshop. My name is Hugh Meyer. I am one of the programming and electronics mentors for Red Alert Robotics FRC Team 1741. In this session I want to talk about the value of logging data from your robot.

Compelling Reasons for Data Logging Capture fast events Thoughtful evaluation process Verify repeatability There are several good reasons to log data. The best example I have seen is when NASA launches a spaceship and crashes it into a planet. It's a fast event and when it is all over all you have left is the data. Many times we are working with mechanisms that operate very quick and it is hard to tell exactly what is happening. By logging data we can review what happened in a more precise way. We can also take some time to evaluate carefully if the sequence of operation is exactly doing what we designed it to do. Repeatability is another aspect that is important. If you want to consistently put the game piece in the goal you need to know your system does the same thing each cycle. Logging can help to verify this and often will expose issues.

Compelling Reasons for Data Logging Establish normal operating range Detect leading edge of failure before disaster Verify design target Establishing normal operating ranges can be very helpful. For example if you determine that normal operating range for the current draw of the drive base is 20 amps per motor then you can verify this parameter stays in range. If after a few competitions you see that the motors are drawing 35 amps this would be flag to warn you that something is wrong. This can be a sort of “advance warning” that trouble is just ahead. This can help you find a problem before it is a disaster. Logging can help you to determine if your system is operating within design targets. By logging the current draw on a motor you can see if it is excessive. For instance if you have a shooter or launcher were the motor is drawing 85 amps you may want to consider gearing it differently to reduce that to a safer range.

My favorite example is from a few years ago when we implemented a telescoping mechanism. It started acting up and everyone was blaming the programmers. We had lots of data showing the max current draw of that system was 25 amps. We simply showed everyone that when it was failing to operate it was drawing around 50 amps. This quickly pointed to a mechanical jamming situation and the problem was addressed.

Different Approaches for Logging Data Use built in logging feature of the driver station. Located on the “Charts” tab Click “Launch Viewer” button for more detail Windows on the left indicate the file and location of the data files The driver station has built in logging. Look for the tab labeled charts.

Driver Station Charts Charts tab give a continuous display of many useful attributes If you click on the “Launch Viewer” button it opens the Log File Viewer This display shows in real time several different values. You can see the batter voltage, the CPU utilization, and some other information. If you click the “Launch Viewer” button the Log File Viewer dialog box will open.

Log File Viewer This gives more information and allows you to manage the log files. You can review past logs.

Different Approaches for Logging Data The supplied Driver Station Log File Viewer is helpful, but you really need data that is specific to your robot to be helpful I suggest you create your own logging system You have several options ( Read the slide)

Different Approaches for Logging Data Save the data on the driver station computer Save the data on the RoboRIO Save the data on an external memory card Save the data on an external computer Where you save the data determines your main approach to logging data. You can save the data on the driver station computer, the RoboRIO, an external memory card, or an external computer. We have done all of these. Currently we save the data on the RoboRIO and this seems to work well.

What you need for saving data on the RoboRIO Code that reads the data Writes the data to disk Move data from RoboRIO to processing system To save data to the RoboRIO you need code that reads the data and writes it to disk. Then you need a way to move the data to the computer you will be using to evaluate and archive the data.

Code to open log file and write data There are three components to the code. The routine to open and write the data is very simple. This examples shows how to do that. If the file is not open, then open it. Otherwise just go ahead and write the data out to the file. Notice we are outputting a line of headers at the same time we open the file. This helps to keep track of what the data means. The TeleopPeriodic section just calls the WriteToLogFile routine. Then when going back into disable mode we go ahead and flush the buffer and close the file.

Moving Data from the RoboRIO Use FTP to transfer the file back to the driver station after the match is concluded We create a batch file that does this This batch file is in the same folder destination where the data is to go The batch file renames the file to include the date and time in the file name (Read the slide)

Data Transfer Batch File # GetLogging.bat file cd C:\FIRSTrobotics\RA14_LogFileArchive\2014_HomeComing ftp -A -s:ftpcmds.txt 10.17.44.2 for /f "tokens=1-3 delims=/- " %%a in ('date /t') do set XDate=%%a-%%b-%%c for /f "tokens=1-2 delims=: " %%a in ('time /t') do set XTime=%%a.%%b rename "config.txt" "config-%XDate%-%XTime%.txt" rename "logging.csv" "logging-%XDate%-%XTime%.csv" The batch file controls the FTP process that moves the data from the RoboRIO to the target. Notice that you will need to update the file to include where the data is located and the IP address of the destination computer. After the data is moved it renames the file to include the time and date in the name. The txt file contains the the details FTP commands. # ftpcmds.txt file get logging.csv get config.txt bye

Data Folder Example This screen shot of the final data folder shows how the files get renamed. It also shows the batch file and the ftp command file. The .csv file is the data from the robot. The .txt file is the configuration file from the robot. By having both the data and configuration files we can know exactly how the robot was configured when the data file was logged.

Analyzing the Data Import into a spread sheet program Create specialized evaluation program Moving data from capture device to evaluation device Archiving data into a subversion repository The next step to analyzing the data is to import it into some kind of program, either a spread sheet program or some specialize one that you create. We usually just us OpenOffice Calc or Excel.

The Data File an Example The data is just a simple ascii text file that looks like this. The header record followed by the numbers.

Open Data in OpenOffice Calc To open the file in OpenOffice Calc, just right click and select ope with OppenOffice Calc.

Text Import to OpenOffice Calc A text import dialog box will open and in most cases just take the defaults. Look at the sample window to verify that the data is parsed correctly into the individual fields.

Once the data is imported you use the chart wizard to create a graph Once the data is imported you use the chart wizard to create a graph. Select the line type and chart type then finish and you should get a nice chart.

Like this. On this chart the blue line is the set point commanded by the user from the joystick. The red line is what the mechanism is doing. The end of travel is plus or minus 6.5, so you can see that the system is oscillating over the full range of motion. The yellow line is the command going to the speed controller. This is NOT what you want to see for a PID position controlled system. By the end of this session you will see what it should look like.

??? Questions ??? These are the steps to getting the data from the robot to a graph. Are there any questions about this process before we move on? (Read the slide)

PID Tuning Process Need method to command a step response Easy ability to change PID gain values (Summarize the slide)

Step Response One must be able to command an immediate change to a different value This should be done in a very controlled and precise manner Essentially the command to the system should be a few cycles of square wave This can be as simple as a button for the user to press, or as complex as an automation sequence (Read the slide)

Step Response We usually just add a button for testing and have the user command the change (Read the slide)

The blue line is the commanded input signal The blue line is the commanded input signal. You can see that it is a square wave. It is commanding about 50% movement. This is important because you don't want to saturate the system. Do not command a full scale move. In this system the full range of motion is plus and minus 6.5. Notice the red line is the actual motion. As you can see the system is not responding very good, but it is better than the earlier graph I showed where it was oscillating full range. logging-Thu-09-18-09.12.csv

Easy Method to change PID gain values Setup a configuration file on the RoboRIO Include in that configuration file the 3 gain values Develop a simple procedure to apply a changed configuration file to the system

Configuration Code Config.h Config.cpp config.txt putconfig.bat ftpcmds.txt These are the files that comprise our configuration mode.

Config File Initialization void Tshirt::RobotInit() { //Start robot cout << "Starting up..." << endl; cout<<"Loading Config File..... "<<endl; Config::LoadFromFile("config.txt"); cout<<"Done!"<<endl; Some where in the initialization code you will need to load the configuration file.

Using Config function to initialize PID values

Reset code to reload new PID values

Config File Example

FTP Transfer System

Questions We now have in place all we need to be able to easily change the PID gain variables Are there any questions at this point?

PID Tuning Strategies Iteration by experience Ziegler-Nichols and other tuning strategies Several are mentioned on Chief Delphi http://www.chiefdelphi.com/forums/portal.php PID without a PhD by Tim Wescott

Iteration by Experience After doing this for a while you will get to recognize different patterns and what will correct them P will make slower oscillations D will make fast high frequency oscillations I helps reach the target Not very scientific Can take really long time to find a solution

Start with P Tuning Process For small, low torque motors with little or no gearing, one procedure you can use to get a good baseline tune is to probe it’s response to a disturbance. To tune a PID use the following steps: 1. Set all gains to zero. 2. Increase the P gain until the response to a disturbance is a steady oscillation. 3. Increase the D gain until the oscillations go away (i.e. it’s critically damped). 4. Repeat steps 2 and 3 until increasing the D gain does not stop the oscillations. 5. Set P and D to the last stable values. 6. Increase the I gain until it brings you to the set point with the number of oscillations desired (normally zero but a quicker response can be had if you don’t mind a couple oscillations of overshoot) What disturbance you use depends on the mechanism the control is attached to. Normally moving the mechanism by hand away from the set point and letting go is enough. If the oscillations grow bigger and bigger then you need to reduce the P gain. If you set the D gain too high the system will begin to chatter (vibrate at a higher frequency than the P gain oscillations). If this happens, reduce the D gain until it stops.

Start with D Tuning Process To tune a PID use the following steps: 1. Set all gains to 0. 2. Increase Kd until the system oscillates. 3. Reduce Kd by a factor of 2-4. 4. Set Kp to about 1% of Kd. 5. Increase Kp until oscillations start. 6. Decrease Kp by a factor of 2-4. 7. Set Ki to about 1% of Kp. 8. Increase Ki until oscillations start. 9. Decrease Ki by a factor of 2-4.

Ziegler-Nichols & Other Tuning Strategies Set one of the variables to where the system just oscillates Measure the time period of the oscillation Calculate the PID values from some formula or look up table based on these measurements

Ziegler-Nichols The Ziegler–Nichols tuning method is a heuristic method of tuning a PID controller. It was developed by John G. Ziegler and Nathaniel B. Nichols. It is performed by setting the I (integral) and D (derivative) gains to zero. The "P" (proportional) gain, KP is then increased (from zero) until it reaches the ultimate gain KU , at which the output of the control loop oscillates with a constant amplitude. KU and the oscillation period TU are used to set the P, I, and D gains depending on the type of controller used. Use the table to determine the final gains.

Ziegler-Nichols

Ziegler-Nichols & Others – Links 1. Ziegler-Nichols Method http://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method 2. Tyreus-Luyben Tuning http://www.chem.mtu.edu/~tbco/cm416/zn.html 3. Comparison of PID Controller Tuning Methods by Mohammad Shahrokhi and Alireza Zomorrodi

Questions? Are there any questions regarding tuning methods?

Steering System Example Position control for an Ackermann steering mechanism http://en.wikipedia.org/wiki/Ackermann_steering_geometry Servo style motor control Joystick position translates to steer angle

Ackermann Steering Example

Ackermann Steering Example

First Pass at Tuning P = .125 I = .001 D = .00125

Second Pass at Tuning P = .220 I = .005 D = .320

Third Pass at Tuning P = .220 I = .005 D = .300

Launching Mechanism Example Position control for a Leonardo Da Vinci cam mechanism Reflective index sensor for homing each cycle Schmitt trigger (7414) for optical sensor http://www.digikey.com/product-detail/en/SN7414N/296-33604-5-ND/1575159 http://www.ti.com/lit/ds/symlink/sn7414.pdf

De Vinci Cam Red Alert Cam

De Vinci Cam

First Pass at Tuning logging-Wed-02-26-07.37.csv # CAM PID cam_p = .06 cam_i = .003 cam_d = .003

Next Pass at Tuning logging-Mon-02-24-08.13.csv # CAM PID cam_p = .75 cam_i = 0 cam_d = 0

Better But Still Oscillating logging-Mon-02-24-08.19.csv # CAM PID cam_p = .1 cam_i = 0 cam_d = 0

Another Pass Tuning logging-Mon-02-24-08.22.csv # CAM PID cam_p = .01 cam_i = 0 cam_d = 0

Nearing Final Solution logging-Mon-02-10-10.44.csv # CAM PID cam_p = 0.017 cam_i = 0.0005 cam_d = 0.00

Wind Up Detail

Launch Detail

Sequence of Several Launches

Speed Control for Frisbee Launcher Example Velocity control for drive wheels

Frisbee Launcher

Drive Base Example Mecanum Drive

Drive Wheel PID Tuning

Drive Wheel PID Tuning

Conclusion Log as much data as you can Build your code as modular as possible so you can reuse it Implement a config file for your robot Save your config file with the log data file

Questions Any questions?

Contact Information Find this presentation at http://hughmeyer.com/workshops Hugh Meyer Phone: 317 786-9214 Email: hmeyer@redalert1741.org