Go to Post Were going to nationals!?! Did anyone think of telling me this? - Beta Version [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-01-2013, 13:39
Luan Motta Luan Motta is offline
Registered User
FRC #1772
 
Join Date: Jan 2013
Location: brazil
Posts: 4
Luan Motta is an unknown quantity at this point
Keep the engine speed

We want that the motor remains at the same speed all the time with encoder.
Maybe we need to use the PID controller.
How we will do this in java?
  #2   Spotlight this post!  
Unread 14-01-2013, 15:32
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: Keep the engine speed

Last year, we used a "Bang Bang" controller, which Mr. Ether helped us implement (though he got the idea from another member here, IIRC) for controlling our shooter wheel.

My C++ (similar enough to Java to help) source code from last year lives here:
https://github.com/TeamExcel/Project.../Robot2012.cpp
Lines 1063 and 1346 are most interesting for you.

The basic proposition is that a PID controller is overkill, or the wrong tool for the job; when you power the wheel, the RPM will increase, when you don't power the wheel, the RPM will decrease. Since you have direct control over what you want to change (speed of the wheel), you simply apply power when the wheel isn't going fast enough, and remove power once it is going fast enough; it won't continue going faster when you remove power, so you don't have to reduce power as you approach the setpoint (one of the features of a PID), and once you pass your setpoint removing power is the best way to reduce your speed (rather than applying power in the negative direction).

Our output to the motor uses a voltage ramp to prevent any big snap on/off actions (ie if the motor is off, quickly ramp up the voltage toward 100%, rather than jumping there instantly), other than that, it's "On" when too slow, and "Off" when too fast.

Make sure you are not in "brake" mode on your motor controller (a jumper on the Jaguar controls this).
  #3   Spotlight this post!  
Unread 14-01-2013, 15:37
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Electrical/Programming Mentor
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,785
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Keep the engine speed

We had this working for our drive train last year, and we program in Java. If you send an e-mail to 2177@therobettes.com, I'll make sure our programmers send you a code sample of what we did!
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
  #4   Spotlight this post!  
Unread 14-01-2013, 19:40
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 591
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: Keep the engine speed

If you want to use the PIDController class for this, be sure to use the FeedFoward term. It is documented partway down this page:

http://wpilib.screenstepslive.com/s/...rs-pid-control

but basically, you need to give the motor a base value that is close the desired motor speed. The P, I, and D adjustments will be added to the FeedForward term in the calculations.

Brad
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
  #5   Spotlight this post!  
Unread 14-01-2013, 20:15
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: Keep the engine speed

Is there a way to hook an encoder to the CIMs if we aren't using a gearbox?
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional
  #6   Spotlight this post!  
Unread 14-01-2013, 21:17
Radical Pi Radical Pi is offline
Putting the Jumper in the Bumper
AKA: Ian Thompson
FRC #0639 (Code Red Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York
Posts: 655
Radical Pi has a spectacular aura aboutRadical Pi has a spectacular aura aboutRadical Pi has a spectacular aura about
Re: Keep the engine speed

I'm not sure of how one would do that (I'm not very mechanically minded), but there are other ways to measure the speed of a wheel. On our shooter last year we had a beam sensor which detected the spokes of the wheel instead of an encoder. It runs into some trouble at lower speeds, but the cRIO's counters are perfectly capable of measuring the speed of something like that
__________________

"To have no errors would be life without meaning. No strugle, no joy"
"A network is only as strong as it's weakest linksys"
  #7   Spotlight this post!  
Unread 14-01-2013, 21:23
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,091
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: Keep the engine speed

Quote:
Originally Posted by Radical Pi View Post
On our shooter last year we had a beam sensor which detected the spokes of the wheel instead of an encoder. It runs into some trouble at lower speeds
Did you ask the FPGA for the spoke count and then divide the change in spoke count by the elapsed time,

or

