Motor Blocks in Loops
With our MegaPowUp series of blocks, we need to run a loop so that our Motor block is constantly ramping up in power. Once it reaches the limit, each loop will just keep it at the maximum. Sounds good, right? Well, when the motor block is being constantly looped like this, it creates problems.
Here, the PowerUp loop runs for the whole duration of the MyBlock. Each instance of the green Motor Block runs only as long as it takes for the loop to restart, so motor history is constantly forgotten. Our robot did not drive straight with this code.
With this new version of the MegaPowUp block, the robot actually stops looping the motor block once it either reaches maximum power or the block's ending condition is met - in this case, we just stop. If we've reached maximum power, but want to continue running, then we activate a new Motor block that starts once and only ends when the block ends. This makes the robot drive straighter.
Now, why don't we do anything like this in SuperPUDS? That constantly loops the motor block, right? There's two reasons why we don't.
- That's not something we can just do. The DS part of PUDS stands for DriveStr8 - and this block controls the steering for the Motor block by using a PID controller. For a PID to work properly, it must be constantly changing - so this block has to be in a loop, unless we just don't do DriveStr8 - but then we should just use MegaPowUp.
- We don't even need to - the loop isn't a problem. Since the steering in the block is controlled by a PID, the motor block's PID is irrelevant - another PID is already being used, and since it works properly when looped due to remembering history, we're fine keeping it looping.