Go to Post It is a wise tutor/mentor who knows when to ask for help. - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 26-09-2016, 00:01
botster botster is offline
Registered User
no team
 
Join Date: Sep 2016
Location: San Jose
Posts: 7
botster is an unknown quantity at this point
Tuning PID Constants Over a Range

Our team is trying to impliment PID for autonomous driving/turning, however we are struggling on tuning the constants. We have been using 1114's suggested method of tuning kP, kD, then kI, and we have been successful for tuning a single value.

For example we can tune gyroTurn(5) to turn 5 degrees, but those constants don't work for gyroTurn(25). Are we doing something wrong? or are we supposed to create different sets of constants for ranges of the angle?
Reply With Quote
  #2   Spotlight this post!  
Unread 26-09-2016, 00:15
Jchau Jchau is offline
1414 - Programmer | Engineer
FRC #1414 (iHOT Robotics)
Team Role: Programmer
 
Join Date: Jun 2016
Rookie Year: 2015
Location: Atlanta, GA
Posts: 5
Jchau is an unknown quantity at this point
I am by no means an expert with PIDs, but in this I would suggest turn down the I constant. I ramps up over time, so with the greater degree of movement, it takes longer for the PID controller to get to the target value. Therefore, the I constant may get too high.

Sent from my SM-N920G using Tapatalk
Reply With Quote
  #3   Spotlight this post!  
Unread 26-09-2016, 00:27
Knufire Knufire is offline
Rose-Hulman Institute of Technology
no team
Team Role: College Student
 
Join Date: Sep 2009
Rookie Year: 2010
Location: Terre Haute, IN
Posts: 736
Knufire has a reputation beyond reputeKnufire has a reputation beyond reputeKnufire has a reputation beyond reputeKnufire has a reputation beyond reputeKnufire has a reputation beyond reputeKnufire has a reputation beyond reputeKnufire has a reputation beyond reputeKnufire has a reputation beyond reputeKnufire has a reputation beyond reputeKnufire has a reputation beyond reputeKnufire has a reputation beyond repute
Re: Tuning PID Constants Over a Range

Could you clarify what you mean by "didn't work"?

Was the response not fast enough or did it never reach the intended goal value?
__________________
Team 469: 2010 - 2013
Team 5188: 2014 - 2016
NAR (VEX U): 2014 - Present
Reply With Quote
  #4   Spotlight this post!  
Unread 26-09-2016, 00:33
Caleb Sykes's Avatar
Caleb Sykes Caleb Sykes is offline
Registered User
FRC #4536 (MinuteBots)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2009
Location: St. Paul, Minnesota
Posts: 1,042
Caleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond repute
Re: Tuning PID Constants Over a Range

Quote:
Originally Posted by botster View Post
Our team is trying to impliment PID for autonomous driving/turning, however we are struggling on tuning the constants. We have been using 1114's suggested method of tuning kP, kD, then kI, and we have been successful for tuning a single value.

For example we can tune gyroTurn(5) to turn 5 degrees, but those constants don't work for gyroTurn(25). Are we doing something wrong? or are we supposed to create different sets of constants for ranges of the angle?
Do you have a maximum velocity (or throttle) limitation in your code? If not, the constants used for 5 degree turns will likely cause substantial overshoot for 25 degree turns.
Reply With Quote
  #5   Spotlight this post!  
Unread 26-09-2016, 00:41
botster botster is offline
Registered User
no team
 
Join Date: Sep 2016
Location: San Jose
Posts: 7
botster is an unknown quantity at this point
Re: Tuning PID Constants Over a Range

Quote:
Originally Posted by Knufire View Post
Could you clarify what you mean by "didn't work"?

Was the response not fast enough or did it never reach the intended goal value?
If we tuned the turn for 5 degrees, then the robot would be too slow and never make it to 25 degrees. If we tune the turn for 25 degrees, the robot would overshoot the 5 degrees.
Reply With Quote
  #6   Spotlight this post!  
Unread 26-09-2016, 00:43
botster botster is offline
Registered User
no team
 
Join Date: Sep 2016
Location: San Jose
Posts: 7
botster is an unknown quantity at this point
Re: Tuning PID Constants Over a Range

We clip our motor power at 0.7, but this would not be slow enough for smaller angles and if we clip the power lower, the larger turns would be slower than desired.
Reply With Quote
  #7   Spotlight this post!  
