Motion tracking skull Halloween prop
If you read Grant’s Creepy eyes Halloween prop post, then you already know that several of us here at Pololu are working on Halloween projects. I based my project on a motion tracking Halloween prop tutorial by Jason Poel Smith that I saw last year on the Make magazine website. The concept is simple: make a Halloween prop mysteriously follow an unsuspecting person as they walk by. The tutorial by Jason Smith uses photoresistors to track a person by detecting their shadow and moving a servo with a Halloween prop attached to it. This works well, but there are a few things that I thought could be improved. For example, the photoresistors placed in specific locations give discrete positions for the servo to turn to, which results in a jerky motion that appears as if the prop is moving in steps instead of smoothly following a person as they walk by. Another problem is that photoresistors are dependent on lighting, so this setup can only be used in well lit (or strategically lit) areas, and I wanted to be able to use this prop in a dimly lit hallway (this is for Halloween after all, right?).
Both of the aspects of the original tutorial I wanted to improve came from the use of photoresistors, so I decided to swap them out for two Sharp GP2Y0A60SZ analog distance sensors. These sensors can be used to detect the distance to an object up to around 5 feet away. I used the Micro Maestro as the main controller, because the Maestro makes it easy to read the analog outputs from the sensors and control the servo. Hot glue was used to attached the Sharp distance sensors and servo horn to the skull, which was made of Styrofoam. Using a light-weight prop made of Styrofoam allowed me to use a small Power HD Mini Servo. My batteries, Micro Maestro, and mini servo were all mounted to a scrap piece of clear acrylic using double-sided tape, and our Premium Jumper Wires were used to make the necessary electrical connections (though servo cables would have worked well for this, also). Finally, I wrote a Maestro script (copied below) to compare the analog signals from the Sharp distance sensors and turn the servo toward whichever sensor was detecting something closer. The GIF below is an example of the result:
The motion tracking skull following someone walking in front of it.
6000 #initial position dup 0 servo #initialize servo 5000 delay #delay for set up purposes begin #take the difference between the two analog signals 1 get_position 2 get_position minus #compare the difference to a threshold and update servo #position if it is within the limits (900us - 2200us) dup -140 less_than if swap dup 3600 greater_than if 5 minus swap else swap endif endif 140 greater_than if dup 8800 less_than if 5 plus endif endif dup 0 servo #update servo position repeat
Complete parts list
Here is a list of all the parts I used to make this project (many of which are on sale until Oct. 22, 2014 for our Polo-BOO! Halloween Sale)
- Micro Maestro USB Servo Controller
- Power HD Mini Servo HD-1711MG
- Sharp GP2Y0A60SZ analog distance sensors
- 4-AA battery holder
- NiMH AA batteries
- Premium Jumper Wire 50-Piece Rainbow Assortment F-F 6″
- Styrofoam skull
- Ping pong eyeballs
- Scrap acrylic
The motion tracking skull still has plenty of room for improvement, such as coming up with a clever and festive way of hiding the electronics, adding LEDs for lighting effects, or maybe even adding a sound module like the MP3 Trigger for an extra scare. The whole prop currently only uses 3 of the 6 channels on the Micro Maestro, so it is possible to use one Micro Maestro to control two independent motion tracking props. I haven’t decided what I want to add to it yet, but I plan on continuing to improve it as Halloween approaches. The script that I used is simple right now, and while it works, it can probably be improved to get even smoother motion, so I can continue to work on that as well.
Las Vegas Mini Maker Faire 2016 update
We recently attended the 2016 Las Vegas Mini Maker Faire, and I decided to revisit this motion-tracking skull prop for a demonstration. When I first brought the prop to the LVBots Halloween Hack Night back in 2014, I noticed that the first instinct people had (especially kids) was to try to walk fast enough that it could not keep up with them, so I wanted to make it more reactive, and still keep it simple, so I used proportional control. The updated code (shown below) uses the difference of the sensors as an error value since the two sensors would ideally output the same analog voltage when the object is the same distance from each of them. The error is then multiplied by a proportional coefficient (1/40 worked pretty well in my tests) and added to the target position. A larger error results in a larger correction, making the prop harder to outrun.
6000 #initial position dup 0 servo #initialize servo 5000 delay #delay for set up purposes begin #calculate the error (the difference between the two analog signals) 1 get_position 2 get_position minus #multiply the error by a proportional coefficient #(1/40 worked well for me) and add the stored target #position to the offset inferred from sensors 40 divide plus #make sure the target position stays between the limits #if outside a limit, overwrite the target with the limit dup 4000 less_than if drop 4000 endif dup 8000 greater_than if drop 8000 endif #the target position is being stored on the stack, so duplicate it and update servo position dup 0 servo repeat
If you try making this prop, one thing to keep in mind is that you should check that your signs are right. Some servos will turn counterclockwise when the pulse width is lower than 1.5 ms and some will turn clockwise, so you will probably have to do some testing. A sign error will produce unstable, positive feedback; if your motion tracking prop is turning away from the object instead of toward it, you might have a simple sign error.