Go to Post We just need to make engineering an interesting everyday thing, as visible as art exhibits or concerts or football games. - Alan Anderson [more]
Home
Go Back   Chief Delphi > Technical > Electrical
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-02-2012, 18:04
Mr. Rogers's Avatar
Mr. Rogers Mr. Rogers is offline
That? That was in the CAD.
FRC #3539 (Byting Bulldogs)
Team Role: College Student
 
Join Date: Apr 2011
Rookie Year: 2011
Location: Romeo, MI
Posts: 67
Mr. Rogers will become famous soon enoughMr. Rogers will become famous soon enough
High Speed Encoder Problem

Hey, we have a 128 click encoder for our shooter speed. Our java programmers managed to get an encoder velocity, but it updates constantly and is all over the place, it ranges +/- 1000 clicks per second when we run a constant speed on the shooter motors, any way to clean up the "noise," if that's the problem. Thanks.
__________________
Grow the roses of success!
2011 Archimedes 2nd seed,
2011 Waterford Champion, 2011 Troy Simi-Finalist,
2011 Waterford Rookie all star, 2011 Troy Rookie all star
http://www.bytingbulldogs.com/
  #2   Spotlight this post!  
Unread 22-02-2012, 18:05
Ty Tremblay's Avatar
Ty Tremblay Ty Tremblay is offline
Robotics Engineer
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2006
Rookie Year: 2004
Location: Alton NH
Posts: 832
Ty Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond repute
Re: High Speed Encoder Problem

How are you calculating the rate? Are you using WPILib?
__________________
  #3   Spotlight this post!  
Unread 22-02-2012, 18:10
Mr. Rogers's Avatar
Mr. Rogers Mr. Rogers is offline
That? That was in the CAD.
FRC #3539 (Byting Bulldogs)
Team Role: College Student
 
Join Date: Apr 2011
Rookie Year: 2011
Location: Romeo, MI
Posts: 67
Mr. Rogers will become famous soon enoughMr. Rogers will become famous soon enough
Re: High Speed Encoder Problem

It that a lab view feature? We're using a pre-made java class from the 2012 API. It has a " .getRate() " that returns the angular velocity.
__________________
Grow the roses of success!
2011 Archimedes 2nd seed,
2011 Waterford Champion, 2011 Troy Simi-Finalist,
2011 Waterford Rookie all star, 2011 Troy Rookie all star
http://www.bytingbulldogs.com/
  #4   Spotlight this post!  
Unread 22-02-2012, 18:14
Ty Tremblay's Avatar
Ty Tremblay Ty Tremblay is offline
Robotics Engineer
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2006
Rookie Year: 2004
Location: Alton NH
Posts: 832
Ty Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond reputeTy Tremblay has a reputation beyond repute
Re: High Speed Encoder Problem

WPILib is basically the whole thing. I think encoder.getRate() works by reading the number of encoder counts from the FPGA and then dividing by the time elapsed between readings. As your RPMs increase, your noise will increase. Have you tried a moving average?

1000 ticks per second is actually pretty darn slow. That equates to about 470rpm. Is that the speed you're looking for?
__________________
  #5   Spotlight this post!  
Unread 22-02-2012, 18:15
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,521
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: High Speed Encoder Problem

That's the encoder we gave you .

The getrate from the library is an instananeous rate. You'll be better off using the 'get count' function, and then measureing the time between loop updates like this:

(New count - old count ) / loop time

If that ends up still being noisy, you can average, or calculate over more than one loop. Also, make sure you're running in single sample mode rather than 4x to remove phase errors.
  #6   Spotlight this post!  
Unread 22-02-2012, 19:06
Mr. Rogers's Avatar
Mr. Rogers Mr. Rogers is offline
That? That was in the CAD.
FRC #3539 (Byting Bulldogs)
Team Role: College Student
 
Join Date: Apr 2011
Rookie Year: 2011
Location: Romeo, MI
Posts: 67
Mr. Rogers will become famous soon enoughMr. Rogers will become famous soon enough
Re: High Speed Encoder Problem

