Program the return-to-center (right side)

If the turret has strayed too far to the right (motor D has > | 250 degrees), the tank will need to make a sharp right turn to center the beacon within its line of sight again and center the turret. We will add some programming in the true case of our new switch that will do just that.

First, add a medium motor block and set it to turn motor D off. This case executes when the turret starts to rotate too far, so we need to stop it to make sure it does not over-rotate.

Next, the tank will make its sharp right turn. We will use the move tank block, which allows us to individually control the power of both drive motors (port B + C). Set its mode to On for Seconds. Set the power of motor B, the left drive ...

Get Building Smart LEGO MINDSTORMS EV3 Robots now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.