Go to Post It's super-ironic that a question about searching was found via searching. Whodathunk? - Brandon Martus [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 17-01-2011, 09:34
JewishDan18's Avatar
JewishDan18 JewishDan18 is offline
Registered User
FRC #1700
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Sunnyvale, CA
Posts: 185
JewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to behold
PID Speed Control

I was looking to use encoders to control the speed on the motors via a PID loop this year. I've done a lot of searching, and have not found the answers I'm looking for. I have no experience using PID loops, so bear with me for a moment.

Using the WPILib PIDController, I made a wrapper for the encoder to get speed, but I'm a little confused about the output. If I use the Jaguar for the output, it seems to me that as the robot approaches my desired speed, the motors will slow down (since error will approach zero). To me, it seems that the output of the PIDController should be used as the acceleration of the motor. Is this what is commonly done? It seems to me that the Jaguars are capable of an extremely high acceleration rate, which will lead to high levels of oscillation. Does one combat this by setting the constants to be quite small? Or is my premise of using acceleration fundamentally flawed? I'd like to get input from someone who has done this before, as there is no one on my team who has.

Thanks in advance,
Dan
Reply With Quote
  #2   Spotlight this post!  
Unread 17-01-2011, 09:47
Jared Russell's Avatar
Jared Russell Jared Russell is online now
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: PID Speed Control

Your intuition is correct: If speed is your source of error and Jaguar PWM is your output, then your proportional term will become 0 once you hit the setpoint.

Here is a great thread on this topic from a couple of years ago: http://www.chiefdelphi.com/forums/sh...&highlight=PID

The short answer: You need to accumulate your output over time and use that instead. In essense, yes, you are controlling motor acceleration (just as in a position loop, you are controlling motor velocity).

What you have now:
Jaguar_PWM = Kp*error + Kd*error_derivative + Ki*error_sum

What fixes the problem:
Jaguar_PWM += Kp*error + Kd*error_derivative + Ki*error_sum
Reply With Quote
  #3   Spotlight this post!  
Unread 17-01-2011, 10:26
JewishDan18's Avatar
JewishDan18 JewishDan18 is offline
Registered User
FRC #1700
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Sunnyvale, CA
Posts: 185
JewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to behold
Re: PID Speed Control

Thanks. That thread is exactly what I was looking for. The last poster had some of the same concerns as me (lag when setting speed and the oscillating around the set point).

I'm hoping that we can get the CAN issues worked out, we can use the built in functionality. If not, I'll tinker with acceleration control, and if that fails, I think I'll do something similar to what Alan did, and set a distance target ahead of the robot proportional to the speed I want to go.

Thanks again!
Reply With Quote
  #4   Spotlight this post!  
Unread 17-01-2011, 11:56
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,077
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID Speed Control

Quote:
Originally Posted by JewishDan18 View Post
I was looking to use encoders to control the speed on the motors via a PID loop this year. I've done a lot of searching, and have not found the answers I'm looking for. I have no experience using PID loops, so bear with me for a moment.

Using the WPILib PIDController, I made a wrapper for the encoder to get speed, but I'm a little confused about the output. If I use the Jaguar for the output, it seems to me that as the robot approaches my desired speed, the motors will slow down (since error will approach zero).
Yes, the motors slow down, but... they slow down to the "desired speed" (not to zero).

Think of it this way: a PID tries to drive the error to zero. Since your error is a "speed error", when the error is zero, it means your actual speed (measured by the encoder) is equal to your "desired speed" (the command you are sending).

If you use only the "P" term of the PID, you will always have a small speed error. That's where the "I" term comes in. The "I" term causes the PID to keep slowly bumping up (or down) the speed as long as the speed error is non-zero.

The "P" term gives you dynamic response, the "I" term gives you steady-state accuracy.




Last edited by Ether : 17-01-2011 at 12:02.
Reply With Quote
  #5   Spotlight this post!  
Unread 17-01-2011, 17:07
JewishDan18's Avatar
JewishDan18 JewishDan18 is offline
Registered User
FRC #1700
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Sunnyvale, CA
Posts: 185
JewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to behold
Re: PID Speed Control

So as the proportional error drops, the integral error picks up for it? That makes sense.
Reply With Quote
  #6   Spotlight this post!  
Unread 17-01-2011, 18:22
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,077
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID Speed Control

Quote:
Originally Posted by JewishDan18 View Post
So as the proportional error drops, the integral error picks up for it? That makes sense.
You could look at it that way.

The proportional part responds immediately and aggressively to large errors, but is satisfied once the error is "sufficiently small"*. The integral part makes relatively slow corrections, even to large errors, but doesn't give up until the error is essentially zero.


*how small is "sufficiently small" depends on how high you have the gain turned up for P.



Last edited by Ether : 17-01-2011 at 18:26.
Reply With Quote
  #7   Spotlight this post!  
Unread 18-01-2011, 09:19
BradAMiller BradAMiller is online now
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 590
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: PID Speed Control

Quote:
Originally Posted by JewishDan18 View Post
I'm hoping that we can get the CAN issues worked out, we can use the built in functionality. If not, I'll tinker with acceleration control, and if that fails, I think I'll do something similar to what Alan did, and set a distance target ahead of the robot proportional to the speed I want to go.
A new release of Java was just published last night that includes very improved CAN Jaguar classes. Give it a try, should work much better.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
  #8   Spotlight this post!  
Unread 20-01-2011, 22:11
JewishDan18's Avatar
JewishDan18 JewishDan18 is offline
Registered User
FRC #1700
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Sunnyvale, CA
Posts: 185
JewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to behold
Re: PID Speed Control

Awesome, I updated my plugins and got all control methods working except the speed control I'll keep working with the encoder to make sure it is working properly.
Reply With Quote
  #9   Spotlight this post!  
Unread 21-01-2011, 15:55
buildmaster5000 buildmaster5000 is offline
Trying to program the swerve drive
AKA: Alex
FRC #2421 (Rolling Thunder Robotics)
Team Role: Alumni
 
Join Date: May 2009
Rookie Year: 2009
Location: Northern Virginia
Posts: 207
buildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud ofbuildmaster5000 has much to be proud of
Re: PID Speed Control

Quote:
Originally Posted by BradAMiller View Post
A new release of Java was just published last night that includes very improved CAN Jaguar classes. Give it a try, should work much better.
Unfortunatly, using the PID control of the Jaguars was ruled illegal by Q&A.
Quote:
Originally Posted by http://forums.usfirst.org/showthread.php?t=16140
There is no rule that prohibits the Jaguars from reading the values from the encoders, however note that Rule R49 requires that the ROBOT must be controlled by the cRIO. In other words, commands may not originate in the Jaguar or any other controller, they must originate in the cRIO.
As my team was going to attempt a similar setup, would someone mind explaining how to setup closed loop speed control (I am really a mechanical guy who has inherited part of programming this year as the main programming student deemed swerve "too hard"). We are using java and have a operating chassis for the swerve. Currently the software "works" as designed but there are different speeds for each wheel, even when the PWM output is the same to each wheel.
__________________
-Alex



2010 Washington DC Regional: Engineering Excellence Award
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 22:18.

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