Go to Post A well learned individual knows themselves and how to collect and use the tool of knowledge. - techhelpbb [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 01-03-2013, 18:26
AsianRookie AsianRookie is offline
Registered User
AKA: Steven/Tim
FRC #0321 (Robolancers)
Team Role: Programmer
 
Join Date: Oct 2012
Rookie Year: 2007
Location: Philadelphia
Posts: 31
AsianRookie is an unknown quantity at this point
Encoder getRate question

Hey guys, so I have a couple of questions for encoders.
I wired it correctly because live window shows values for speed.
1)Am I using the setDistancePerPulse() correctly?
2)I am getting 0 for getRate() method, is the code correct?
Code:
        shooterMotor = new Talon(RobotMap.SHOOTER_MOTOR);
        shooterEncoder = new Encoder(RobotMap.SHOOTER_ENCODER_A, RobotMap.SHOOTER_ENCODER_B, true, CounterBase.EncodingType.k4X);
        shooterEncoder.setDistancePerPulse(4/360);//4:1 gear ratio
        shooterEncoder.setPIDSourceParameter(Encoder.PIDSourceParameter.kRate);
        shooterEncoder.start();
If anyone can help, that would be appreciated.
Reply With Quote
  #2   Spotlight this post!  
Unread 01-03-2013, 19:02
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: Encoder getRate question

Quote:
Originally Posted by AsianRookie View Post
1)Am I using the setDistancePerPulse() correctly?
Nope. DistancePerPulse is the distance in units that your robot travels, per pulse. So what you need to do is take the circumference of your wheels and divide that by the resolution of your encoder (usually 360 or 250) to give you the distance that your robot will travel forward for every "pulse" of the encoder.

So if you're using 6" wheels, that would give you a circumference of ~18.85 inches. For every turn of your robot's wheels, your robot will travel roughly that distance. So you take the number of pulses per revolution of the encoder, and divide 18.849556 by that number, to give you the distance per pulse of the encoder.

I don't think gear ratio factors into it, since I'm 99% sure the encoder shaft is linked to the output shaft rather than the input gears. This can be fairly trivially tested though I suppose. Or just look up the gearbox manual.
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional

Last edited by F22Rapture : 01-03-2013 at 19:18.
Reply With Quote
  #3   Spotlight this post!  
Unread 01-03-2013, 19:45
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: Encoder getRate question

Quote:
Originally Posted by AsianRookie View Post
shooterEncoder = new Encoder(RobotMap.SHOOTER_ENCODER_A, RobotMap.SHOOTER_ENCODER_B, true, CounterBase.EncodingType.k4X);
shooterEncoder.setDistancePerPulse(4/360);//4:1 gear ratio
You do not want to use getRate() with a 360 CPR encoder with 4X decoding at shooter wheel speeds.

See the first attachment


Do this instead:

1) Connect only Channel A of the encoder to the DSC, and use an up/down counter (from the Counter class) set to count up only. Leave Channel B disconnected.

2) Set the FPGA sampling ring buffer size to 120.

3) Use the counter class's getPeriod() to get the period, then calculate rpm = 60/(360*period)

See the second attachment.




Attached Thumbnails
Click image for larger version

Name:	5000rpm 1440CPR 4N.png
Views:	78
Size:	5.8 KB
ID:	14220  Click image for larger version

Name:	5000rpm 360CPR 120N.png
Views:	70
Size:	5.6 KB
ID:	14221  

Last edited by Ether : 01-03-2013 at 20:12.
Reply With Quote
  #4   Spotlight this post!  
Unread 01-03-2013, 20:46
AsianRookie AsianRookie is offline
Registered User
AKA: Steven/Tim
FRC #0321 (Robolancers)
Team Role: Programmer
 
Join Date: Oct 2012
Rookie Year: 2007
Location: Philadelphia
Posts: 31
AsianRookie is an unknown quantity at this point
Re: Encoder getRate question

Quote:
Originally Posted by F22Rapture View Post
Nope. DistancePerPulse is the distance in units that your robot travels, per pulse. So what you need to do is take the circumference of your wheels and divide that by the resolution of your encoder (usually 360 or 250) to give you the distance that your robot will travel forward for every "pulse" of the encoder.

So if you're using 6" wheels, that would give you a circumference of ~18.85 inches. For every turn of your robot's wheels, your robot will travel roughly that distance. So you take the number of pulses per revolution of the encoder, and divide 18.849556 by that number, to give you the distance per pulse of the encoder.

