Aiming the turret

The robot will now use the second infrared sensor, IR 2, to aim the turret in the direction of the beacon. We will use proportional logic to control the aiming of the turret, just as we did for the driving. The heading value measured by IR 2 is multiplied by a k value and will set the target power for motor D, the motor responsible for rotating the turret.

We are going to start this new segment of programming directly after the proportional beacon follower we just wrote. Make sure the new code blocks are still within the switch block. Add a new infrared sensor block with its mode set to Measure | Beacon. This time, the port should be set to 2.

Add a math block set to multiply after the new IR sensor block. As before, this ...

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.