Scheduling a command in the End() method of the current command causes an endless loop calling End() of the same command repeatedly.
How should one command schedule another command following the current command. Note that a command group is not feasible as the first command has to be cancelled (by the driver) in order to stop. That is there is not an automatic IsFinished() on the first command.
The first command constructs the following command in it’s constructor. Then calls mCommand.Schedule() in the End() method of the first command.
We are using ToggleWhenPressed on a Joystick button. So the first press starts the command and the second press cancels the command. Pretty convenient.
Other suggestions?
Still interested why scheduling a command is an endless loop.
It sounds like you’re setting up a toggle switch so one command or the other is always running. This should work if you made the “second command” the default command for the subsystem. It will run whenever the other isn’t.
Added: I believe end() is being called repeatedly because starting the second command cancels whatever command is already using any of the subsystems needed, which is - your first.
I spoke before testing. While the first command ends, the robot crashes before the second (end) command is run. There’s clearly a data structure out of sorts (invalid iterator).
We’re trying the default command solution as well as WhenFinished decorator.
With regard to the decorators (e.g. WhenFinished(), which is not actually implemented ),
The decorators are just returning a convenient SequentialCommand. Cancelling the command is still going to cancel the entire sequential list of commands. We want to cancel the current running command and then complete with some additional commands.