Introduction to Commands
Why Commands?
Commands represent actions the robot can take. Commands enforce structure into how we tell the robot to make it more predictable. All commands share the same structure so once you learn that structure you will be able to write complex actions with the simple building blocks of Commands!
The 4 Parts of a Command
Basic commands have 4 components that are related to the action desired.
Initialize
The Initialize method is called only once at the beginning of the command
Execute
the execute method is called every periodic cycle (every 20ms) code you put in here is run over and over again until the command is finished.
isFinished
the isFinished method is where we determine if the command should be finished it is also run every periodic cycle (every 20ms). Some commands we want to run until another command needs the subsystem and therefore we will return false. Others run until a condition is met and that logic is put within the isFinished method to return true when the command is supposed to end
End
This method is called at the End of the command once isFinished is True or another command needs the subsystem. Here we often set things back to the way they were before the command ran.
Practice
First write out what you want the robot do so using template
First _________, then do ___________, Until ________, Finally do ________
For example if I want the robot to score a game piece from the claw it could be
First Set claw motor to spit, then do ___________, Until Claw no longer sees game piece, Finally do set claw motor to zero
Requirements
What if I asked you to type an essay and juggle? You cant because you would need your hands to only be doing one. The same is true for the robot we cannot ask the same hardware to do 2 things at once.