Go to Post Secure your battery well, or it will fly like a fish. - Nate Laverdure [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 68 votes, 5.00 average. Display Modes
  #16   Spotlight this post!  
Unread 26-02-2013, 15:29
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,360
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: PID vs Bang-Bang for Shooter Consistency

Quote:
Originally Posted by lori558 View Post
...
We tested the code that billbo911 posted and it worked!
With a few very minor adjustments we got it to work specifically for our robot perfectly. I pulled up a graph of the speed and output and it was very consistent.

I think our problem this whole time has just been the fact that we were making it too complicated. ...
Thanks everyone for taking the time to help out with this! It really helps our team out.
Well, this is going to make my wife very happy!!!
I was going to swing by Kennedy this evening, but now I get to spend the evening with her because it looks like you guys are going to be just fine!! Good luck in San Diego!!

Quote:
Originally Posted by Ether View Post
Bill has posted various versions using different decoding methods. For the benefit of readers of this thread, could you please post the final code that worked for you? Please include both the "begin" and "TeleOp" portions.
Again, for the benefit of readers here, would you please post a screenshot of the graph.
That's what's great about CD and the FRC community.


I'm not going to post what I believe they are using, I'll leave that to Lori so that we see exactly what is working for them.

As she stated, complicating Bang Bang is not necessary. It is actually a very simple controller IN THE RIGHT SITUATION. I believe the key to making it work is, a reliable way to measure the output being controlled.

I still have a couple questions that will probably need to be answered by Mark McLeod, although you may know the answer to this Ether.

How does the FPGA derive the "period" value? Is it just the time between rising, or falling, edges of a signal? Will the duty cycle of the signal influence the "period" value?
__________________
CalGames 2009 Autonomous Champion Award winner
Sacramento 2010 Creativity in Design winner, Sacramento 2010 Quarter finalist
2011 Sacramento Finalist, 2011 Madtown Engineering Inspiration Award.
2012 Sacramento Semi-Finals, 2012 Sacramento Innovation in Control Award, 2012 SVR Judges Award.
2012 CalGames Autonomous Challenge Award winner ($$$).
2014 2X Rockwell Automation: Innovation in Control Award (CVR and SAC). Curie Division Gracious Professionalism Award.
2014 Capital City Classic Winner AND Runner Up. Madtown Throwdown: Runner up.
2015 Innovation in Control Award, Sacramento.
2016 Chezy Champs Finalist, 2016 MTTD Finalist
Reply With Quote
  #17   Spotlight this post!  
Unread 26-02-2013, 15:44
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,088
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 vs Bang-Bang for Shooter Consistency

Quote:
Originally Posted by billbo911 View Post
How does the FPGA derive the "period" value? Is it just the time between rising, or falling, edges of a signal?
The FPGA has an oscillator running at 40MHz. This is divided by 40 to produce a 1 microsecond timer for time-stamping events (like the detection of rising and/or falling edges).

Additionally, the 40MHz clock is divided down by 261 to create a 153257 Hz (6.515 microsecond) polling frequency. The FPGA polls all the DIO inputs synchronously at this frequency.

Whether the FPGA counts and timestamps rising edge only, or both rising and falling edges, or both rising and falling edges on both channels, is determined by how the user sets up the counter (or encoder) object.

In encoder 4X mode, I believe FPGA counts both rising and falling edges on both channels, and by default computes the period using the 5 most-recent counts (i.e 4 periods). Then in WPILib, the period returned is divided by 4 to give the actual period between consecutive edges, which is the value returned to the caller.

Quote:
Will the duty cycle of the signal influence the "period" value?
For a simple 1-channel counter (either a one-per-rev or an encoder with only one channel connected), an object can be created which counts only rising edges. So for a single piece of tape, the width of the tape doesn't matter, as long as it is wide enough for the sensor (and the FPGA) to detect it. The WPILib default for this type of counter is to use the 2 most recent counts to compute the period. This works well for a one-per-rev sensor, because there's only one rising edge per revolution, so there's no error due to tape placement (since it's always the same edge which is being detected).




Last edited by Ether : 26-02-2013 at 16:39.
Reply With Quote
  #18   Spotlight this post!  