Quote:
Originally Posted by Tom Line View Post
That's the encoder we gave you .
Yeah.
I thought about an average value too, but our programmers don't know how to implement that.
__________________
Grow the roses of success!
2011 Archimedes 2nd seed,
2011 Waterford Champion, 2011 Troy Simi-Finalist,
2011 Waterford Rookie all star, 2011 Troy Rookie all star
http://www.bytingbulldogs.com/
  #7   Spotlight this post!  
Unread 22-02-2012, 20:00
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,074
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: High Speed Encoder Problem

Quote:
Originally Posted by Mr. Rogers View Post
I thought about an average value too, but our programmers don't know how to implement that.
If you use an infinite impulse response filter, it is very simple to do:

new_filtered_value = K*previous_filtered_value + (1-K)* new_sample

... that's all there is to it.

"K" is a tuning constant, which you use to adjust the "strength" of the filter. K must be in the range zero to +1. When K=0, there is no filtering. When K=1, the filtering is so "strong" that the filtered value never changes.



  #8   Spotlight this post!  
Unread 14-04-2012, 23:17
JamesTerm's Avatar
JamesTerm JamesTerm is offline
Terminator
AKA: James Killian
FRC #3481 (Bronc Botz)
Team Role: Engineer
 
Join Date: May 2011
Rookie Year: 2010
Location: San Antonio, Texas
Posts: 298
JamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to behold
Re: High Speed Encoder Problem

Quote:
Originally Posted by Ether View Post
If you use an infinite impulse response filter, it is very simple to do:

new_filtered_value = K*previous_filtered_value + (1-K)* new_sample

... that's all there is to it.

"K" is a tuning constant, which you use to adjust the "strength" of the filter. K must be in the range zero to +1. When K=0, there is no filtering. When K=1, the filtering is so "strong" that the filtered value never changes.



I like this IIR... in the video world we call this a blend function as it is a way to blend one pixel onto another... where we would do blending transitions effects for each pixel.