I don't think gear ratio factors into it, since I'm 99% sure the encoder shaft is linked to the output shaft rather than the input gears. This can be fairly trivially tested though I suppose. Or just look up the gearbox manual.
Well, the encoder is on a different shaft than the motor because we didnt have a way to mount it directly to the motor shaft. Thanks for the clearing though.

Quote:
Originally Posted by Ether View Post
You do not want to use getRate() with a 360 CPR encoder with 4X decoding at shooter wheel speeds.

Do this instead:

1) Connect only Channel A of the encoder to the DSC, and use an up/down counter (from the Counter class) set to count up only. Leave Channel B disconnected.

2) Set the FPGA sampling ring buffer size to 120.

3) Use the counter class's getPeriod() to get the period, then calculate rpm = 60/(360*period)
Thanks for the tip, I will try that when I get in my school on Monday.
Reply With Quote
  #5   Spotlight this post!  
Unread 01-03-2013, 20:52
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: Encoder getRate question

Quote:
Originally Posted by AsianRookie View Post
Well, the encoder is on a different shaft than the motor because we didnt have a way to mount it directly to the motor shaft.
So what speed is your encoder spinning at? And is this for a shooter wheel (as the code seems to imply) or a drivetrain wheel?


Reply With Quote
  #6   Spotlight this post!  
Unread 03-03-2013, 20:11
AsianRookie AsianRookie is offline
Registered User
AKA: Steven/Tim
FRC #0321 (Robolancers)
Team Role: Programmer
 
Join Date: Oct 2012
Rookie Year: 2007
Location: Philadelphia
Posts: 31
AsianRookie is an unknown quantity at this point
Re: Encoder getRate question

I did not receive the gear ratio from the person who was in charge of the shooter, but it is a higher teeth count on the motor and a lower teeth count for the wheel. And yes, this is for the shooter. Also the encoder wheel has 250 ticks.
Reply With Quote
  #7   Spotlight this post!  
Unread 08-03-2013, 10:48
JefferMC JefferMC is offline
Registered User
AKA: Jeff Corbett
FRC #1319 (Flash)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2005
Location: United States
Posts: 44
JefferMC will become famous soon enough
Re: Encoder getRate question

On encoders for shooting wheels, you may wish to watch out for the maximum RPM the encoder can handle. There are both electrical and physical issues there.

You can also approach the granularity of the VxWorks timer, which I believe has a resolution of 6 us. Since GetRate() gives you the inverse of the time between the last two ticks, with a resolution of about 6 us, this caused us some issues with oscillation between two substantially different returned values for RPS. Using the FPGA with the ring buffer may help with this, but we opted for the x1 resolution.
Reply With Quote
  #8   Spotlight this post!  
Unread 08-03-2013, 11:27
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: Encoder getRate question

Quote:
Originally Posted by JefferMC View Post
On encoders for shooting wheels, you may wish to watch out for the maximum RPM the encoder can handle. There are both electrical and physical issues there.
For US Digital E4P encoders, the limit is 60,000 rpm or 3,600,000/CPR, whichever is less.

Quote:
You can also approach the granularity of the VxWorks timer, which I believe has a resolution of 6 us.
The FPGA handles encoders. Vxworks is not involved.


Quote:
Since GetRate() gives you the inverse of the time between the last two ticks, with a resolution of about 6 us, this caused us some issues with oscillation between two substantially different returned values for RPS.
For a high-speed one-direction application like a shooter wheel, do not use getRate(). Use getPeriod() from the Counter class. Make sure you physically connect only Channel A. Leave Channel B disconnected. Create an up/down counter counting rising edges only.

See the attached example calculation of a 250 CPR encoder set up this way and spinning at 5000 rpm, showing the effect of the 6us polling period of the FPGA when the ring buffer is set to 125 samples (1/2 of a revolution).

Quote:
Using the FPGA with the ring buffer may help with this, but we opted for the x1 resolution.
1X decoding of an encoder still requires detecting the rising edges of both channels, which limits your speed.


Attached Thumbnails
Click image for larger version

Name:	5000rpm 250CPR 125N.png
Views:	42
Size:	9.7 KB
ID:	14294  
Reply With Quote
  #9   Spotlight this post!  
Unread 08-03-2013, 15:55
JefferMC JefferMC is offline
Registered User
AKA: Jeff Corbett
FRC #1319 (Flash)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2005
Location: United States
Posts: 44
JefferMC will become famous soon enough
Re: Encoder getRate question