Did you ask the FPGA for the elapsed time (using the microtimer) between the last two counts ?


  #8   Spotlight this post!  
Unread 14-01-2013, 21:34
nighterfighter nighterfighter is offline
1771 Alum, 1771 Mentor
AKA: Matt B
FRC #1771 (1771)
Team Role: Mentor
 
Join Date: Sep 2009
Rookie Year: 2007
Location: Suwanee/Kennesaw, GA
Posts: 835
nighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant futurenighterfighter has a brilliant future
Re: Keep the engine speed

http://www.chiefdelphi.com/forums/sh...d.php?t=105679
__________________
1771- Programmer, Captain, Drive Team (2009-2012)
4509- Mentor (2013-2015)
1771- Mentor (2015)
  #9   Spotlight this post!  
Unread 15-01-2013, 00:30
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Keep the engine speed

Quote:
Originally Posted by BradAMiller View Post
If you want to use the PIDController class for this, be sure to use the FeedFoward term. It is documented partway down this page:

http://wpilib.screenstepslive.com/s/...rs-pid-control

but basically, you need to give the motor a base value that is close the desired motor speed. The P, I, and D adjustments will be added to the FeedForward term in the calculations.

Brad
Happy to see a feed forward term was added to the PIDController class this year!
  #10   Spotlight this post!  
Unread 15-01-2013, 00:43
Radical Pi Radical Pi is offline
Putting the Jumper in the Bumper
AKA: Ian Thompson
FRC #0639 (Code Red Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York
Posts: 655
Radical Pi has a spectacular aura aboutRadical Pi has a spectacular aura aboutRadical Pi has a spectacular aura about
Re: Keep the engine speed

Quote:
Originally Posted by Ether View Post
Did you ask the FPGA for the spoke count and then divide the change in spoke count by the elapsed time,

or

Did you ask the FPGA for the elapsed time (using the microtimer) between the last two counts ?
The latter (via GetPeriod()). The issue was that the FPGA declared the motor stalled below certain speeds. We considered the other method for a bit, but decided that it wasn't really necessary to implement since the problematic speeds were so slow that the ball wouldn't even get out of the shooter.
__________________

"To have no errors would be life without meaning. No strugle, no joy"
"A network is only as strong as it's weakest linksys"
  #11   Spotlight this post!  
Unread 15-01-2013, 08:57
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,532
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: Keep the engine speed

Quote:
Originally Posted by DjScribbles View Post
Last year, we used a "Bang Bang" controller, which Mr. Ether helped us implement (though he got the idea from another member here, IIRC) for controlling our shooter wheel.

My C++ (similar enough to Java to help) source code from last year lives here:
https://github.com/TeamExcel/Project.../Robot2012.cpp
Lines 1063 and 1346 are most interesting for you.

The basic proposition is that a PID controller is overkill, or the wrong tool for the job; when you power the wheel, the RPM will increase, when you don't power the wheel, the RPM will decrease. Since you have direct control over what you want to change (speed of the wheel), you simply apply power when the wheel isn't going fast enough, and remove power once it is going fast enough; it won't continue going faster when you remove power, so you don't have to reduce power as you approach the setpoint (one of the features of a PID), and once you pass your setpoint removing power is the best way to reduce your speed (rather than applying power in the negative direction).

Our output to the motor uses a voltage ramp to prevent any big snap on/off actions (ie if the motor is off, quickly ramp up the voltage toward 100%, rather than jumping there instantly), other than that, it's "On" when too slow, and "Off" when too fast.

Make sure you are not in "brake" mode on your motor controller (a jumper on the Jaguar controls this).
A bang-bang controller tends to be limited in situations where your rotational inertia is not high. The result is an unstable speed that oscillates approximately just above your set point.

