Originally posted by dbreise2017
View Post
Let me try to explain why a state machine can make this situation better. Let's say you have task A, which is your drive loop and is polling your IMU, reading an encoder, and setting motor powers. You also have task B running, which is polling, say, your lift encoder, waiting for it to come all the way down before turning off the lift motor. In this case, task A takes about 22ms, but task B takes only 3ms. This means that task B will try to run many, many times while task A hasn't even gotten through one iteration yet! But if both tasks are run using a cooperative multitasking through a state machine, then each task will get run in series, and both A and B will get an iteration done every 25ms or so.
Leave a comment: