|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Java Command Based Command
New to Command Based... We are about to start coding the commands for each subsystem and before we get too far, we need the following info on how to handle multiple commands...
For example, we have a feeder motor... we want a command to FeederOn(clockwise), FeederOnRev(counterclockwise) and FeederOff... We created a Feeder_Command class... Code:
public class TeleopFeederOn_Command extends Command{
@Override
protected void execute(){
while(Robot.oi.getOperatorJoystick().getRawButton(4) ==true){
Robot.fuelFeederSubsystem.FeederOn();
}
Robot.fuelFeederSubsystem.FeederOff();
}
@Override
protected boolean isFinished() {
// TODO Auto-generated method stub
return false;
}
@Override
protected void end() {
Robot.fuelFeederSubsystem.FeederOff();
}
@Override
protected void interrupted(){
end();
}
}
|
|
#2
|
||||
|
||||
|
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:
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()); 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. Last edited by otherguy : 03-02-2017 at 22:34. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|