Unread 26-09-2016, 07:22
adciv adciv is offline
One Eyed Man
FRC #0836 (RoboBees)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2010
Location: Southern Maryland
Posts: 478
adciv is a name known to alladciv is a name known to alladciv is a name known to alladciv is a name known to alladciv is a name known to alladciv is a name known to all
Re: Tuning PID Constants Over a Range

Quote:
Originally Posted by botster View Post
For example we can tune gyroTurn(5) to turn 5 degrees, but those constants don't work for gyroTurn(25). Are we doing something wrong? or are we supposed to create different sets of constants for ranges of the angle?
You aren't doing something wrong, its physics at work. Due to static friction small angle are hard while larger angles are easy. Somewhere between 5 and 10 degrees you change between the two. Basically, in order to start turning, your drive motors need to be above a certain value in order to overcome static friction. At that point, you're then only subject to dynamic friction. We typically tune our PIDs for large turning values and then if we need to make a small turn, turn away and then towards the desired angle.

This year, we ended up having different turning/yaw control PID values based on if we were moving forward or not.
__________________
Quote:
Originally Posted by texarkana View Post
I would not want the task of devising a system that 50,000 very smart people try to outwit.
Reply With Quote
  #8   Spotlight this post!  
Unread 26-09-2016, 08:26
Caleb Sykes's Avatar
Caleb Sykes Caleb Sykes is offline
Registered User
FRC #4536 (MinuteBots)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2009
Location: St. Paul, Minnesota
Posts: 1,042
Caleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond repute
Re: Tuning PID Constants Over a Range

Quote:
Originally Posted by botster View Post
We clip our motor power at 0.7, but this would not be slow enough for smaller angles and if we clip the power lower, the larger turns would be slower than desired.
How fast are you trying to go on the large turns? What are you trying to accomplish that requires such a quick response? If you are doing something extremely difficult like a 2-ball auto, PID will likely not be sufficient on its own, and you will need to create better control loops using things like motion profiling.

While we're at it, the following information would be helpful:
What type of drivetrain do you have?
How many/which drive motors power the drivetrain?
What is the minimum throttle value which allows the robot to turn in place?
What is the maximum achievable angular velocity of the robot?
Reply With Quote
  #9   Spotlight this post!  
Unread 26-09-2016, 10:56
Oblarg Oblarg is offline
Registered User
AKA: Eli Barnett
FRC #0449 (The Blair Robot Project)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Philadelphia, PA
Posts: 1,049
Oblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond repute
Re: Tuning PID Constants Over a Range

This is likely a static friction problem, and the easiest solution I've found to deal with it is to implement a "minimum output" parameter that roughly corresponds to the smallest motor voltage which will result in actual movement. Then, you change your PID response so that the magnitude of the output is never less than that value, e.g. you can just add the value (with the proper sign) to any output, or you can simply set any output that is too small to the minimum value (again, with the proper sign). I think the former behaves somewhat better, but both work.

You can also implement cascading control, where the output of your angle PID is fed to a velocity PID for the wheels instead of directly to the motors. Thus, the internal PID loop will account for the problem automatically (provided it is tuned correctly).

You also really should not need an I or D term for a turn-to-angle loop.
__________________
"Mmmmm, chain grease and aluminum shavings..."
"The breakfast of champions!"

Member, FRC Team 449: 2007-2010
Drive Mechanics Lead, FRC Team 449: 2009-2010
Alumnus/Technical Mentor, FRC Team 449: 2010-Present
Lead Technical Mentor, FRC Team 4464: 2012-2015
Technical Mentor, FRC Team 5830: 2015-2016

Last edited by Oblarg : 26-09-2016 at 11:00.
Reply With Quote
  #10   Spotlight this post!  
Unread 26-09-2016, 11:57
Rangel(kf7fdb)'s Avatar
Rangel(kf7fdb) Rangel(kf7fdb) is offline
John Rangel
FRC #0842 (Falcon Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Phoenix, AZ
Posts: 720
Rangel(kf7fdb) has a reputation beyond reputeRangel(kf7fdb) has a reputation beyond reputeRangel(kf7fdb) has a reputation beyond reputeRangel(kf7fdb) has a reputation beyond reputeRangel(kf7fdb) has a reputation beyond reputeRangel(kf7fdb) has a reputation beyond reputeRangel(kf7fdb) has a reputation beyond reputeRangel(kf7fdb) has a reputation beyond reputeRangel(kf7fdb) has a reputation beyond reputeRangel(kf7fdb) has a reputation beyond reputeRangel(kf7fdb) has a reputation beyond repute
Re: Tuning PID Constants Over a Range

