Here is what the above would look like in Java:
Code:
public class MyMotorSubsystem extends Subsystem {
ControllerType myMotor;
public MyMotorSubsystem () {
myMotor = new ControllerType(RobotMap.ID_MY_MOTOR);
}
public void setMotor(double value) {
myMotor.set(value);
}
}
Command to run the motor.
Code:
public class CommandBase extends Command {
public static MyMotorSubsystem myMotorSubsystem;
public static void init() {
myMotorSubsystem = new MyMotorSubsystem();
}
}
public class RunMotorCommand extends CommandBase {
JoystickButton runMotorButton;
public RunMotorCommand(JoystickButton runMotorButton) {
this.runMotorButton = runMotorButton;
runMotorButton.whenPressed(this);
}
void initialize() {
requires(myMotorSubsystem);
}
void execute() {
myMotorSubsystem.setMotor(1.0);
}
boolean isFinished() {
return !runMotorButton.get();
}
void end() {
myMotorSubsystem.setMotor(0.0);
}
void interrupted() {
myMotorSubsystem.setMotor(0.0);
}
}
Create an instance of the command
Code:
// somewhere in OI.java
new RunMotorCommand(new JoystickButton(myJoystick, something));
My team does not use the CommandBase, and we usually instantiate subsystems in the Robot.java file, so I am not 100% sure this is right, but the basic idea should be apparent. Basically, create a command that in the execute will call a method from a subsystem that sets the motor to the value you want, which is triggered by a button and will end when that button isn't pressed.