View Single Post
  #6   Spotlight this post!  
Unread 02-03-2013, 23:27
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,685
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"

Electrical implementation depends a little bit on the specifics of your sensor's output, I think. That is, whether it's a TTL output, sinking, sourcing, open collector, etc.

Software implementation is conceptually easy, but implementation could be tricky depending on how you do it. The idea is to "debounce" the signal. Bouncing is when the sensor output, most typically on a physical limit switch, bounces from on to off before settling on one value. So conceptually, you don't want to treat the Input as "On" until it has been On for Xms without any changes. If your debounce time is 10ms and the input is On for 5ms then briefly switches Off for 1ms, then you restart the timer and wait another 10ms after it turns back On. Eventually the signal turns on and stays that way for 10ms and you treat finally treat it as actually on.

Depending on how many of these you need to act like this, you can treat it in a number of ways. I was originally hoping you could wrap DigitalInput and use the input interrupts and a Timer that generated an interrupt event... and then I discovered that the Timer class (in C++ anyways) doesn't have interrupts implemented. So wrapping DigitalInput looks like it'll be somewhat more complicated... I suppose you can do it with a Timer and only have the check occur when the Get function is called... That's the only time you're going to care anyways, so it'd actually make sense. I think I could actually whip up code for that fairly easily. Whether it'd work right the first time is another question, and it'd definitely be in C++, so that might not be super useful to you.

If you only need debouncing on this one sensor, you might do a similar thing, but outside the class in the teleop loop or wherever you're checking for this condition. Pseudo code:
Code:
if(oldInput != input)
  timer.Reset();
oldInput = input;
if(timer.HasPeriodPassed(deb_time) && input != debInput)
  debInput = input;
"debInput" would be the "denoised" value you'd want. Mind you, this has to run in some sort of periodic loop for it to work, and the resolution is only going to be as good as the period of said loop. If you're running this in a 20ms loop, then it obviously can completely miss the signal bouncing around for up to 19 ms as long as the signal is at the same value from one 20ms cycle to the next. Interrupts would give you a lot better control on things, but would be more complex and might be unnecessary.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter