Go to Post "Drink Mountain Dew. Eat Pizza. Make Robot. This is life." - onecoolc [more]
Home
Go Back   Chief Delphi > Technical > Programming
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
  #16   Spotlight this post!  
Unread 04-03-2013, 15:30
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,760
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Sensor "de-noising"

Quote:
Originally Posted by mrklempae View Post
This year we're using a moving average to filter out noise from our sensors. It's about seven lines of code total, and works by feeding a stream of data into an array and calculating the average continuously. It works really well for rangefinders, but I'm sure it's applicable to almost anything. All you need to do to adjust the sensitivity is change the sample size.
Applicable to anything except a digital signal. Unless 2/3rds on has some sort of meaning I'm unaware of.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
  #17   Spotlight this post!  
Unread 05-03-2013, 13:26
EricS-Team180's Avatar
EricS-Team180 EricS-Team180 is offline
SPAM, the lunchmeat of superheroes!
AKA: Eric Schreffler
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Apr 2002
Rookie Year: 2001
Location: Stuart, Florida
Posts: 561
EricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond reputeEricS-Team180 has a reputation beyond repute
Re: Sensor "de-noising"

While Kevin's approach is far more elegant, this might work for you in a pinch:
Code:
/* some set-up */
#include <stdio.h>
#define true 1
#define false !true 
typedef char boolean;

/* a program to run the stuff */
int main (void)
{
static int array[5] = {0,0,0,0,0};
static int counter = 0;
boolean persistence;
boolean digitalInput;
int i;

/* run the persistance checker in a loop */
 for (i=0; i<10; i++)
 {  

   /* put in some false then put in some true */
  if(i>4)
     digitalInput = true;
  else
     digitalInput = false;

  /* check on the input and fill the 
   * persistence array with the result 
   */  
  if( digitalInput)
    array[counter] = 1;
  else
    array[counter] = 0;

  /* keep tabs on the array index */
  counter++;
  if(counter > 4) 
        counter = 0;

/* now AND the entire array and show the result */
  persistence = array[0] && array[1] && array[2] && array[3] && array[4];
  printf(" perist = %d \n",persistence);

 }

}
When the array fills and remains filled, you get true, otherwise it's false
...ugly but it could work

Eric
__________________

Don't PANIC!
S. P. A. M.

Last edited by EricS-Team180 : 05-03-2013 at 13:34.
  #18   Spotlight this post!  
Unread 05-03-2013, 17:08
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,134
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: Sensor "de-noising"


Here's a simple IIR filter which does essentially the same thing with 2 lines of code, no loops, and no conditional logic:

Code:
ave = 0.5*(input+ave);
output = truncate(ave+0.03);
It does use floating point (for ave), but the cRIO has an FPU.

input and output are 0 or 1.


  #19   Spotlight this post!  
Unread 06-03-2013, 02:24
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 446
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Sensor "de-noising"

Last year we created a class to handle averaging out our noise. we were using this for sensors that gave us analog data, but you could send in 1.0 and 0.0 on the output side for a digital signal.

What ended up being nice about this class last year was that we could very easily change how many samples were being included in the average. As we started to speed things up throughout the season, we needed the average to be more responsive (fewer samples)

Here's the Java code: https://gist.github.com/jcorcoran/5097376
__________________
http://team2168.org
  #20   Spotlight this post!  
Unread 06-03-2013, 08:47
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,134
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: Sensor "de-noising"

Quote:
Originally Posted by otherguy View Post
What ended up being nice about this class last year was that we could very easily change how many samples were being included in the average.
The 0.03 number can be adjusted to accomplish the same thing.


  #21   Spotlight this post!  
Unread 06-03-2013, 09:01
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,760
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Sensor "de-noising"

Quote:
Originally Posted by Ether View Post

Here's a simple IIR filter which does essentially the same thing with 2 lines of code, no loops, and no conditional logic:

Code:
ave = 0.5*(input+ave);
output = truncate(ave+0.03);
It does use floating point (for ave), but the cRIO has an FPU.

input and output are 0 or 1.
It's been a while since I've done IIR filters and such, so my math on them is rusty. Is that actually exactly equivalent to checking than the signal has been 1 for the last X ms? It would seem that it would tolerate some blips low. And it definitely switches 1->0 quicker than 0->1.

Mind you, it's probably a perfectly cromulent and simple solution to the OP's actual problem, it just seems different than actual debouncing.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
  #22   Spotlight this post!  
Unread 06-03-2013, 09:25
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,134
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: Sensor "de-noising"

Quote:
Originally Posted by Kevin Sevcik View Post
It's been a while since I've done IIR filters and such, so my math on them is rusty. Is that actually exactly equivalent to checking than the signal has been 1 for the last X ms? It would seem that it would tolerate some blips low. And it definitely switches 1->0 quicker than 0->1.

Mind you, it's probably a perfectly cromulent and simple solution to the OP's actual problem, it just seems different than actual debouncing.
As shown, it debounces only in one direction: it requires 5 ones in a row to switch the output to 1, but only one zero to switch back to zero (and stay zero until 5 more consecutive ones are seen).

If you want to debounce in both directions, change the second line to

Code:

if(output==0) output=truncate(ave+0.03); else output=truncate(ave+1-0.03);

Last edited by Ether : 06-03-2013 at 09:42.
  #23   Spotlight this post!  
Unread 06-03-2013, 22:58
efoote868 efoote868 is offline
foote stepped in
AKA: E. Foote
FRC #0868
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2005
Location: Noblesville, IN
Posts: 1,427
efoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond reputeefoote868 has a reputation beyond repute
Re: Sensor "de-noising"

Quote:
Originally Posted by Ether View Post
As shown, it debounces only in one direction: it requires 5 ones in a row to switch the output to 1, but only one zero to switch back to zero (and stay zero until 5 more consecutive ones are seen).

If you want to debounce in both directions, change the second line to

Code:

if(output==0) output=truncate(ave+0.03); else output=truncate(ave+1-0.03);
If I understand what you're doing, .03 is a nice way to represent 2 ^ -5, and if you wanted more or less consecutive bits (allowing longer debouncing) you'd adjust the exponent accordingly.
__________________

Be Healthy. Never Stop Learning. Say It Like It Is. Own It. Like our values? Flexware Innovation is hiring!. We're looking for Senior Automation, Software, and System Engineers. Check us out!
  #24   Spotlight this post!  
Unread 06-03-2013, 23:21
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,134
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: Sensor "de-noising"

Quote:
Originally Posted by efoote868 View Post
...if you wanted more or less consecutive bits (allowing longer debouncing) you'd adjust the exponent accordingly.
Yes.


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 04:36.

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