If you are using pneumatic wheels or something else with a reasonably high moment of inertia (I haven't done calculations to determine the cross over) then bang-bang is fine. Otherwise, you will probably want to look at PID. Or you can combine the two using a conditional to switch from bang-bang to PID when you are within a certain range of your setpoint.
  #12   Spotlight this post!  
Unread 15-01-2013, 09:43
EricS-Team180's Avatar
EricS-Team180 EricS-Team180 is offline
SPAM, the lunchmeat of superheroes!
AKA: Eric Schreffler
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Apr 2002
Rookie Year: 2001
Location: Stuart, Florida
Posts: 561
EricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond repute
Re: Keep the engine speed

Last year, we controlled our shooter wheel using a gear tooth counter as a sensor and a PID function based on BradAMiller's PIDController class. We
overloaded the Calculate function in the class (if I remember correctly...don't have the code here) based on a vi of a PID method posted, here, on CD by Kevin Harrial of Team 2168. (We re-wrote it in C++) Without the speed control we measured ~5.0sec recovery time after shooting a ball. With the PID we reduced that to ~0.5sec. 10x improvement! With the closed loop control, the drive team could shoot fast with good repeatability. In addition to the gear tooth sensor, we also tried a TachGen. It worked great, but it put us over the robot cost limit.

I haven't looked at Brad's method for this year, but that addition of the FF is a good one!

Eric
__________________

Don't PANIC!
S. P. A. M.
  #13   Spotlight this post!  
Unread 15-01-2013, 09:54
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,091
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: Keep the engine speed

Quote:
Originally Posted by Tom Line View Post
A bang-bang controller tends to be limited in situations where your rotational inertia is not high. The result is an unstable speed that oscillates approximately just above your set point.

If you are using pneumatic wheels or something else with a reasonably high moment of inertia (I haven't done calculations to determine the cross over) then bang-bang is fine
You can make it work with lower inertia wheels with just a few extra lines of code.

Instead of banging between 0% and 100% when you're near the setpoint, reduce the amplitude of the banging.

To do this, you need to have an idea of what the nominal required voltage is at each setpoint speed you want to control.

For a simple example, let's say you want to control the speed at 3000 rpm and you've found it takes approx 60% of full voltage to do that.

Change your bang-bang code from this:
Code:
if (speed > 3000) bang 0%

else bang 100%
...to this:
Code:
if (speed > 3000 + 200) bang 0%

else if (speed > 3000) bang 60% - 20%

else if (speed > 3000 - 200) bang 60% + 20%

else bang 100%
The numbers above in bold black are your setpoint and your estimated voltage% at setpoint.

The numbers above in red are "tuning parameters".

Making the 20% number larger improves spinup recovery time. Making it smaller reduces the amplitude of oscillations. Don't make it too small or you'll have essentially open-loop operation.

Making the "200" number smaller improves spinup recovery time. If you make it too small the extra lines of code have no effect - you've essentially got 0-100% bang-bang.




Last edited by Ether : 15-01-2013 at 11:03. Reason: replaced narrative with pseudocode
  #14   Spotlight this post!  
Unread 15-01-2013, 16:35
BitTwiddler's Avatar
BitTwiddler BitTwiddler is offline
electronics/programming mentor
AKA: Mr Tanguay
FRC #1726 (N.E.R.D.S.)
Team Role: Mentor
 
Join Date: Oct 2008
Rookie Year: 2006
Location: Sierra Vista, AZ
Posts: 247
BitTwiddler is on a distinguished road
Re: Keep the engine speed

What is the advantage of using the "bang-bang" method of speed control versus PID?
Better use of the motor power band perhaps?
  #15   Spotlight this post!  
Unread 15-01-2013, 16:43
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,091
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: Keep the engine speed

Quote:
Originally Posted by BitTwiddler View Post
What is the advantage of using the "bang-bang" method of speed control versus PID?
If you've got enough inertia and can use the simple on/off logic, it requires no tuning and very little code.

Since the code is so simple, you can run it at higher speed without sucking up too much processing time.

It has the fastest spin-up and recovery time.


Closed Thread


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 02:52.

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