Consider an arm that's going to throw something. When it first starts up, it needs to initialize, and then it waits. When it throws, it needs to launch a process, and then waits for a signal that throwing is complete, and then retracts. It then waits for the next throwing command.
This is typed in code that's mostly Java, but not compiled or tested.
An enum that represents your states.
Code:
public enum State {Initializing, Waiting, StartThrowing, Throwing, StartRetracting, Retracting}
then in your logic
Code:
public State state;
...
// This switch is run repeatedly, either in a while loop if you're in an iterative robot or as part of a command in the command based robot.
switch (state)
{
case Initializing:
// Do whatever one time initialization logic here
state = Waiting;
break;
case Waiting:
if (arm_is_triggered) { // however you're triggering the arm
state = StartThrowing;
}
break;
case StartThrowing:
// Do whatever one-time logic needed to start throwing -- e.g., open solenoid
state = Throwing;
break;
case Throwing:
if (done_throwing) { // however you're detecting throwing is done -- e.g., limit switch, timer
// do whatever's needed to stop throwing
state = StartRetracting;
}
break;
case StartRetracting:
// Do whatever is needed to start retracting
state = Retracting;
break;
case Retracting:
if (done_retracting) {
// do whatever's needed to stop retracting
state = Waiting;
}
break;
default:
printf("Unknown state!\n");
break;
}