Chapter 12. Formula EV3: a racing robot

Now that you’ve learned how to program the EV3 to control motors and sensors, you can begin making more sophisticated robots, such as autonomous vehicles, robotic animals, and complex machines. This chapter presents the Formula EV3 Race Car, shown in Figure 12-1.

Unlike the EXPLOR3R you built earlier, the race car uses three motors. Two Large Motors in the rear make the car drive, while the Medium Motor lets you steer the front wheels. Think of the rear motors as the car’s engine and the motor in the front as the car’s steering wheel.

The Formula EV3 Race Car

Figure 12-1. The Formula EV3 Race Car

Once you’ve built the race car, you’ll create several My Blocks to make it easy to program the car to drive and steer. Then you’ll combine these blocks in one program that lets you control the car remotely and another program that makes the robot drive around autonomously and avoid obstacles. Finally, you’ll be challenged to add more functionality to the design and to make it race faster using gears.

Build the race car by following the instructions on the subsequent pages. Before you start building, select the pieces you’ll need to complete the robot, shown in Figure 12-2.

image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption
image with no caption

The Formula EV3 Race Car uses two separate mechanisms to drive and steer. To drive the car, you switch on the Large Motors in the rear. You can steer the car by turning the front wheels to the left or to the right with the Medium Motor in the front. When you combine driving and steering in one program, you can move the car in any direction.

In a moment, we’ll create some custom My Blocks that will make it easy to program the Formula EV3 Race Car to steer in different directions. But first, let’s have a look at how the steering mechanism works. Your program will use the Rotation Sensor inside the Medium Motor to accurately control the orientation of the front wheels, which determine the direction in which the robot will drive.

To see how this works, use your hands to set the front wheels in the centered position, as shown in Figure 12-3. Then, go to Port View on the EV3 brick, and observe the Rotation Sensor value (port A) as you manually steer the front wheels to the left and to the right. You’ll find values around 60 degrees for the left, 0 degrees for the center, and −60 degrees for the right. Note that these angles indicate the position of the motor. The wheels turn left and right by a smaller amount because of the gears in the steering mechanism.

As shown in Figure 12-3, the Medium Motor should move toward the point where the sensor measures 60 degrees in order to make the robot steer left. To steer right, it should move toward the −60 degree measurement, and to drive straight ahead, it should move back to 0 degrees. You’ll make three My Blocks, called Left, Right, and Center, to put the wheels in each of these positions.

These blocks will work only if the sensor value is 0 degrees when the wheels are centered. Because you don’t want to center the front wheels manually each time you run the program, you’ll make another My Block, called Reset, to do this for you. This My Block centers the wheels and sets the Rotation Sensor value to 0. You’ll place it at the start of each program for this robot.

Before you create a complete program, you should test the My Blocks to see whether they work as expected. Create the SteerTest program shown in Figure 12-8 and run it. The front wheels should automatically line up with the rear wheels when the Reset My Block runs. Next, they should turn to the left, to the right, and then back to the center.

Now that you’ve created My Blocks for the steering mechanism, it’s easy to create a remote control program using the techniques you learned in Chapter 8. Your next program makes the car drive in all directions as you press the buttons on the infrared remote, as shown in Figure 12-9. For each of the button combinations, the robot runs one of the My Blocks to steer the front wheels and a Move Tank block to power the rear wheels.

You use Move Tank blocks so you can choose the speed of both motors separately. If the robot goes straight forward or backward, both wheels turn at 75% speed. When turning, the outermost wheel should go slightly faster than the inner wheel, so you’ll make the faster wheel drive at 80% speed and the slower wheel at 70%.

A negative speed value, such as −75, makes the robot go forward due to the orientation of the motors in this robot. Positive values, such as 75, make the robot go backward. Now create the RemoteControl program using Figure 12-10.

Note

If the robot does not drive in a straight line when driving forward, adjust the degrees value in the Medium Motor block in the Reset My Block shown in Figure 12-4. Try a value slightly larger than 78 degrees if you see a deviation to the left; try a smaller value if the robot deviates to the right.

Now you’ll create a program to make the race car drive around your room autonomously, avoiding obstacles with the Infrared Sensor. The robot begins by driving straight forward until the sensor detects a proximity value below 70%. Then, the robot reverses and steers left to move away from the obstacle. Finally, the robot centers its wheels so that it can drive straight forward in a new direction. Create the AutonomousDrive program, as shown in Figure 12-11.

In this chapter, you had a chance to build and program a robot from instructions. This is, of course, a lot of fun, but it’s even more fun to create your own robot designs. For example, you could expand the design with gears or larger wheels to make the car faster, or you could turn the robot into a completely different vehicle, such as a passenger car or an off-road vehicle.

Don’t worry if you don’t succeed on the first try; you’ll gain more and more building experience as you continue to try new designs. Try out the Design Discoveries at the end of this chapter to get started, and be sure to use the techniques you learned in Chapter 10 and Chapter 11.