Chapter 13. ANTY: the robotic ant

By now, you’ve gotten the hang of building models that move on wheels. Another fun, but slightly more challenging, kind of model you can build is an animal robot that uses legs to move instead of wheels. In this chapter, you’ll build and program ANTY (see Figure 13-1). ANTY is a six-legged, insect-like creature that walks around and responds to its environment by expressing different types of behavior based on what its sensors “see.”

The Infrared Sensor serves as ANTY’s eyes, allowing the robot to detect objects in its surroundings and to find food. The Color Sensor in the robot’s tail enables ANTY to detect changes in its environment. Different surroundings—that is, different colored objects—make the robot behave differently. Green objects give the robot a sense of safety, meaning it can take a nap. Red objects indicate danger, making the robot shake aggressively to scare off enemies. Blue objects scare ANTY, prompting it to run away. Finally, yellow objects make the robot hungry, causing it to start looking for food.

ANTY

Figure 13-1. ANTY

ANTY uses two motor assemblies to walk, each of which controls a set of three legs. Turning one motor forward makes the three legs connected to it step forward, as shown in Figure 13-2. Turning both motors forward simultaneously makes the whole robot walk forward.

But this works only if the legs on the left side are in the opposite position of the legs on the right side. For example, the left legs should be in position 2 when the right legs are in position 4 to ensure that there are always at least three legs in contact with the ground. This will happen when one motor is exactly 180 degrees ahead of the other. (The green dot in position 4 is 180 degrees ahead of the green dot in position 2.)

The robot uses the Touch Sensor to determine the absolute position of each motor so that the motors can be placed in opposite positions when the program begins. The robot knows that a set of legs is in position 1 when the Touch Sensor is pressed by a cam element, as shown in Figure 13-2.

After you’ve built the robot, you’ll make a My Block that places the legs on either side in the required position, after which the robot can start walking using Move Tank blocks. As long as both motors turn at the same speed, the motors will remain 180 degrees apart.

Now that you’ve learned a bit about the robot’s functionality, you’re ready to build it. Follow the directions on the next pages, but first select the pieces you need (see Figure 13-3).

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

You learned earlier that you make ANTY walk forward by having both motors rotate forward simultaneously, but only after the legs on either side are placed in opposite positions (180 degrees apart). You’ll create a My Block to place the right legs in position 1 and the left legs in position 3 (see Figure 13-2), using the fact that a motor presses the Touch Sensor with a cam element when it’s in position 1. You’ll use this block at the start of each program for ANTY.

Once the block completes running, Move Tank blocks will make the robot walk by turning both motors at the same speed to keep them in opposite positions.

Once the legs are in place, you make the robot walk forward using Move Tank blocks configured to rotate both motors forward at the same speed. The robot can turn left or right by rotating one of the motors backward. You can use these techniques to create an obstacle avoidance program.

Rather than using Move blocks in On mode, as when programming the EXPLOR3R, this program has the motors make four complete turns using On For Rotations mode. This movement is repeated until the Infrared Sensor’s proximity measurement drops below 50%. Then, the robot turns left by reversing the left motor and turning the right motor forward three rotations.

Create the ObstacleAvoid program using the instructions in Figure 13-5. Note that it’s necessary to rotate both motors at the same speed and for a fixed number of complete turns to ensure that the legs always end up in the original opposite position, ready to take more steps. If you program a movement that makes your motors end in a different position, you’ll need to run the Opposite My Block again to reset the legs.

Next, you’ll create the program that makes your robot express different kinds of behavior based on changes in its surroundings. We’ll start with the most complicated behavior—searching for food—so we can test this part of the program separately. When you’re ready, you’ll combine it with the robot’s other behaviors.

We’ll mimic the search for food by making the robot search for the infrared beacon. You’ll use the techniques you learned in Chapter 8. ANTY looks for the beacon, walks toward it, and stops once it’s found it. To accomplish this, the robot takes two steps to the left or to the right, depending on which side it sees the beacon, and then it takes two steps forward. It repeats this behavior until it sees the beacon up close, indicating that it has reached its destination.

Create the FindingFood program, as shown Figure 13-6. Once you’ve verified that your program works, turn the Loop block with its contents into a My Block called Find so that you can use it in your next program. (Don’t include the Opposite block in the Find My Block—you’ll place it elsewhere in the final program.)

The final program makes ANTY express different kinds of behavior based on the color it sees with the Color Sensor in its tail. For example, ANTY will take a quick nap when you hold a green object near the sensor, because the color green indicates the safety of a grass field.

Let’s begin by creating the basic structure of the ColorBehavior program. The robot should repeatedly check which color it sees and do something different in response to each color. You program the robot to do this with a Switch block in Color Sensor – Measure – Color mode that you place in a Loop block, as shown in Figure 13-7.

The switch has five cases: No Color, Green, Yellow, Blue, and Red. The default case is No Color, so the blocks on this tab will run when black, white, or brown is detected. The next step is to add blocks to each tab of the switch.

You can use the EV3 to build not only vehicles and machines but also robotic animals and creatures. In this chapter, you built ANTY, a six-legged walker. You learned how to make it walk with two Large Motors combined with the Touch Sensor to detect the absolute position of each motor.

In addition to building a walking robot, you created a program that controls your robot’s behavior, so that ANTY would perform different actions based on sensor input to imitate the behavior of a real animal.

Now try some of the Discoveries to explore this robot design further. What cool creatures will you make?