Go to Post Of course 254 owns Battlebots too - dodar [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 04-02-2013, 20:11
thecakeisalie's Avatar
thecakeisalie thecakeisalie is offline
Registered User
FRC #0293
 
Join Date: Mar 2012
Location: Pennington
Posts: 37
thecakeisalie is an unknown quantity at this point
How to create an On/Off button?

While reviewing our shooter code, I figured that the ability to be able to toggle our shooter wheels on/off would be a nice feature to have. However, no matter how hard I tried, I simply could not figure out a way to do this.
The only method that I was able to call upon was just joystickButton.get() since we are using Iterative robot this year.
If it is possible to create an On/Off button, how would it be done?
Reply With Quote
  #2   Spotlight this post!  
Unread 04-02-2013, 22:24
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Re: How to create an On/Off button?

An On/Off button on the dashboard or on your joystick?
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me
Reply With Quote
  #3   Spotlight this post!  
Unread 04-02-2013, 22:43
thecakeisalie's Avatar
thecakeisalie thecakeisalie is offline
Registered User
FRC #0293
 
Join Date: Mar 2012
Location: Pennington
Posts: 37
thecakeisalie is an unknown quantity at this point
Re: How to create an On/Off button?

On the joystick. I would prefer a more physical button.
Reply With Quote
  #4   Spotlight this post!  
Unread 04-02-2013, 22:55
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Re: How to create an On/Off button?

The easiest way would be to save the state as on or off in a boolean or byte variable and then switch it every time the button is pressed.

Pseudo-Code:
Code:
if joystick button pressed then
    if lightsAreOn is true then
        //so some stuff
        set lightsAreOn to false
    else
        //do some stuff
        set lightsAreOn to true
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me
Reply With Quote
  #5   Spotlight this post!  
Unread 05-02-2013, 17:48
thecakeisalie's Avatar
thecakeisalie thecakeisalie is offline
Registered User
FRC #0293
 
Join Date: Mar 2012
Location: Pennington
Posts: 37
thecakeisalie is an unknown quantity at this point
Re: How to create an On/Off button?

That won't work since teleop loops every 20ms, which means one press will equal a lot of Joystick.get()'s.
Reply With Quote
  #6   Spotlight this post!  
Unread 05-02-2013, 18:25
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: How to create an On/Off button?

Use the Timer to limit how quickly you can toggle.

Code:
double interim = 2; //can only toggle every 2 seconds
double previous = 0;

boolean isOn = false; //state of motors

if(JoystickButton.get()) {
  /*check if interim time has passed since previous check*/
  if(Timer.getFPGATimestamp() - previous >= interim) {
    previous == Timer.getFPGATimestamp();
    if(isOn == true) {
      //change state of motors
      isOn = false;
    } else {
      //change state of motors
      isOn = true;
    }
  }
}
__________________
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
  #7   Spotlight this post!  
Unread 05-02-2013, 18:38
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How to create an On/Off button?


Code:
button1 = GetButton(button1);
if (button1 && ! button1previous) toggle1 = !toggle1;
button1previous = button1;
initialize toggle1 to zero.


Reply With Quote
  #8   Spotlight this post!  
Unread 05-02-2013, 20:03
thecakeisalie's Avatar
thecakeisalie thecakeisalie is offline
Registered User
FRC #0293
 
Join Date: Mar 2012
Location: Pennington
Posts: 37
thecakeisalie is an unknown quantity at this point
Re: How to create an On/Off button?

Quote:
Originally Posted by Ether View Post

Code:
button1 = GetButton(button1);
if (button1 && ! button1previous) toggle1 = !toggle1;
button1previous = button1;
initialize toggle1 to zero.


Thank you. This is exactly what I was looking for but couldn't write myself
I assume that if you wanted to start with the motors running, I would initialize toggle as true?
Reply With Quote
  #9   Spotlight this post!  
Unread 05-02-2013, 20:05
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How to create an On/Off button?

Quote:
Originally Posted by thecakeisalie View Post
Thank you. This is exactly what I was looking for but couldn't write myself
I assume that if you wanted to start with the motors running, I would initialize toggle as true?
Yes. Either that or run the motors when it's false


Reply With Quote
  #10   Spotlight this post!  
Unread 05-02-2013, 20:50
Team3266Spencer's Avatar
Team3266Spencer Team3266Spencer is offline
Team Captain and Lead Programmer
AKA: Spencer Lanman
FRC #3266 (Robots-R-US)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Richmond, Indiana
Posts: 280
Team3266Spencer is an unknown quantity at this point
Re: How to create an On/Off button?

Quote:
Originally Posted by thecakeisalie View Post
That won't work since teleop loops every 20ms, which means one press will equal a lot of Joystick.get()'s.
Not if your using the command-based template.
__________________
2012: Buckeye Regional, Queen City Regional, Human Player
2013: Queen City Regional, Buckeye Regional, Crossroads Regional
Shooter Operator
2014: Crossroads Regional, Queen City Regional
Catapult Operator
2015: Georgia Southern Classic Regional (Winner), Queen City Regional
Chainsaw Operator
Want to talk? TeamSpeak: team3266.noip.me
Reply With Quote
  #11   Spotlight this post!  
Unread 07-02-2013, 15:50
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 543
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: How to create an On/Off button?

This is code that I wrote and use. Just make all of your buttons AdvancedButton and call

button#.togglePressed(yourCommand);

some variables are protected so that they cant be accessed but u can still extend the class and make your own addition

code
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 12:48.

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