Something that also helps in making small turns is to move forward slightly while turning to the set degree.
__________________
2011-2014 Arizona Regional Winners
2012 Dean's List Winner
2012-2013 Team President
2013 8th Place Robosub Competition
2014-? Mentor


Reply With Quote
  #11   Spotlight this post!  
Unread 27-09-2016, 02:58
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 800
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Tuning PID Constants Over a Range

Quote:
Originally Posted by Oblarg View Post
This is likely a static friction problem, and the easiest solution I've found to deal with it is to implement a "minimum output" parameter that roughly corresponds to the smallest motor voltage which will result in actual movement. Then, you change your PID response so that the magnitude of the output is never less than that value, e.g. you can just add the value (with the proper sign) to any output, or you can simply set any output that is too small to the minimum value (again, with the proper sign). I think the former behaves somewhat better, but both work.

You can also implement cascading control, where the output of your angle PID is fed to a velocity PID for the wheels instead of directly to the motors. Thus, the internal PID loop will account for the problem automatically (provided it is tuned correctly).

You also really should not need an I or D term for a turn-to-angle loop.
I've found the opposite. I and D are quite important for pneumatic tires on carpet. We added the equivalent of I this year, and have found that D has been crucial for years to get smooth fast performance.

I don't think you need to go to cascading control here. That sounds more complicated than needed. We run statespace controllers, but the only real difference between a SS controller and a PID loop is the improved filtering on the velocity term. Our heading controller works very well.


The first thing I tell people who ask me about tuning controllers like this is to start plotting things. With time as the X axis, plot left power, right power, right - left position, and gyro heading. You'll learn a lot from those plots. Feel free to post them as well if you want some more feedback.

Backlash in your drivetrain is also important. If you have too much backlash, you will hunt around the goal. A small move will stabilize because you don't get moving fast enough to need to flip to the other side of the backlash in order to slow down.

What frequency are you running your control loops at? Are you using the WPILib PID loop or your own? Too slow a loop time, or running the controller in the joystick code can cause a lot of problems.

Consider also adding in a motion profile. You can do a constant velocity profile, or try a trapezoidal profile. This will give your controller a bunch of small moves in a (more) feasible path which will be a lot easier to follow. We do trapezoidal motion profiles for all of our movements.

OP: From your profile, it looks like you are in the Bay Area. If the timing works out, 971 would be happy to chat in person with you guys, and take a look.
Reply With Quote
  #12   Spotlight this post!  
Unread 27-09-2016, 11:15
Oblarg Oblarg is offline
Registered User
AKA: Eli Barnett
FRC #0449 (The Blair Robot Project)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Philadelphia, PA
Posts: 1,049
Oblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond repute
Re: Tuning PID Constants Over a Range

Quote:
Originally Posted by AustinSchuh View Post
I've found the opposite. I and D are quite important for pneumatic tires on carpet. We added the equivalent of I this year, and have found that D has been crucial for years to get smooth fast performance.
We ran a cascading P loop last year, and it worked beautifully. It's really not any extra work (or complexity) to run cascading control if you're already using velocity control for your drive - you just output to the existing PID controller instead of to the motors.
__________________
"Mmmmm, chain grease and aluminum shavings..."
"The breakfast of champions!"

Member, FRC Team 449: 2007-2010
Drive Mechanics Lead, FRC Team 449: 2009-2010
Alumnus/Technical Mentor, FRC Team 449: 2010-Present
Lead Technical Mentor, FRC Team 4464: 2012-2015
Technical Mentor, FRC Team 5830: 2015-2016
Reply With Quote
  #13   Spotlight this post!  
Unread 27-09-2016, 14:17
Paul Copioli's Avatar Unsung FIRST Hero Woodie Flowers Award
Paul Copioli Paul Copioli is offline
President, VEX Robotics, Inc.
FRC #3310 (Black Hawk Robotics)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 2000
Location: Rockwall, TX
Posts: 1,382
Paul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond repute
Re: Tuning PID Constants Over a Range

Quote:
Originally Posted by Oblarg View Post
We ran a cascading P loop last year, and it worked beautifully. It's really not any extra work (or complexity) to run cascading control if you're already using velocity control for your drive - you just output to the existing PID controller instead of to the motors.
Eli,

While your statement is true, we have found that simply putting a motion profile on your input will eliminate the need for cascading control.

