Go to Post Don't test your autonomous on the comp field. There's a practice field for a reason. - DampRobot [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 17-03-2013, 12:23
shindigo shindigo is offline
Registered User
AKA: Mike Parker
FRC #0102
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2009
Location: Somerville, NJ
Posts: 33
shindigo is an unknown quantity at this point
Reassigning button.whenPressed during teleop

Hi,
I think this is a straight-up technical question. How can we reassign the command that is assigned to button.whenPressed during teleop?

We tried something like :
Code:
CommandBase.oi.myPublicButton.whenPressed(new myOtherCommand())
within a command, but this does not seem to work. The button still executes the original command we had assigned to it.

Tia - mp
Reply With Quote
  #2   Spotlight this post!  
Unread 17-03-2013, 20:30
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Reassigning button.whenPressed during teleop

I don't think it's possible. Button.whenPressed() calls Trigger.whenActive(), which adds a ButtonScheduler to the Scheduler's internal list of buttons. I don't think there's a way to remove it. I believe there is an alternative, though.

Custom buttons are pretty easy to make, they just need a get() method. So, if you want an easy way to disable a certain button binding, have a variable:
Code:
Button doubleBoundButton; // this is the button you want to trigger differently at different times
boolean initialBindingEnabled = true;
Button initialBinding = new Button() {
           public boolean get() {
               return initialBindingEnabled && doubleBoundButton.get();
           }
       },
       secondaryBinding = new Button() {
           public boolean get() {
               return !initialBindingEnabled && doubleBoundButton.get();
           }
       };
You can then bind different things to each:
Code:
initialBinding.whenPressed(new DoSomething());
secondaryBinding.whenPressed(new DoSomethingElse());
Then, to toggle which is enabled:
Code:
initialBindingEnabled = !initialBindingEnabled;
__________________
I code stuff.
Reply With Quote
  #3   Spotlight this post!  
Unread 17-03-2013, 23:08
shindigo shindigo is offline
Registered User
AKA: Mike Parker
FRC #0102
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2009
Location: Somerville, NJ
Posts: 33
shindigo is an unknown quantity at this point
Re: Reassigning button.whenPressed during teleop

Wow -that is some pretty snappy code! I have never seen the override of a get in a new before, but I'm a relative novice at java. Can any public method be overridden for an instance of a class in Java? I will give it a try tomorrow night.

Btw, do you have a link to the source of the wpilib? There are times when I would like to understand more about what is going on behind the scenes.

Thanks -

Mike Parker - programming mentor, team 102
Reply With Quote
  #4   Spotlight this post!  
Unread 18-03-2013, 18:45
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: Reassigning button.whenPressed during teleop

Quote:
Originally Posted by shindigo View Post
Wow -that is some pretty snappy code! I have never seen the override of a get in a new before, but I'm a relative novice at java. Can any public method be overridden for an instance of a class in Java? I will give it a try tomorrow night.

Btw, do you have a link to the source of the wpilib? There are times when I would like to understand more about what is going on behind the scenes.

Thanks -

Mike Parker - programming mentor, team 102
https://github.com/1684chimeras/2013...cedButton.java

lil something i made, allows you to assign different commands to different modes than set the mode of the button (e.g. set A to lock for drive, B for climb in climbing than set the mode of all the buttons to 2 when u want to climb)

Button source code is in C:\Users\yourname\sunspotfrcsdk\lib\wpilibj.src.zi p

to your override question.... Yeah you can override any public method. You can also use super.(method) to refer to the method that you were overriding
Reply With Quote
  #5   Spotlight this post!  
Unread 18-03-2013, 19:07
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Reassigning button.whenPressed during teleop

Quote:
Originally Posted by shindigo View Post
Can any public method be overridden for an instance of a class in Java?
In Java, you can override any non-final method, and anonymous classes (new ClassName() { /* stuff */ }) let you make individual variables with specific versions of methods, instead of having to make a new class every time you want to make a tiny change.

Quote:
Originally Posted by shindigo View Post
Btw, do you have a link to the source of the wpilib?
In the sunspotfrcsdk folder (which should be in your user directory), in its lib directory, there are wpilibj.src.zip and wpilibj.project.zip. The src one just has the source files, and the project one is a full netbeans project. The more complicated aspects of command-based programming are in edu.wpi.first.wpilibj.command and edu.wpi.first.wpilibj.buttons.
__________________
I code stuff.
Reply With Quote
  #6   Spotlight this post!  
Unread 22-03-2013, 07:16
shindigo shindigo is offline
Registered User
AKA: Mike Parker
FRC #0102
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2009
Location: Somerville, NJ
Posts: 33
shindigo is an unknown quantity at this point
Re: Reassigning button.whenPressed during teleop

Great! Thanks for the pointer!
Reply With Quote
  #7   Spotlight this post!  
Unread 22-03-2013, 12:59
JefferMC JefferMC is offline
Registered User
AKA: Jeff Corbett
FRC #1319 (Flash)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2005
Location: United States
Posts: 44
JefferMC will become famous soon enough
Re: Reassigning button.whenPressed during teleop

Quote:
Originally Posted by shindigo View Post
Great! Thanks for the pointer!
There are no pointers in Java.
Reply With Quote
  #8   Spotlight this post!  
Unread 22-03-2013, 21:09
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: Reassigning button.whenPressed during teleop

Quote:
Originally Posted by JefferMC View Post
There are no pointers in Java.
Yes there is. Not the type ur thinking of
Reply With Quote
  #9   Spotlight this post!  
Unread 22-03-2013, 22:54
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Reassigning button.whenPressed during teleop

Quote:
Originally Posted by JefferMC View Post
There are no pointers in Java.
Everything except primitives is a pointer in Java. You might prefer to call them references, but references are themselves just less flexible (and less dangerous) pointers.
__________________
I code stuff.
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