Quote:
Originally Posted by Ether View Post
For US Digital E4P encoders, the limit is 60,000 rpm or 3,600,000/CPR, whichever is less.
Due to an inventory issue, we were forced to use a 360 CPR encoder to attempt to measure our shooting wheel. We exceeded the CPR limit. Frustrating to watch the RPM graph drop to zero as the wheel accelerates. Other solutions were found.

Quote:
The FPGA handles encoders. Vxworks is not involved.
According the the documentation, the FPGA is only used when the counter type is set to k4x, not for k2x and/or k1x. From what I can see from perusing the code, this is correct.

Quote:
For a high-speed one-direction application like a shooter wheel, do not use getRate(). Use getPeriod() from the Counter class. Make sure you physically connect only Channel A. Leave Channel B disconnected. Create an up/down counter counting rising edges only.
getRate() is a derivative of getPeriod(). getPeriod suffers from the same problem, i.e. the period of time between two "clicks" is approaching the resolution of the clock by which those clicks are measured.

The reason we had quad-encoding on this encoder was that at one point we were going to reload discs back through the barrel of the gun, causing us to run the motors backwards and wanting to be sure we knew they were running backwards.

Also, I seem to recall that the PID classes wanted an Encoder and would not accept a Counter. I may be wrong about that.

Quote:
See the attached example calculation of a 250 CPR encoder set up this way and spinning at 5000 rpm, showing the effect of the 6us polling period of the FPGA when the ring buffer is set to 125 samples (1/2 of a revolution).

1X decoding of an encoder still requires detecting the rising edges of both channels, which limits your speed.
I never found that the handling the second channel caused an appreciable issue for the cRIO. However, the point is well taken that it is extra interrupts and unneeded effort.
Reply With Quote
  #10   Spotlight this post!  
Unread 08-03-2013, 16:03
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Encoder getRate question

Quote:
Originally Posted by JefferMC View Post
Also, I seem to recall that the PID classes wanted an Encoder and would not accept a Counter. I may be wrong about that.
The PIDController class only needs a PIDSource and PIDOutput. Counter does not implement PIDSource, but you could always extend it and implement PIDSource.
__________________
All opinions are my own.
Reply With Quote
  #11   Spotlight this post!  
Unread 08-03-2013, 16:20
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: Encoder getRate question

Quote:
Originally Posted by JefferMC View Post
According the the documentation, the FPGA is only used when the counter type is set to k4x, not for k2x and/or k1x.
What documentation are you referring to?


Quote:
I seem to recall that the PID classes wanted an Encoder and would not accept a Counter. I may be wrong about that.
Many teams are successfully using home-brew one-count-per-rev counters on their one-directional shooter wheels. Also, PID is not the only game in town.

Quote:
I never found that the handling the second channel caused an appreciable issue for the cRIO.
Perhaps you did but didn't realize it:
Quote:
Originally Posted by JefferMC View Post
we were forced to use a 360 CPR encoder to attempt to measure our shooting wheel. We exceeded the CPR limit.
Quote:
However, the point is well taken that it is extra interrupts and unneeded effort.
There are no interrupts involved. The FPGA polls the DIO at ~153KHz


Reply With Quote
  #12   Spotlight this post!  
Unread 13-03-2013, 14:45
AsianRookie AsianRookie is offline
Registered User
AKA: Steven/Tim
FRC #0321 (Robolancers)
Team Role: Programmer
 
Join Date: Oct 2012
Rookie Year: 2007
Location: Philadelphia
Posts: 31
AsianRookie is an unknown quantity at this point
Re: Encoder getRate question

A made a modified Counter class, to be used with PIDController and has 120 samples to average. It works wonderful. Thank you Ether.
Reply With Quote
  #13   Spotlight this post!  
Unread 13-03-2013, 14:55
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: Encoder getRate question

Quote:
Originally Posted by AsianRookie View Post
A made a modified Counter class, to be used with PIDController and has 120 samples to average. It works wonderful. Thank you Ether.
And thank you for the follow-up post.

Would you be willing to post your modified Counter class? It would be a service to the FRC community. There are other teams/individuals who need some help figuring out how to do this.



Last edited by Ether : 13-03-2013 at 15:01. Reason: typo
Reply With Quote
  #14   Spotlight this post!  
Unread 15-03-2013, 17:51
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 430
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Encoder getRate question

In case anyone else was looking for a source code example...

Looks like Joe Ross posted a patch to the Encoder and Counter classes for Java.
http://firstforge.wpi.edu/sf/go/artf...v=1&_pagenum=1
__________________
http://team2168.org
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:15.

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