Re: FTC Autonomous Aritificial Intelligence State Machines
By definition, state machines can remember their states. So when an operation takes a long time (e.g. drive forward 4 ft), instead of doing a "busy wait" loop just waiting for the drive to complete, a state machine just remembers the state and returns to the caller so that some other stuff can get done while the robot is driving forward. For example, without the state machine, the code may look like this:
Notice all the functions in this code have either busy wait loops or wait1Msec() statements. That means they don't return until the operations are completed. This is perfectly fine for a simple autonomous. However, imagine if you want to go park on the ramp after dumping the block and you are running out of time, you may want to do things in parallel to save some seconds. For example, there is no reason why you can't raise the shoulder and drive forward at the same time. How do you do that and still maintain the relatively simple looking main code? The answer is using a state machine.