View Single Post
  #2   Spotlight this post!  
Unread 31-03-2012, 09:46
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
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: Custom GetRate not working.

Quote:
Originally Posted by Mk.32 View Post
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;

Reply With Quote