Unread 26-02-2013, 16:36
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,360
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: PID vs Bang-Bang for Shooter Consistency

Quote:
Originally Posted by Ether View Post
The FPGA has an oscillator running at 40MHz. This is divided by 40 to produce a 1 microsecond timer for time-stamping events (like the detection of rising and/or falling edges).

Additionally, the 40MHz clock is divided down by 261 to create a 153257 Hz (6.515 microsecond) polling frequency. The FPGA polls all the DIO inputs synchronously at this frequency.

Whether the FPGA counts and timestamps rising edge only, or both rising and falling edges, or both rising and falling edges on both channels, is determined by how the user sets up the counter (or encoder) object.

In encoder 4X mode, I believe FPGA counts both rising and falling edges on both channels, and by default computes the period using the 5 most-recent counts (i.e 4 periods). Then in WPILib, the period returned is divided by 4 to give the actual period between consecutive edges, which is the value returned to the caller.



For a simple 1-channel counter (either a one-per-rev or an encoder with only one channel connected), an object can be created which counts only rising edges. So for a single piece of tape, the width of the tape doesn't matter, as long as it is wide enough for the sensor (and the FPGA to detect it). The WPILib default for this type of counter is to use the 2 most recent counts to compute the period. This works well for a one-per-rev sensor, because there's only one rising edge per revolution, so there's no error due to tape placement (since it's always the same edge which is being detected).




This is basically what I expected but I wanted to verify.
The additional detail also helps whenever we will be using encoders, counters and timers.
__________________
CalGames 2009 Autonomous Champion Award winner
Sacramento 2010 Creativity in Design winner, Sacramento 2010 Quarter finalist
2011 Sacramento Finalist, 2011 Madtown Engineering Inspiration Award.
2012 Sacramento Semi-Finals, 2012 Sacramento Innovation in Control Award, 2012 SVR Judges Award.
2012 CalGames Autonomous Challenge Award winner ($$$).
2014 2X Rockwell Automation: Innovation in Control Award (CVR and SAC). Curie Division Gracious Professionalism Award.
2014 Capital City Classic Winner AND Runner Up. Madtown Throwdown: Runner up.
2015 Innovation in Control Award, Sacramento.
2016 Chezy Champs Finalist, 2016 MTTD Finalist
Reply With Quote
  #19   Spotlight this post!  
Unread 26-02-2013, 16:44
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,088
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 vs Bang-Bang for Shooter Consistency

Quote:
Originally Posted by billbo911 View Post
The additional detail also helps whenever we will be using encoders, counters and timers.
Special thanks to jhersh for providing the detail about the FPGA clocks in a PM earlier this month.


Reply With Quote
  #20   Spotlight this post!  
Unread 26-02-2013, 16:44
Woolly's Avatar
Woolly Woolly is offline
Programming Mentor
AKA: Dillon Woollums
FRC #1806 (S.W.A.T.)
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2012
Location: Springfield, MO
Posts: 512
Woolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond reputeWoolly has a reputation beyond repute
Re: PID vs Bang-Bang for Shooter Consistency

Quote:
Originally Posted by billbo911 View Post
As she stated, complicating Bang Bang is not necessary. It is actually a very simple controller IN THE RIGHT SITUATION. I believe the key to making it work is, a reliable way to measure the output being controlled.
Right, I know for our shooter wheel we had to average the last 5 10ms samples to get consistent data out of our US Digital 256 count encoder.
Not to mention we complicated our controller by using an equation to look up the approximate base power needed for the RPM we wanted, and then have it Add or subtract a certain amount from that based on whether we were over or under our setpoint.
After all this fuss, it has become quite reliable though.
__________________


Team 1806 Student: 2012-2013 | Mentor: 2013-Present
Reply With Quote
  #21   Spotlight this post!  
Unread 26-02-2013, 16:59
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,088
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 vs Bang-Bang for Shooter Consistency

Quote:
Originally Posted by Woolly View Post
Right, I know for our shooter wheel we had to average the last 5 10ms samples to get consistent data out of our US Digital 256 count encoder.
This should not be necessary with that encoder if the counter object is set up properly so that the FPGA, not your code, is doing the period computation. You should be able to get very accurate and rock-solid rpm readings without doing that kind of averaging.

