Go to Post ...some of our robots could use a proctologist - Scott Ritchie [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 30-01-2013, 11:07
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
LimitSwitch as Command Button

Is there a way to set a command to fire on the push of a limit switch in a similar way to the way joystick buttons are linked to commands?
Reply With Quote
  #2   Spotlight this post!  
Unread 30-01-2013, 12:02
BigJ BigJ is online now
Registered User
AKA: Josh P.
FRC #1675 (Ultimate Protection Squad)
Team Role: Engineer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Milwaukee, WI
Posts: 947
BigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond repute
Re: LimitSwitch as Command Button

there is a subclass of Button called DigitalIOButton that should do what you want.
Reply With Quote
  #3   Spotlight this post!  
Unread 30-01-2013, 12:16
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: LimitSwitch as Command Button

Quote:
Originally Posted by BigJ View Post
there is a subclass of Button called DigitalIOButton that should do what you want.
Awesome, I knew it was somewhere but I couldn't find it. Thank you.
Reply With Quote
  #4   Spotlight this post!  
Unread 30-01-2013, 12:16
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: LimitSwitch as Command Button

Quote:
Originally Posted by BigJ View Post
there is a subclass of Button called DigitalIOButton that should do what you want.
That is designed for a driver station digital i/o, not on the robot. To do it on the robot, it would not be hard to create a class to extend Button that reads from a digital i/o on the robot. Alternately, you could create an InternalButton object and periodically call the setPressed method with the state of the limit switch.
Reply With Quote
  #5   Spotlight this post!  
Unread 30-01-2013, 12:24
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: LimitSwitch as Command Button

Quote:
Originally Posted by Joe Ross View Post
That is designed for a driver station digital i/o, not on the robot. To do it on the robot, it would not be hard to create a class to extend Button that reads from a digital i/o on the robot. Alternately, you could create an InternalButton object and periodically call the setPressed method with the state of the limit switch.
My only worry is getting multiple triggers with one press from noise on the channel. We're trying to implement a frisbee counter that count frisbees coming in and leaving the robot. We tried using the Counter class, but we kept getting random increases in the count from the limit switches. I'm assuming there was noise as the switch was pressed which made it think that there were multiple presses.
Reply With Quote
  #6   Spotlight this post!  
Unread 30-01-2013, 12:46
BigJ BigJ is online now
Registered User
AKA: Josh P.
FRC #1675 (Ultimate Protection Squad)
Team Role: Engineer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Milwaukee, WI
Posts: 947
BigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond repute
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.
Reply With Quote
  #7   Spotlight this post!  
Unread 30-01-2013, 12:48
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: LimitSwitch as Command Button

Quote:
Originally Posted by notmattlythgoe View Post
My only worry is getting multiple triggers with one press from noise on the channel. We're trying to implement a frisbee counter that count frisbees coming in and leaving the robot. We tried using the Counter class, but we kept getting random increases in the count from the limit switches. I'm assuming there was noise as the switch was pressed which made it think that there were multiple presses.
The counter class acts as an interrupt and counts every single edge of the switch bounce, which isn't what you want.

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.
Reply With Quote
  #8   Spotlight this post!  
Unread 30-01-2013, 12:51
gixxy's Avatar
gixxy gixxy is offline
Programming and Arduino Mentor
AKA: Gustave Michel III
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Ruston, LA
Posts: 207
gixxy is on a distinguished road
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();
    }
    
}
__________________
Programmer - A creature known for converting Caffeine into Code.
Studying Computer Science @ Louisiana Tech University
Associate Consultant @ Fenway Group

2012-13: 3946 - Head of Programming, Electrical and Web
2014 - 3468 - Programming Mentor
2015 - Present - Lurker
Reply With Quote
  #9   Spotlight this post!  
Unread 30-01-2013, 12:52
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: LimitSwitch as Command Button

Quote:
Originally Posted by Joe Ross View Post
The counter class acts as an interrupt and counts every single edge of the switch bounce, which isn't what you want.

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.
You can set the Counter class up to only read the leading or trailing edges, so that isn't a worry. We'll probably end up extending the Button class and doing it that way. We might end up with IR pairs as the counters so the Button class would give us the most flexibility. Thanks for the info.
Reply With Quote
  #10   Spotlight this post!  
Unread 01-02-2013, 08:11
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
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.
Reply With Quote
Reply


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

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