|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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();
|
|
#2
|
||||
|
||||
|
Re: Encoder getRate question
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. Last edited by F22Rapture : 01-03-2013 at 19:18. |
|
#3
|
||||
|
||||
|
Re: Encoder getRate question
Quote:
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. Last edited by Ether : 01-03-2013 at 20:12. |
|
#4
|
|||
|
|||
|
Re: Encoder getRate question
Quote:
Quote:
|
|
#5
|
||||
|
||||
|
Re: Encoder getRate question
Quote:
|
|
#6
|
|||
|
|||
|
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.
|
|
#7
|
|||
|
|||
|
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. |
|
#8
|
||||
|
||||
|
Re: Encoder getRate question
Quote:
Quote:
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). Quote:
|
|
#9
|
||||
|
||||
|
Re: Encoder getRate question
Quote:
Quote:
Quote:
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:
|
|
#10
|
||||
|
||||
|
Re: Encoder getRate question
The PIDController class only needs a PIDSource and PIDOutput. Counter does not implement PIDSource, but you could always extend it and implement PIDSource.
|
|
#11
|
|||||
|
|||||
|
Re: Encoder getRate question
Quote:
Quote:
Quote:
Quote:
Quote:
|
|
#12
|
|||
|
|||
|
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.
|
|
#13
|
||||
|
||||
|
Re: Encoder getRate question
Quote:
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 |
|
#14
|
||||
|
||||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|