Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Logging 4 PID Tuning

Similar presentations


Presentation on theme: "Data Logging 4 PID Tuning"— Presentation transcript:

1 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 In this session I want to talk about the value of logging data from your robot.

2 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.

3 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.

4 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.

5 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.

6 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.

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

8 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)

9 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.

10 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.

11 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.

12 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)

13 Data Transfer Batch File
# GetLogging.bat file cd C:\FIRSTrobotics\RA14_LogFileArchive\2014_HomeComing ftp -A -s:ftpcmds.txt 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

14 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.

15 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.

16 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.

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

18 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.

19 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.

20 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.

21 ??? 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)

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

23 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)

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

25 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 csv

26 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

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

28 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.

29 Using Config function to initialize PID values

30 Reset code to reload new PID values

31 Config File Example

32 FTP Transfer System

33 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?

34 PID Tuning Strategies Iteration by experience
Ziegler-Nichols and other tuning strategies Several are mentioned on Chief Delphi PID without a PhD by Tim Wescott

35 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

36 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.

37 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.

38 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

39 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.

40 Ziegler-Nichols

41 Ziegler-Nichols & Others – Links
1. Ziegler-Nichols Method 2. Tyreus-Luyben Tuning 3. Comparison of PID Controller Tuning Methods by Mohammad Shahrokhi and Alireza Zomorrodi

42 Questions? Are there any questions regarding tuning methods?

43 Steering System Example
Position control for an Ackermann steering mechanism Servo style motor control Joystick position translates to steer angle

44 Ackermann Steering Example

45 Ackermann Steering Example

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

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

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

49 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

50 De Vinci Cam Red Alert Cam

51 De Vinci Cam

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

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

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

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

56 Nearing Final Solution
logging-Mon csv # CAM PID cam_p = 0.017 cam_i = cam_d = 0.00

57 Wind Up Detail

58 Launch Detail

59 Sequence of Several Launches

60 Speed Control for Frisbee Launcher Example
Velocity control for drive wheels

61 Frisbee Launcher

62

63 Drive Base Example Mecanum Drive

64 Drive Wheel PID Tuning

65 Drive Wheel PID Tuning

66 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

67 Questions Any questions?

68 Contact Information Find this presentation at Hugh Meyer Phone:


Download ppt "Data Logging 4 PID Tuning"

Similar presentations


Ads by Google