View Single Post
  #2   Spotlight this post!  
Unread 30-03-2012, 22:58
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,042
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
We've heard that the WIPlib Encoder method getRate() is inconsistent, so we're trying to write out own (better) without any success.
It's not entirely clear what you mean by "without any success". I will assume what you meant is that you are getting a signal, but it is very noisy.


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;
    }
In the above code, you are not using the actual elapsed time since the previous sample to compute rate. You are assuming the scheduler's timing jitter can be ignored. Try reading a high-res system clock and dividing the delta_counts by the actual elapsed time.

Also, if you are not sampling the encoder at 1x, you might try that also:

Quote:
Originally Posted by Joe Ross View Post
With 4x encoding, you get more noise in the velocity due to quadrature phase errors in the encoder wheel. I recommend 1x for velocity and 4x for distance.

Reply With Quote