|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
Re: LimitSwitch as Command Button
Quote:
|
|
#2
|
|||
|
|||
|
Re: LimitSwitch as Command Button
Whoops, my bad. Yeah you should be able to extend Button then and use your own like Joe said. If you only want one activation in a certain amount of time you could make a Timer object internal to your class to make sure only one activation happens per amount of time.
|
|
#3
|
||||||
|
||||||
|
Re: LimitSwitch as Command Button
Quote:
The simplest method for dealing with switch bounce is to poll the switch slower then the duration of the switch bounce. This works as long as the process actuating the switch is "slow", which my guess is that a frisbee counter is. For example, if the switch bounces for 10ms, polling it every 20ms will give you at worst one reading during switch bounce. If you happen to sample low during the bounce, you're reading of the switch will be delayed 20ms (the next sample will be high). If you happen to sample high during the switch bounce, you will react immediately (and the next sample will be high). If you extend button to read the switch, it would automatically get called at 20ms. The following paper has lots of examples of switch bounce, as well as examples of both hardware and software debouncing, if you determine you do need to debounce. http://www.eng.utah.edu/~cs5780/debouncing.pdf If you extend Button, you could implement your debouncing algorithm in get method. |
|
#4
|
|||||
|
|||||
|
Re: LimitSwitch as Command Button
Quote:
|
|
#5
|
|||||
|
|||||
|
Re: LimitSwitch as Command Button
Thanks guys, overriding the Button class worked great, and there was no bouncing at all. The thread must process slower than the bounce happens so we didn't have to worry about it.
|
|
#6
|
||||
|
||||
|
Re: LimitSwitch as Command Button
It is quite easy actually. You just extend Button and implement your own get() method to return the limit switch input. Add your own debouncing and you are good.
Here is my code (I haven't implemented any debouncing) Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.frc3946.MyTest;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.buttons.Button;
/**
*
* @author Gustave Michel
*/
public class IOButton extends Button {
DigitalInput button;
public IOButton(int port) {
button = new DigitalInput(port);
}
public boolean get() {
return button.get();
}
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|