Averaging like that introduces phase lag in the sensor signal. Bang-bang does not like phase lag.

What language were you using?

Quote:
Not to mention we complicated our controller by using an equation to look up the approximate base power needed for the RPM we wanted,
That's called feedforward, and is totally unnecessary with bang-bang.


Quote:
After all this fuss, it has become quite reliable though.
If it's working well for you, now is not the time to be changing the competition code on your robot. But if you'd be interested in exploring this further (maybe on an old robot), start another thread and we can have a discussion about it.


Reply With Quote
  #22   Spotlight this post!  
Unread 26-02-2013, 20:09
flameout flameout is offline
AKA Ryan Van Why
FRC #0957 (SWARM)
Team Role: Alumni
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Oregon
Posts: 168
flameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to all
Re: PID vs Bang-Bang for Shooter Consistency

Quote:
Originally Posted by Ether View Post
1 microsecond timer for time-stamping events (like the detection of rising and/or falling edges).
Quote:
153257 Hz (6.515 microsecond) polling frequency. The FPGA polls all the DIO inputs synchronously at this frequency.
Quote:
WPILib default for this type of counter is to use the 2 most recent counts to compute the period.
Ether, thank you for this info -- this information would be very useful for deciding whether to use this rate determination functionality or numerical differentiation in calculating an encoder's speed (in terms of "lag" and noise for any given sensor and rpm)
Reply With Quote
  #23   Spotlight this post!  
Unread 02-03-2013, 19:42
lori558 lori558 is offline
Registered User
FRC #3250
 
Join Date: Jan 2013
Location: Sacramento, CA
Posts: 9
lori558 is an unknown quantity at this point
Re: PID vs Bang-Bang for Shooter Consistency

Here is our slightly modified code. With the minimum value being at 0, this caused a more inconsistent shooter since the wheel would turn off and on with too much of a difference between the two speeds. Therefore we changed 0 to -0.3.
(Keep in mind, our values are negative simply because this is how our code is written. This can be fixed in the Begin.vi if needed but this is working for us.)

By changing the value to -0.3 it makes it impossible (based off of this code) to shoot below 30%. However, the Frisbee will barely go anywhere at that percentage anyway, therefore that number is perfect for us.

Since the minimum value was changed to -0.3, this caused the wheel to spin at a constant speed of 30% if the desired RPMs were ever lower than that. Thus we added the =0 select value into the code to make sure that when we do not want the wheel to move, it doesn't.

As for the rest of the code, it is the same as using a tachometer and the more basic code so graciously provided by billbo911.
Attached Thumbnails
Click image for larger version

Name:	Delphi code.png
Views:	50
Size:	22.2 KB
ID:	14232  
Reply With Quote
  #24   Spotlight this post!  
Unread 02-03-2013, 20:15
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,088
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 vs Bang-Bang for Shooter Consistency

Quote:
Originally Posted by lori558 View Post
With the minimum value being at 0, this caused a more inconsistent shooter since the wheel would turn off and on with too much of a difference between the two speeds.
[edit] First things first: check to make sure the motor controller brake/coast jumper is in the coast position. If it's not, put it there, change that "-0.3" back to zero, and try it. (hat tip to Billbo911) [/edit]

If that doesn't fix the problem, continue:

The code is not running fast enough.

Take that waveform chart out of there and change the loop timing to 5ms and see if it fixes the problem.


Quote:
Therefore we changed 0 to -0.3
Hmm. What motor controller are you using?



Last edited by Ether : 02-03-2013 at 21:38.
Reply With Quote
  #25   Spotlight this post!  
Unread 02-03-2013, 20:26
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,360
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: PID vs Bang-Bang for Shooter Consistency

I'm thinking the Break/Coast jumper is in the break is position.
__________________
CalGames 2009 Autonomous Champion Award winner
Sacramento 2010 Creativity in Design winner, Sacramento 2010 Quarter finalist
2011 Sacramento Finalist, 2011 Madtown Engineering Inspiration Award.
2012 Sacramento Semi-Finals, 2012 Sacramento Innovation in Control Award, 2012 SVR Judges Award.
2012 CalGames Autonomous Challenge Award winner ($$$).
2014 2X Rockwell Automation: Innovation in Control Award (CVR and SAC). Curie Division Gracious Professionalism Award.
2014 Capital City Classic Winner AND Runner Up. Madtown Throwdown: Runner up.
2015 Innovation in Control Award, Sacramento.
2016 Chezy Champs Finalist, 2016 MTTD Finalist
Reply With Quote
  #26   Spotlight this post!  
Unread 02-03-2013, 21:11
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,088
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 vs Bang-Bang for Shooter Consistency

Quote:
Originally Posted by billbo911 View Post
I'm thinking the Break/Coast jumper is in the break is position.
Yikes! You could be right!

That wasn't even on my radar - I just assumed folks knew it should be coast.


Reply With Quote
  #27   Spotlight this post!  
Unread 03-03-2013, 02:19
lori558 lori558 is offline
Registered User
FRC #3250
 
Join Date: Jan 2013
Location: Sacramento, CA
Posts: 9
lori558 is an unknown quantity at this point
Re: PID vs Bang-Bang for Shooter Consistency

The jumper is in the coast position. We made sure as we were wiring the robot that it was put there.
Before we modified the code we had tried changing the 10ms to 1ms and it was way better, but still not as consistent as it is with the modification. It could just be the way that our bot is designed and programmed, but it works for us.
Reply With Quote
  #28   Spotlight this post!  
Unread 03-03-2013, 09:17
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,088
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 vs Bang-Bang for Shooter Consistency


Quote:
Originally Posted by lori558 View Post
Before we modified the code we had tried changing the 10ms to 1ms and it was way better, but still not as consistent as it is with the modification.
Did you try it without the waveform chart ?


Quote:
It could just be the way that our bot is designed and programmed, but it works for us.
Understood. But here's a chance for you to help those who helped you. We'd like to understand what's going on; to contribute to the community knowledge base.


Reply With Quote
  #29   Spotlight this post!  
Unread 03-03-2013, 09:27
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,685
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: PID vs Bang-Bang for Shooter Consistency

So turn the robot on and leave it in disabled mode. Try turning your wheel by hand, then unplug one of the motor wires and try turning it by hand again. If it doesn't get easier to turn when you unplug a wire, then it's definitely in coast.

Also, if it's fairly hard to turn even with a wire unplugged, then you just have a lot of mechanical resistance in your system. That would also explain why you're seeing better stability with a -0.3 instead of 0. The extra mechanical resistance is slowing your wheel down more rapidly, so giving it a little push instead of letting it coast makes it ramp down slower. So you're having to bump it less often to keep it in tolerance, which I assume is what you're counting as better stability.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
Reply With Quote
  #30   Spotlight this post!  
Unread 03-03-2013, 12:02
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,360
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: PID vs Bang-Bang for Shooter Consistency

Quote:
Originally Posted by Kevin Sevcik View Post
...

Also, if it's fairly hard to turn even with a wire unplugged, then you just have a lot of mechanical resistance in your system. That would also explain why you're seeing better stability with a -0.3 instead of 0. The extra mechanical resistance is slowing your wheel down more rapidly, so giving it a little push instead of letting it coast makes it ramp down slower. So you're having to bump it less often to keep it in tolerance, which I assume is what you're counting as better stability.
Excellent point!
An ideal system for Bang Bang have very little resistance to rotation and a considerable amont of rotational inertia.
Maybe Lori's solution is something to consider when using Bang Bang on a less than optimal system. This is deffinately something I would like to invetigate a bit more.
__________________
CalGames 2009 Autonomous Champion Award winner
Sacramento 2010 Creativity in Design winner, Sacramento 2010 Quarter finalist
2011 Sacramento Finalist, 2011 Madtown Engineering Inspiration Award.
2012 Sacramento Semi-Finals, 2012 Sacramento Innovation in Control Award, 2012 SVR Judges Award.
2012 CalGames Autonomous Challenge Award winner ($$$).
2014 2X Rockwell Automation: Innovation in Control Award (CVR and SAC). Curie Division Gracious Professionalism Award.
2014 Capital City Classic Winner AND Runner Up. Madtown Throwdown: Runner up.
2015 Innovation in Control Award, Sacramento.
2016 Chezy Champs Finalist, 2016 MTTD Finalist
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 07:56.

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