View Single Post
  #2   Spotlight this post!  
Unread 03-02-2017, 22:27
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 446
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Java Command Based Command

If you want a button to execute a command you should be doing this in the OI class.
See here for an example: https://wpilib.screenstepslive.com/s...joystick-input

Basically:
  • create a command for each of your actions (or one that takes in a parameter for the "speed" to pass on to the motors).
  • In OI, you link the command to execute to a Joystick action on a button (e.g. WhenPressed, WhileHeld, etc.).
  • the execute method of your command is just going to call in to the subsystem it requires and call the right setter method that ultimately calls someMotorName.set(speed).

To specifically address your code example, get rid of everything except "Robot.fuelFeederSubsystem.FeederOn();" in the execute method. Then add something like the following to the OI class:
Code:
Joystick myJoystick = new Joystick(0);
Button aButton = new JoystickButton(myJoystick, 5);

...

aButton.whileHeld(new TeleopFeederOn_Command());
Check the Javadoc for Button to see understand what the different methods for button presses (whileHeld, whenPressed...) do.

The guides for command based programming on screensteps live are pretty good. You could also use RobotBuilder to generate some example code to see what the "right" way to do it is. And there's also lots of example code out there to pull from.
__________________
http://team2168.org

Last edited by otherguy : 03-02-2017 at 22:34.
Reply With Quote