The amount of time the BOE Shield-Bot spends rotating in place determines how far it turns. So, to tune a turn, all you need to do is adjust the delay function’s ms parameter to make it turn for a different amount of time.
Let’s say that the BOE Shield-Bot turns just a bit more than 90° (1/4 of a full circle). Try delay(580), or maybe even delay(560). If it doesn’t turn far enough, make it run longer by increasing the delay function’s ms parameter 20 ms at a time.
The smallest change that actually makes a difference is 20.
Servo control pulses are sent every 20 ms, so adjust your delay function call’s ms parameter in multiples of 20.
If you find yourself with one value slightly overshooting 90° and the other slightly undershooting, choose the value that makes it turn a little too far, then slow down the servos slightly. In the case of rotating left, both writeMicroseconds us parameters should be changed from 1300 to something closer to 1500. Start with 1400 and then gradually increase the values to slow both servos. For rotating right, start by changing the us parameters from 1700 to 1600, and then experiment with reducing in increments of 10 from there.
Your Turn – 90° RotatingTurns and Sketch Updates
- Modify ForwardLeftRightBackward so that it makes precise 90° rotating turns.
- Update the label on each servo with a notation about the appropriate delay function ms parameter for a 90° turn.
- Update the delay function ms parameters in ForwardLeftRightBackward with the values that you determined for straight forward and backward travel.
Carpeting can cause navigation errors.
If you are running your BOE Shield-Bot on carpeting, don’t expect perfect results! The way the carpet pile is laying can affect the way your BOE Shield-Bot travels, especially over long distances. For more precise maneuvers, use a smooth surface.