Go to Post The sign of a mature community is not that everyone is nice and happy but that differring opinions can be expressed. -Joe Johnson - archiver [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 16-01-2014, 20:06
OwenVanTiem OwenVanTiem is offline
Code Monkey
FRC #0453 (Rock Em Sock Em Robotics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Michigan
Posts: 5
OwenVanTiem is an unknown quantity at this point
Programming Limit Switch

I am the programmer for my team, and I am curious how to program a limit switch. I cant seem to find any documentation or code snippets elsewhere on the internet.
Reply With Quote
  #2   Spotlight this post!  
Unread 16-01-2014, 20:14
NWChen's Avatar
NWChen NWChen is offline
Alum
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: New York City
Posts: 205
NWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to behold
Re: Programming Limit Switch

Initialize limit switches as a digital input:
Code:
DigitalInput switch = new DigitalInput(channel)
To check if a switch is closed or not, use the get() method:
Code:
if(switch.get()) doSomething();
See this thread.
Reply With Quote
  #3   Spotlight this post!  
Unread 17-01-2014, 09:58
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
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,717
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: Programming Limit Switch

What Signet said.

Also, if you ware using the Command Based structure with Java you can set the limit switch up to act as a button to fire a command.

Code:
final DigitalInput limitSwitch = new DigitalInput(1);
Button limitSwitchButton = new Button() {
     public boolean get() {
           return limitSwitch.get();
     }
};
limitSwitchButton.whenPressed(new SomethingCommand());
Reply With Quote
  #4   Spotlight this post!  
Unread 17-01-2014, 15:11
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: Programming Limit Switch

Quote:
Originally Posted by notmattlythgoe View Post
What Signet said.

Also, if you ware using the Command Based structure with Java you can set the limit switch up to act as a button to fire a command.

Code:
final DigitalInput limitSwitch = new DigitalInput(1);
Button limitSwitchButton = new Button() {
     public boolean get() {
           return limitSwitch.get();
     }
};
limitSwitchButton.whenPressed(new SomethingCommand());
Actually there is already a class for this in WPILib: DigitalIOButton.

So you just need:
Code:
Button limitSwitchButton = new DigitalIOButton(1);
limitSwitchButton.whenPressed(new limitSwitchCommand());
__________________
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
  #5   Spotlight this post!  
Unread 17-01-2014, 15:22
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
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,717
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: Programming Limit Switch

Quote:
Originally Posted by gixxy View Post
Actually there is already a class for this in WPILib: DigitalIOButton.

So you just need:
Code:
Button limitSwitchButton = new DigitalIOButton(1);
limitSwitchButton.whenPressed(new limitSwitchCommand());
Even simpler.
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 22:35.

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