|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Custom GetRate not working.
Hi all,
We've heard that the WIPlib Encoder method getRate() is inconsistent, so we're trying to write out our own (better) without any success. Any suggestions? Code: private static double currGet = 0.0; public static double getRate() { double prevGet = currGet; currGet = shooterEncoder.get(); int scalar = 50; double rateDegreePerSec = Math.abs(currGet-prevGet)*scalar; double rpm = rateDegreePerSec/6.0; System.out.println("Rate: " + rpm); return rpm; } Last edited by Mk.32 : 30-03-2012 at 23:52. |
|
#2
|
||||
|
||||
|
Re: Custom GetRate not working.
Quote:
Code:
private static double currGet = 0.0;
public static double getRate() {
double prevGet = currGet;
currGet = shooterEncoder.get();
int scalar = 50;
double rateDegreePerSec = Math.abs(currGet-prevGet)*scalar;
double rpm = rateDegreePerSec/6.0;
System.out.println("Rate: " + rpm);
return rpm;
}
Also, if you are not sampling the encoder at 1x, you might try that also: Quote:
|
|
#3
|
||||
|
||||
|
Re: Custom GetRate not working.
Sorry for the confusion, we are getting data back however it is very noisy and unstable.
Last edited by Mk.32 : 31-03-2012 at 01:46. Reason: Typo. |
|
#4
|
||||
|
||||
|
Re: Custom GetRate not working.
Quote:
Try using 1x instead of 4x, and try using actual measured elapsed time since last sample instead of a fixed scale factor. If that doesn't work, check to make sure your encoder disk is installed properly. |
|
#5
|
||||
|
||||
|
Re: Custom GetRate not working.
Here is a quick re-write I did, using all the above comments. Encoder is set to 1x.
Wouldn't get to test till next Wednesday. But comments are welcome. Code:
public static void shooterEncoderStart() {
shooterEncoder.start();
shooterEncoder.setDistancePerPulse(1.0 / 360.0);
}
public static void shooterEncoderReset() {
shooterEncoder.reset();
}
public static double getRate() {
double get1 = shooterEncoder.get();
double time = Timer.getFPGATimestamp();
double get2 = shooterEncoder.get();
time -= Timer.getFPGATimestamp();
double rateDegreePerSec = Math.abs(get2-get1)/Math.abs(time);
return rateDegreePerSec/6.0; //RPM
}
|
|
#6
|
||||
|
||||
|
Re: Custom GetRate not working.
Quote:
You want to get the encoder count and the time once per iteration, and compare those values to the previous iteration. Pseudocode: Code:
new_counts = get_counts(); new_time = get_time(); rate = (new_counts - previous_counts)/(new_time - previous_time); previous_counts = new_counts; previous_time = new_time; |
|
#7
|
||||
|
||||
|
Re: Custom GetRate not working.
Thank you for the help Ether, I will try it out next meeting!
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|