Go to Post Gatting your senior pic with robot = (Cool factor * infinity). :cool: - Elgin Clock [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 05-07-2016, 12:50
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 216
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Good way to bring shooter to exact speed?

Hi,

We recently decided to put an encoder on our shooter so that we can stop setting the shooter to a percentage of the battery power to an actual rpm. The problem we have now is how do we exactly program it to go to a certain rpm?

My best guess would be to use a PID loop and then limit the output to not include negative numbers so that the shooter doesn't suddenly change directions. We have tried just writing a linear equation like speed = distanceFromRPM * .01 +.4 but that usually didn't work well and the time it took to reach the desired RPM had a huge variation.

We just want a method that takes very little time to get up to the RPM and is consistent. Any ideas are appreciated and welcomed!
__________________
#Python4Life
Reply With Quote
  #2   Spotlight this post!  
Unread 05-07-2016, 12:57
ThaddeusMaximus's Avatar
ThaddeusMaximus ThaddeusMaximus is offline
Thaddeus Hughes
FRC #4213 (MetalCow Robotics)
Team Role: College Student
 
Join Date: Jan 2016
Rookie Year: 2012
Location: Shirley, IL
Posts: 72
ThaddeusMaximus is a jewel in the roughThaddeusMaximus is a jewel in the roughThaddeusMaximus is a jewel in the rough
Re: Good way to bring shooter to exact speed?

Quote:
Originally Posted by team-4480 View Post
Hi,

We recently decided to put an encoder on our shooter so that we can stop setting the shooter to a percentage of the battery power to an actual rpm. The problem we have now is how do we exactly program it to go to a certain rpm?

My best guess would be to use a PID loop and then limit the output to not include negative numbers so that the shooter doesn't suddenly change directions. We have tried just writing a linear equation like speed = distanceFromRPM * .01 +.4 but that usually didn't work well and the time it took to reach the desired RPM had a huge variation.

We just want a method that takes very little time to get up to the RPM and is consistent. Any ideas are appreciated and welcomed!
Take-Back-Half (TBH) control.
Reply With Quote
  #3   Spotlight this post!  
Unread 05-07-2016, 13:29
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 216
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: Good way to bring shooter to exact speed?

Quote:
Originally Posted by ThaddeusMaximus View Post
What do I start H0 with? Something low?
__________________
#Python4Life
Reply With Quote
  #4   Spotlight this post!  
Unread 05-07-2016, 13:37
ThaddeusMaximus's Avatar
ThaddeusMaximus ThaddeusMaximus is offline
Thaddeus Hughes
FRC #4213 (MetalCow Robotics)
Team Role: College Student
 
Join Date: Jan 2016
Rookie Year: 2012
Location: Shirley, IL
Posts: 72
ThaddeusMaximus is a jewel in the roughThaddeusMaximus is a jewel in the roughThaddeusMaximus is a jewel in the rough
Re: Good way to bring shooter to exact speed?

Quote:
Originally Posted by team-4480 View Post
What do I start H0 with? Something low?
I've a terrible memory. As a wise Shia LaBeouf said, "Just Do It": Make sure there's no safety hazards with the shooter running at full blast and try something

I could be wrong but with at 15000 PPR encoder and 5000 RPM, we were using a H0 somewhere in the thousands...
Reply With Quote
  #5   Spotlight this post!  
Unread 05-07-2016, 14:04
team-4480's Avatar
team-4480 team-4480 is offline
Debug? What's that?
FRC #4480
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Minnesooota
Posts: 216
team-4480 will become famous soon enoughteam-4480 will become famous soon enough
Re: Good way to bring shooter to exact speed?

Quote:
Originally Posted by ThaddeusMaximus View Post
I've a terrible memory. As a wise Shia LaBeouf said, "Just Do It": Make sure there's no safety hazards with the shooter running at full blast and try something

I could be wrong but with at 15000 PPR encoder and 5000 RPM, we were using a H0 somewhere in the thousands...
Is this generally how you would do it?
Code:
            #define self.last up top
            ....

            self.difference = 3200 - self.encoder.getRate() #3200 is the target RPM
            self.averageDiff = ((self.last + self.difference)/2)*.0000005 #Finds difference and averages then multiplies gain
            self.totalSpeed+=self.averageDiff #Adds it to the PWM speed
            self.last = self.difference #Gets ready for the next time
            self.speedShooter=self.totalSpeed #Sets the speed
__________________
#Python4Life
Reply With Quote
  #6   Spotlight this post!  
Unread 05-07-2016, 16:50
ratdude747's Avatar
ratdude747 ratdude747 is offline
Official Scorekeeper
AKA: Larry Bolan
no team
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Madison, IN
Posts: 1,063
ratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond repute
Re: Good way to bring shooter to exact speed?

I'd go for a PID. You'll need to convert the encoder count to a 0-1 range of speeds, but otherwise, if it's like it was back in the old days (2011), it's pretty easy to set up.

As for tuning said PID, there are various ways (google it, as I don't have my controls textbook handy). Whichever tuning technique you use, you'll want to get it so it has a quick response without breaking anything, blowing anything, or oscillating. I'd avoid over-tuning (getting it really, really spot on) as you're liable to become marginally stable (which puts you one bit of drift away from instability).

Yeah there is probably an easier FRC-specific way to do this, but this (minus the PID code) is what they do in industry and will likely produce the best results possible with your hardware. As many of us know, controls can be temperamental to tune, but when you get it right, it will deliver.
__________________
Dean's List Semi-finalist 2010
1747 Harrison Boiler Robotics 2008-2010, 2783 Engineers of Tomorrow 2011, Event Volunteer 2012-current

DISCLAIMER: Any opinions/comments posted are solely my personal opinion and does not reflect the views/opinions of FIRST, IndianaFIRST, or any other organization.
Reply With Quote
  #7   Spotlight this post!  
Unread 05-07-2016, 17:29
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,026
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: Good way to bring shooter to exact speed?



Talon SRX PIDF 1 2

TBH 1 2

Bang-Bang 1 2


Reply With Quote
  #8   Spotlight this post!  
Unread 05-07-2016, 17:42
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,185
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: Good way to bring shooter to exact speed?

Use the Talon SRX in speed control mode. The update rate and onboard filtering is better than anything you'll be able to get in code running on the crio.
Reply With Quote
  #9   Spotlight this post!  
Unread 05-07-2016, 18:38
thatprogrammer's Avatar
thatprogrammer thatprogrammer is offline
Registered User
AKA: Ahad Bawany
no team (None)
Team Role: Programmer
 
Join Date: Apr 2014
Rookie Year: 2014
Location: Florida
Posts: 609
thatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond repute
Re: Good way to bring shooter to exact speed?

Quote:
Originally Posted by Tom Bottiglieri View Post
Use the Talon SRX in speed control mode. The update rate and onboard filtering is better than anything you'll be able to get in code running on the crio.
What if he decides to use a roboRIO?
Also: Is there a way to use the roboRIO's PID class or make a custom PID class that can do speed control?*

*Could you just use a generic PID controller and use the following piece of code? (As ratdude747 implied)
Code:
if(Motor_Speed<0){
Motor_Speed = 0;
}
Reply With Quote
  #10   Spotlight this post!  
Unread 05-07-2016, 20:04
kiettyyyy's Avatar
kiettyyyy kiettyyyy is offline
Registered User
FRC #1538 (The Holy Cows)
Team Role: Engineer
 
Join Date: Mar 2006
Rookie Year: 2005
Location: San Diego, CA
Posts: 181
kiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond repute
Send a message via AIM to kiettyyyy
Re: Good way to bring shooter to exact speed?

Quote:
Originally Posted by thatprogrammer View Post
What if he decides to use a roboRIO?
Also: Is there a way to use the roboRIO's PID class or make a custom PID class that can do speed control?*

*Could you just use a generic PID controller and use the following piece of code? (As ratdude747 implied)
Code:
if(Motor_Speed<0){
Motor_Speed = 0;
}
That's what he meant. The SRX is extremely capable..
__________________
-Kiet Chau

2004-2008 - Software Developer/Driver on Team #968
2008-2011 - Software Developer/Coach/Mentor/"Engineer" on Team #968
2011-Present - Mentor & Engineer on Team #1538
www.team1538.com
Reply With Quote
  #11   Spotlight this post!  
Unread 05-07-2016, 20:10
thatprogrammer's Avatar
thatprogrammer thatprogrammer is offline
Registered User
AKA: Ahad Bawany
no team (None)
Team Role: Programmer
 
Join Date: Apr 2014
Rookie Year: 2014
Location: Florida
Posts: 609
thatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond repute
Re: Good way to bring shooter to exact speed?

Quote:
Originally Posted by kiettyyyy View Post
That's what he meant. The SRX is extremely capable..
I thought the emoji would make my sarcasm obvious.
I brought up the idea of "limiting" the PID's output range from 0-1 (As suggested by ratdude747) in case if someone wishing to control a flywheel didn't happen to have an SRX handy.
Reply With Quote
  #12   Spotlight this post!  
Unread 05-07-2016, 23:21
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,565
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Good way to bring shooter to exact speed?

Quote:
Originally Posted by Ether View Post

TBH 2
This links to this post:

Quote:
Originally Posted by Ether View Post
^Following up on the above^

You can improve the spinup response of TBH by clever selection of the initial values before you change the setpoint "S" from 0 to your desired speed.

Do a simple open-loop test to establish the approximate value of motor command (in the range 0 to +1) required to hold your wheel speed at the target value. Call this experimentally determined motor command value "M". It doesn't have to be exact.


To start your spinup do the following:

Set S to your desired wheel speed; initialize Y=1, d=1, and b=2*M-1; and turn your speed controller on.

Since Y=1, you will be applying full voltage to the motor to spin it up (just like bang-bang). Y will remain equal to 1 (applying full voltage) during the spinup, because there will be no zero crossings until you reach the target speed S.

When you reach the first zero crossing (at the target speed), the TBH algorithm will set Y (and b) equal to (Y+b)/2 = (1+(2*M-1))/2 = M, which is the experimentally-determined motor command value required to maintain the wheel at the target speed. You will immediately have the correct (or approximately correct) motor command for your target speed. This will reduce overshoot and oscillation.
If I read this correctly, this will not work some of the time, but not in all cases:
  • If M (the first approximation to the speed) is exactly right, this would result in a tiny overshoot (as the controller notices and reduces the applied voltage) followed by a decay ramp* back to the desired speed. -- GOOD (and quite lucky)
  • If M is a bit low, this would result in the same tiny overshoot followed by a decay ramp* towards a speed less than that desired. At some point, this ramp will cross the desired speed, and the remainder will function exactly as Take Back Half is intended -- GOOD
  • If M is a bit high (results in a speed greater than the acceptable variation from the desired speed), this would result in the same tiny overshoot followed by a decay ramp* towards a speed greater than that desired. The speed will never again cross the desired speed, so TBH will make no further adjustments, and the speed reaches an asymptotic limit outside of the desired speed range -- NOT GOOD.

I would expect more consistent results by calculating the initial b as 2*M'+1, where you are confident that M' is below the "proper" value for M, perhaps 75% or 90% of your "best estimate" depending on how well you know this number.


* - As long as the system has continuous, monotonic response near M, and some sort of frictional losses, there should be a decay ramp of some variety or other, which is enough for my argument. If the system is linear near voltage M, and the frictional losses are viscous (proportional to speed), this will be a classic exponential decay ramp.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #13   Spotlight this post!  
Unread 05-07-2016, 23:57
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,026
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: Good way to bring shooter to exact speed?

Quote:
Originally Posted by GeeTwo View Post
...If M is a bit high (results in a speed greater than the acceptable variation from the desired speed), this would result in the same tiny overshoot followed by a decay ramp* towards a speed greater than that desired.
You don't ramp "towards a speed greater than that desired". You ramp toward the setpoint S, by reducing (or increasing) Y. When you cross the setpoint, the sign of the error changes, and Y is adjusted.

Quote:
Originally Posted by GeeTwo View Post
The speed will never again cross the desired speed
Y will be integrated in the proper direction until the sign of the error changes. You will cross the setpoint.


Reply With Quote
  #14   Spotlight this post!  
Unread 06-07-2016, 02:16
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,565
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Good way to bring shooter to exact speed?

Perhaps I missed something really basic, but this is how I read these posts:


Quote:
Originally Posted by Ether View Post
You don't ramp "towards a speed greater than that desired". You ramp toward the setpoint S, by reducing (or increasing) Y. When you cross the setpoint, the sign of the error changes, and Y is adjusted.
This is only true over the longer course if/when Y is regularly adjusted. I was referring to the period between the first and second crossings of the setpoint speed, during which the voltage applied is held constant. My contention (presented below) is that the second crossing is never achieved in my third case (estimate for M is too large), beginning from a standstill.

Quote:
Originally Posted by Ether View Post
Y will be integrated in the proper direction until the sign of the error changes. You will cross the setpoint.
How does integration of Y cause the sign of the error to change? The "crossing" is determined by whether d and e have the same sign bit. Y is not part of this calculation, only S (setpoint/desired speed) and P (measured speed).

Here's what I'm considering: for simplicity, let's assume a ridiculously simple system such that over the range of 0.2 to 0.8, the asymptotic/terminal speed is equal to the applied voltage multiplier (for a fresh battery). The target speed is 0.5, but M for a desired speed of 0.5 was previously mis-measured at 0.6.

At initialization, b = 2 * 0.6 - 1 = 0.2. e=S-P begins positive, as the motor is not moving (Set point speed definitely faster than measured speed).

The applied voltage multiplier at startup is 1.0, which causes the shooter to promptly reach a speed of 0.5. By the time speed reaches [for argument's sake] 0.51, the applied voltage is adjusted to 0.6, and e is set to a negative value (that is, running too fast). The speed then continues to increase until asymptotically reaching 0.6. d continues to return negative values, so signbit(e) == signbit(d). The if clause in your loop is never reached, and the voltage is held at 0.6 -- until the battery voltage drops so that a voltage multiplier of 0.6 cannot maintain a speed of 0.5. At that point, the algorithm would begin to work as desired, but the match would likely be long over.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #15   Spotlight this post!  
Unread 06-07-2016, 08:19
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,026
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: Good way to bring shooter to exact speed?

Quote:
Originally Posted by GeeTwo View Post
How does integration of Y cause the sign of the error to change?
Because Y is the output to the motor controller, and the integration of Y is always in the direction to drive the speed toward (and then past) the setpoint... which causes a change in the sign of "e".



Last edited by Ether : 06-07-2016 at 10:07.
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:08.

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