@jwakeman: your issue appears to be that your alternate condition was causing a new command to be created every iteration. This would cause a new command to be created, assigned to the button, and interrupt the old each iteration.
I haven't tried this code, but the pattern I used was like this:
Code:
<in class definition>
Command *mainCommand;
Command *altCommand;
<in constructor>
mainCommand = new MainCommand();
altCommand = new AlternativeCommand();
<in periodic function within the same class>
if (condition)
{
button->whenPressed(altCommand);
}
else
{
button->whenPressed(mainCommand);
}
This way, you have only have one instance of each command that can be assigned to the button.
I put this code in the OI class, and added an UpdateOI function, which is called from the teleop periodic loop.