With our recent encoder issue (sorry I don't know how to link to it)... I tried using the blend, but found that it would introduce latency when it is tuned too high. I prefer this over averaging though, but the real winner is the Kalman filter... that one gave good enough results without the latency. And latency makes it much more difficult to tune the PID. (Especially to someone who has not yet mastered the skill of it yet).
  #9   Spotlight this post!  
Unread 15-04-2012, 02:38
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: High Speed Encoder Problem

We have a similar filter in our library but we called it MovingAverage filter. In a sense, it is averaging the last N points.
Code:
/*
 * MovingAverage of N points:
 *      MovingAverage = (MovingAverage*(N - 1) + CurrData)/N
 *                    = MovingAverage*(N - 1)/N + CurrData/N
 *                    = MovingAverage*(1 - Kf) + CurrData*Kf
 * where 1/N = Kf
 *        (N - 1)/N = 1 - 1/N = 1 - Kf
 */
__________________
  #10   Spotlight this post!  
Unread 15-04-2012, 10:05
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,074
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: High Speed Encoder Problem

Quote:
Originally Posted by mikets View Post
We have a similar filter in our library but we called it MovingAverage filter. In a sense, it is averaging the last N points.
Code:
/*
 * MovingAverage of N points:
 *      MovingAverage = (MovingAverage*(N - 1) + CurrData)/N
 *                    = MovingAverage*(N - 1)/N + CurrData/N
 *                    = MovingAverage*(1 - Kf) + CurrData*Kf
 * where 1/N = Kf
 *        (N - 1)/N = 1 - 1/N = 1 - Kf
 */
Actually, what you've shown above is an IIR filter and it does not average just the last N points. The values of all previous samples (not just the last N samples) get included in the calculation (to within the floating-point precision being used). The older samples contribute exponentially less to the output.

As you've shown, it's identical to what was posted earlier.



Last edited by Ether : 15-04-2012 at 11:31. Reason: edited for clarity
  #11   Spotlight this post!  
Unread 15-04-2012, 15:49
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: High Speed Encoder Problem

You are right, it does carry the history of all pass data points.
__________________
  #12   Spotlight this post!  
Unread 16-04-2012, 09:10
JamesTerm's Avatar
JamesTerm JamesTerm is offline
Terminator
AKA: James Killian
FRC #3481 (Bronc Botz)
Team Role: Engineer
 
Join Date: May 2011
Rookie Year: 2010
Location: San Antonio, Texas
Posts: 298
JamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to beholdJamesTerm is a splendid one to behold
Re: High Speed Encoder Problem

Here is the Kalman Filter:

Code:
  /***********************************************************************************************************/
 /*												KalmanFilter												*/
/***********************************************************************************************************/

void KalmanFilter::Reset()
{
	m_FirstRun=true;
    //initial values for the kalman filter
    m_x_est_last = 0.0;
    m_last = 0.0;
}

KalmanFilter::KalmanFilter(): m_Q(0.022),m_R(0.617)  //setup Q and R as the noise in the system
{
}

double KalmanFilter::operator()(double input)
{
	//For first run set the last value to the measured value
	if (m_FirstRun)
	{
		m_x_est_last=input;
		m_FirstRun=false;
	}
    //do a prediction
    double x_temp_est = m_x_est_last;
    double P_temp = m_last + m_Q;
    //calculate the Kalman gain
    double K = P_temp * (1.0/(P_temp + m_R));
    //the 'noisy' value we measured
    double z_measured = input;
    //correct
    double x_est = x_temp_est + K * (z_measured - x_temp_est); 
    double P = (1- K) * P_temp;
    
    //update our last's
    m_last = P;
    m_x_est_last = x_est;
    
	//Test for NAN
	if ((!(m_x_est_last>0.0)) && (!(m_x_est_last<0.0)))
		m_x_est_last=0;

    return x_est;
}
  #13   Spotlight this post!  
Unread 22-02-2012, 19:09
Mr. Rogers's Avatar
Mr. Rogers Mr. Rogers is offline
That? That was in the CAD.
FRC #3539 (Byting Bulldogs)
Team Role: College Student
 
Join Date: Apr 2011
Rookie Year: 2011
Location: Romeo, MI
Posts: 67
Mr. Rogers will become famous soon enoughMr. Rogers will become famous soon enough
Re: High Speed Encoder Problem

Quote:
Originally Posted by Tom Line View Post

If that ends up still being noisy, you can average, or calculate over more than one loop. Also, make sure you're running in single sample mode rather than 4x to remove phase errors.
Yeah, I was wondering if we could do that. All the java classes for encoder need an A and B channel. Could we just sample pulses from one digital port and compare it against the code's timer????
__________________
Grow the roses of success!
2011 Archimedes 2nd seed,
2011 Waterford Champion, 2011 Troy Simi-Finalist,
2011 Waterford Rookie all star, 2011 Troy Rookie all star
http://www.bytingbulldogs.com/
  #14   Spotlight this post!  
Unread 22-02-2012, 19:25
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,074
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: High Speed Encoder Problem

Quote:
Originally Posted by Mr. Rogers View Post
Yeah, I was wondering if we could do that. All the java classes for encoder need an A and B channel. Could we just sample pulses from one digital port and compare it against the code's timer????
Yes, but with the Counter class instead of the Encoder class.


  #15   Spotlight this post!  
Unread 22-02-2012, 19:28
Mr. Rogers's Avatar
Mr. Rogers Mr. Rogers is offline
That? That was in the CAD.
FRC #3539 (Byting Bulldogs)
Team Role: College Student
 
Join Date: Apr 2011
Rookie Year: 2011
Location: Romeo, MI
Posts: 67
Mr. Rogers will become famous soon enoughMr. Rogers will become famous soon enough
Re: High Speed Encoder Problem

Quote:
Originally Posted by Ether View Post
Yes, but with the Counter class instead of the Encoder class.


Perfect, Thanks.
__________________
Grow the roses of success!
2011 Archimedes 2nd seed,
2011 Waterford Champion, 2011 Troy Simi-Finalist,
2011 Waterford Rookie all star, 2011 Troy Rookie all star
http://www.bytingbulldogs.com/
Closed Thread


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:10.

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