Go to Post (Water on all this would be good too) - buildmaster5000 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 30-03-2012, 21:13
Mk.32's Avatar
Mk.32 Mk.32 is offline
Registered User
AKA: Mark
FRC #2485 (W.A.R. Lords)
Team Role: Engineer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: San Diego
Posts: 770
Mk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud of
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;
}
__________________
Engineering mentor: Team 2485: WARLords 2013-

Team President: Team 3647 2010-2013

Last edited by Mk.32 : 30-03-2012 at 23:52.
Reply With Quote
  #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,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
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
  #3   Spotlight this post!  
Unread 30-03-2012, 23:39
Mk.32's Avatar
Mk.32 Mk.32 is offline
Registered User
AKA: Mark
FRC #2485 (W.A.R. Lords)
Team Role: Engineer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: San Diego
Posts: 770
Mk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud of
Re: Custom GetRate not working.

Sorry for the confusion, we are getting data back however it is very noisy and unstable.
__________________
Engineering mentor: Team 2485: WARLords 2013-

Team President: Team 3647 2010-2013

Last edited by Mk.32 : 31-03-2012 at 01:46. Reason: Typo.
Reply With Quote
  #4   Spotlight this post!  
Unread 31-03-2012, 01:02
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
Sorry for the confusion, we are getting data back however it is very noisy and unable.
Unstable.

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.


Reply With Quote
  #5   Spotlight this post!  
Unread 31-03-2012, 03:18
Mk.32's Avatar
Mk.32 Mk.32 is offline
Registered User
AKA: Mark
FRC #2485 (W.A.R. Lords)
Team Role: Engineer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: San Diego
Posts: 770
Mk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud of
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
    }
__________________
Engineering mentor: Team 2485: WARLords 2013-

Team President: Team 3647 2010-2013
Reply With Quote
  #6   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
  #7   Spotlight this post!  
Unread 31-03-2012, 16:33
Mk.32's Avatar
Mk.32 Mk.32 is offline
Registered User
AKA: Mark
FRC #2485 (W.A.R. Lords)
Team Role: Engineer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: San Diego
Posts: 770
Mk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud ofMk.32 has much to be proud of
Re: Custom GetRate not working.

Thank you for the help Ether, I will try it out next meeting!
__________________
Engineering mentor: Team 2485: WARLords 2013-

Team President: Team 3647 2010-2013
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:41.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi