Mr. Wallplate’s Head Turns to Track You

by Tony--K in Circuits > Robots

1903 Views, 7 Favorites, 0 Comments

Mr. Wallplate’s Head Turns to Track You

Eyes2 0.jpg
Mr. Wallplate’s Head Turns to Track You

This is a more advanced version of Mr. Wallplate’s Eye Illusion Robot https://www.instructables.com/id/Mr-Wallplates-Eye-Illusion. An ultrasonic sensor allows Mr. Wallplate’s head to track you as you walk in front of him.

The process may be summarized as follows. The sensor first turns counterclockwise (left) 60 degrees, and then turns right while scanning for an object closer than 3 feet. If it doesn’t detect anything before it reaches 60 degrees right, it repeats the turning left and then scanning until it does detect an object. Then the head turns to face it, the sensor turns left to the left limit (-60 degrees), and scans again to the right. This head-turning and scanning continues until the object moves back farther than 3 feet or goes too far left or right. A more detailed summary of the program logic is in step #6.

This tracking method is not suitable for fast-moving objects, as is obvious from the video. There are some comments at the very end of this write-up, describing a different tracking method using several ultrasonic sensors.

The sensor motor is set to move at a fairly low speed. I tried faster speeds but they resulted in jerky movements that didn’t look good, and the tracking was not much faster.

An interesting point is that the sensor works best to detect objects with hard surfaces that reflect sound well. An object with a soft surface, such as someone wearing a thick sweater, may not be detected at all when too far away (more than about 3 ½ feet in my tests). When I held a piece of corrugated cardboard about 13”x20” in front of me and walked towards the sensor, it detected me about 8 feet away.

In the video,I purposely stayed about 2 ½ feet away as I moved to the side, in order to have the sensor and head point towards me. In tests at closer distances, the sensor pointed somewhat to its left, for the right edge of the sensor’s field of view detected my arm. The field of view is about 25 or 30 degrees.

The Mindstorms EV3 Software on a computer is used to generate a program, which is then downloaded to a microcontroller called an EV3 Brick. The programming method is icon-based, using Programming Blocks such as a Motor Block, Ultrasonic Sensor Block, Math Block, etc. Each Block has options and parameters. It’s very easy and versatile. Also, for testing purposes, when the Brick is connected to the computer and the program is running, the display on the computer shows in real time, the angle of each motor and the distance that the sensor is detecting an object. Furthermore, the mouse cursor may be positioned over a Data Wire in the program, and the value of that Data Wire (in real time) is displayed in a small window near the cursor. (A Data Wire is used to carry values from one Programming Block to another.)

Supplies

  1. LEGO Mindstorms EV3 set.
  2. LEGO Mindstorms EV3 ultrasonic sensor. It’s not included in the EV3 set.
  3. 2 round, plastic, take-out containers no less than 6 ¼ inches (16 cm) in diameter and 1 ¾ inches (4 ½ cm) high. Or, a tub of that same diameter and about 3 ½ inches high would also be okay.
  4. 4 #8 flathead bolts, 1 ½ inches (about 4 cm) long.
  5. 4 nuts for the bolts.
  6. 2 #6 roundhead screws, about ½ inch (1 cm) long, preferably the same colour as the take-out containers.

TOOLS:

  1. Drill and drill bits.
  2. Screwdriver.
  3. Scissors.

Motor for the Sensor

Eyes2 1A.jpg
Eyes2 1B.jpg
Eyes2 1C.jpg
Eyes2 1D.jpg

Place a large motor inside one of the take-out containers and mark where to drill 2 holes on the bottom. My containers have a circular indentation, and I decided to make the holes just inside it, so that the bolt heads wouldn’t stick out and make the unit wobbly.

Attach the motor using 2 bolts going up thru the holes, with 3-hole black LEGO elements to support the motor.

Using the scissors, cut a piece out of the back of the container to make space for the cables.

Attach the ultrasonic sensor to the motor using the 3 gray LEGO elements as shown in one of the photos.

Motor for the Head

Eyes2 2A.jpg
Eyes2 2B.jpg
Eyes2 2C.jpg

First, use the scissors to cut the vertical lip off the other take-out container, so that it will fit upside-down into the rim of the first container. The 2 horizontal rims will be attached later with screws, to keep the 2 containers firmly attached.

Place the other large motor on top of the upside-down take-out container, with the cable connection about ½ inch over the edge. This is necessary in order for the head to fit on the container properly. Mark and drill 2 holes for the 2 farthest holes of the motor.

Attach the motor using 2 bolts going up thru the holes, with 3-hole black elements to support the motor.

Using the scissors, cut a piece out of the side of the container, to make a gap about 4 ½ inches (11 cm) wide. This is needed for the ultrasonic sensor to stick out and move from side to side. The axle of the motor should line up with the middle of the gap.

Modify the Head

Eyes2 3A.jpg
Eyes2 3B.jpg
Eyes2 3C.jpg

Take the Mr. Wallplate head from “Mr. Wallplate’s Eye Illusion” robot, and remove the rear stand. It can be simply pulled off.

Referring to one of the photos, take 2 X-shaped black elements and 2 blue elements that have a cross-section like an “X” at one end and an “O” at the other end. Attach them to the bottom element on the head as shown. The head will slide around the container on them.

Attach the Head to the Motor

Eyes2 4A.jpg
Eyes2 4B.jpg
Eyes2 4C.jpg

Take the elements shown in the first photo (except for the long one) and attach them together as shown in the second photo. Then attach that near the bottom of the head as shown. This will support the head and keep it from nodding up and down.

Attach the motor to the holes under the lip-motor, using the long, gray X-cross-section element. Slide the element farther, to the support from the previous paragraph, as shown.

Connect the EV3 Brick to Mr. Wallplate

Eyes2 5A.jpg
Eyes2 5B.jpg

The flat cables in the EV3 set connect to the Brick as follows:

Port A: 14 inch (35 cm) cable to the small lip-motor.

Port B: 10 inch (26 cm) cable to the large motor for the head.

Port C: 14 inch (35 cm) cable to the large motor for the ultrasonic sensor.

Port 4: The longest cable to the ultrasonic sensor, with a loop near the Brick. The loop will allow the sensor to move better.

Check that the sensor is facing straight out from its container. You can turn the sensor motor by hand. Place the head assembly on top of the sensor container, so that the sensor is sticking out the middle of the gap. Drill 2 pilot holes thru both container rims about 1 inch past the edges of the gap. Drive the 2 screws thru these holes to keep the 2 containers firmly attached.

Description of the Program

The program logic is summarized below. I think steps #3 and #6 would probably be done differently in a program for a different system such as Arduino. LEGO Mindstorms EV3 is very useful and easy to use, but there are some limitations in what can be done. The only way of scanning that I could figure out, was to turn the sensor 10 degrees at a time and check if an object was being detected.

  1. Initialize: set variables to zero and wait 7 seconds.
  2. Turn the sensor counterclockwise (left), to the left limit (-60 degrees).
  3. Turn the sensor 10 degrees right.
  4. Has the sensor moved to the right limit (+60 degrees)?
  5. If yes, check if someone has been detected. If not detected, the sensor turns 120 degrees left and the program continues to the next step. If detected, then the person has moved away. The program says “Goodbye,” the head and sensor turn to face the front, and the program stops.
  6. Loop back to step #3 if the sensor sees nothing within 36 inches.
  7. This step is executed if the sensor detected something within 36 inches. Turn the head to face the detected person. If no one was detected previously, say "Hello."
  8. Loop back to step #2 to continue scanning. But if the loop is repeated 20 times, the program continues to the next step.
  9. Say “Game over.” The head and sensor turn to face the front and the program stops.

Build the Program

Eyes2 6 (2nd) Main program (1).jpg
Eyes2 7 (2nd) Initialize (1).jpg
Eyes2 8 (2nd) Turn sensor left to limit (1).jpg
Eyes2 9 (2nd) Turn head (1).jpg
Eyes2 10 (2nd) Finish (1).jpg

LEGO Mindstorms EV3 has a very convenient icon-based programming method. Programming Blocks are shown at the bottom of the display screen and can be drag-and-dropped into the Programming Canvas window to build a program. I built 4 “My Blocks”, which are mini-programs, like subroutines in regular programs. This made the logic of the main program in the screenshot easier to understand.

I couldn’t figure out how to set up downloading of the program to you folks, and so I’ve included screenshots of the program. The screenshots have comments describing what the Blocks are doing. It shouldn’t take much time for you to build it and/or change it to suit your needs. The screenshots are shown in the following order:

  1. Main program.
  2. “Initialize” My Block.
  3. “Turn sensor left to the left limit” My Block.
  4. “Turn head” My Block.
  5. “Finish” My Block.

When building this program, I would suggest the following:

  1. Build the “My Blocks” first.
  2. It’s important to work from left to right, and to enlarge the Loop and Switch Blocks before dragging other blocks inside. I ran into messy problems trying to insert additional Blocks inside the Loops during testing and refining of the almost-finished program.
  3. The larger Loop Block should be enlarged almost to the right edge of the Programming Canvas, before you start inserting Blocks. This is necessary in order to have plenty of space to drag the other Blocks inside. It can be made smaller afterwards.

Download the Program to the EV3 Brick

The EV3 Brick may be connected to the computer by either a USB cable, Wi-Fi or Bluetooth. When it’s connected and turned on, this is indicated in a small window in the lower right-hand corner of the EV3 window on the computer. Clicking the proper icon in the right-most side at the lower right-hand corner will download the program to the EV3 Brick and run it immediately.

After downloading, the EV3 Brick may be disconnected from the computer and the program may be initiated on the EV3 Brick.

CONCLUDING REMARKS

This was a fun project, and educational about the ultrasonic sensor. I hope you also find it interesting.

There’s another approach to scanning: Several ultrasonic sensors could be placed beside each other, fanning out at about 25 or 30 degrees from each other. The head could turn in the direction of whichever sensor detected an object. This method would detect a fast-moving object much better than the method described in the project above. However, the head would have only a small number of directions it would face. This method should be possible with Mindstorms EV3. The Brick has 4 sensor ports for up to 4 ultrasonic sensors (the programming requires a port number to be assigned for a sensor). More sensors could be accommodated by chaining a second Brick.

An idea to increase the number of positions for the head: If the sensors faced maybe 20 degrees apart, the fields of view would overlap, and 2 sensors would detect an object in the overlapped area. The head could then face in the overlap direction. I don’t know if this is possible; that is, if 2 sensors could detect an object in the overlapped area without their signals interfering with each other.