Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Joysticks (http://www.chiefdelphi.com/forums/showthread.php?t=92181)

pigpc1993 18-02-2011 10:51

Joysticks
 
We are having issues with our code on programming the joysticks. When we press the button our solenoids switch but sometimes they will switch right back. The Dashboard shows that they switch and then switch back sometimes. So I know they are opening. Any suggestions. Here is the code we are using

Code:

            if(js2.getRawButton(3) == true && j2b3 == false){
                s1.changeSolenoid(a1, a1End);
                s2.changeSolenoid(a2, a2End);
                j2b2 = true;
            }
            else{
                j2b2 = false;
            }


mobilegamer999 18-02-2011 11:27

Re: Joysticks
 
should it be j2b2 in the primary if statement as opposed to j2b3? not sure if that was a typo in posting, if so, then I might need a little bit more detail to help you.

Mike Betts 18-02-2011 12:02

Re: Joysticks
 
Quote:

Originally Posted by pigpc1993 (Post 1025863)
We are having issues with our code on programming the joysticks. When we press the button our solenoids switch but sometimes they will switch right back. The Dashboard shows that they switch and then switch back sometimes. So I know they are opening. Any suggestions. Here is the code we are using

Code:

            if(js2.getRawButton(3) == true && j2b3 == false){
                s1.changeSolenoid(a1, a1End);
                s2.changeSolenoid(a2, a2End);
                j2b2 = true;
            }
            else{
                j2b2 = false;
            }


What you are experiencing is called "contact bounce". From Wikipedia:

Quote:

Contact bounce (also called chatter) is a common problem with mechanical switches and relays. Switch and relay contacts are usually made of springy metals that are forced into contact by an actuator. When the contacts strike together, their momentum and elasticity act together to cause bounce. The result is a rapidly pulsed electric current instead of a clean transition from zero to full current. The effect is usually unimportant in power circuits, but causes problems in some analogue and logic circuits that respond fast enough to misinterpret the on-off pulses as a data stream.
You have to implement a filter function commonly called a switch "debounce" to get rid of the problem.

pigpc1993 18-02-2011 12:06

Re: Joysticks
 
Quote:

Originally Posted by Mike Betts (Post 1025898)
What you are experiencing is called "contact bounce". From Wikipedia:



You have to implement a filter function commonly called a switch "debounce" to get rid of the problem.

How might a fix this?

Mike Betts 18-02-2011 12:26

Re: Joysticks
 
Quote:

Originally Posted by pigpc1993 (Post 1025899)
How might a fix this?

I would start by searching for the word debounce... You may find something.

Patrickwhite 18-02-2011 18:12

Re: Joysticks
 
One thing you can try is editing your else to an else if:
Code:

...
} else if (js2.getRawButton(3) == false) {
...
}

This makes sure it only reverts to true when the button is released.

SuperBK 19-02-2011 21:58

Re: Joysticks
 
The easiest way to implement debounce is to have a counter where you have to read an input for a certain number of times for it to be considered valid.


All times are GMT -5. The time now is 22:19.

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