Quote:
Originally Posted by Mk.32
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 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
}
|
The above won't work. "get1" and "get2" will be equal to each other and you'll always return zero.
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;