You are going to want an add 2 limit switches (DigitalInputs) and 1 motor (Talon, Jaguar, Victor) to a subsystem.
Solution A
Create a command WaitForLimitSwitch1. The only method requiring code would be the isfinished() method. Return limitSwitch1.Get();
Create a command WaitForLimitSwitch2. The only method requiring code would be the isfinished() method. Return limitSwitch2.Get();
Create a command to turn the motor on forward.
Create a command to turn the motor on backwards.
Create a command to stop the motor.
Create a command group and add sequentially:
--TurnMotorOnFwdCommand
--WaitForLimitSwitch1Command
--TurnMotorOnRevCommand
--WaitForLimitSwitch2Command
--TurnMotorOffCommand
Assign command group to a joystick button.
Solution B.
Create one command and implement a state machine. Use a class member called state. Perform the actions in the execute method. Always be checking if a limit switch is pressed and if it is then increment the state. ex.
Code:
private int state = 0;
bool isFinished() {return state == 3;
}
void execute() {
if state == 0 {motor->set(1);
if limitSwitch1.get() {state = 1;
}
}
if state == 1 {motor->set(-1)
if limitSwitch2.get() {state = 2;
}
}
if state == 2 {motor->set(0);
state = 3;
}
}
Assign command to a joystick button.