|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
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
}
|
|
#2
|
||||
|
||||
|
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; |
|
#3
|
||||
|
||||
|
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 |
|
|