To me, the motion profile (whichever you choose .. we use trapezoidal acceleration) is a more pure way to do it. We all know that if you give a step input to a motor it really doesn't behave that way so why not give it an input it really can perform.

We have found that motion profile + feedforward gain + PID work for all of our telemetry navigation needs, whether it be for driving or moving a ridiculously complicated arm.

Austin and his crew use state space, but I am too simplistic for all that awesomeness so I stick with profile + FF + PID.

Paul
__________________
In full disclosure I am the President of VEX Robotics, a division of Innovation First International.
Reply With Quote
  #14   Spotlight this post!  
Unread 27-09-2016, 18:25
wesleyac's Avatar
wesleyac wesleyac is offline
Registered User
AKA: Wesley Aptekar-Cassels
FRC #1678
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Davis, CA
Posts: 45
wesleyac is a glorious beacon of lightwesleyac is a glorious beacon of lightwesleyac is a glorious beacon of lightwesleyac is a glorious beacon of lightwesleyac is a glorious beacon of light
Re: Tuning PID Constants Over a Range

I would agree that motion profiling + feed forward will help a lot. 254 and 971 did a great video on this at champs in 2015 (https://www.youtube.com/watch?v=8319J1BEHwM).

The process that we used for tuning our turning went something like this:

1.) Write and test motion profile code (graph it to make sure that it is actually doing what it is supposed to).
2.) Find motion profile parameters. We used trapezoidal motion.
2a.) You can find the maximum velocity by sending 12v to both motors and looking at the maximum slope of the line.
2b.) From the same plot of the velocity, you can run a regression to get the acceleration.
2c.) You should set you FF parameters to something slightly lower than the actual values - as the season wears on, your robot will get less efficient, and you don't want to ask your robot to follow a profile that it's incapable of following.
3.) Find FF parameters
3a.) You can use the dynamics of the system to calculate what these should be, but we found that for turning, they ended up being fairly inaccurate (probably wheel scrub + static friction were a lot of that. pneumatic wheels can be a pain ) We started with calculated values, and tuned them by hand until they largely matched the motion profile. Again, having plots of angle over time as well as target angle over time on the same axes helps hugely here. If you don't have some system to graph variables over time, make one! it will save time in the long run. Test every change with multiple values.
4.) Start tuning PID. There are many different strategies for this. The one that you are using looks fine. Test every change for a range of values (90deg, 25deg, 10deg, 5deg, 2deg, etc. This also applies to tuning the FF values.) Again, graph everything. You can very easily see the effects of changing PID parameters from the graphs.

Another thing to consider it when you want to terminate the loop. If you don't need to be very accurate (for example, in an initial turn before starting vision), then don't have strict termination conditions. Also, if you have problems with the robot continuing to turn after the profile is over, consider adding a minimum derivative as a termination condition.

If you have any questions, feel free to ask.
__________________
Quote:
Originally Posted by The programming team
Define "works."

Last edited by wesleyac : 27-09-2016 at 18:40. Reason: Pushed submit too early :o
Reply With Quote
  #15   Spotlight this post!  
Unread 27-09-2016, 22:29
Oblarg Oblarg is offline
Registered User
AKA: Eli Barnett
FRC #0449 (The Blair Robot Project)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Philadelphia, PA
Posts: 1,049
Oblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond reputeOblarg has a reputation beyond repute
Re: Tuning PID Constants Over a Range

Quote:
Originally Posted by Paul Copioli View Post
Eli,

While your statement is true, we have found that simply putting a motion profile on your input will eliminate the need for cascading control.

To me, the motion profile (whichever you choose .. we use trapezoidal acceleration) is a more pure way to do it. We all know that if you give a step input to a motor it really doesn't behave that way so why not give it an input it really can perform.

We have found that motion profile + feedforward gain + PID work for all of our telemetry navigation needs, whether it be for driving or moving a ridiculously complicated arm.

Austin and his crew use state space, but I am too simplistic for all that awesomeness so I stick with profile + FF + PID.

Paul
We're working on motion profiling this preseason - I entirely agree that it's a conceptually better way to do it.
__________________
"Mmmmm, chain grease and aluminum shavings..."
"The breakfast of champions!"

Member, FRC Team 449: 2007-2010
Drive Mechanics Lead, FRC Team 449: 2009-2010
Alumnus/Technical Mentor, FRC Team 449: 2010-Present
Lead Technical Mentor, FRC Team 4464: 2012-2015
Technical Mentor, FRC Team 5830: 2015-2016
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:35.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi