OUCH

by MaxZorn in Circuits > Raspberry Pi

456 Views, 2 Favorites, 0 Comments

OUCH

ouch_video
DSC05175.JPG
machine.png

Ouch is your personal Omnidirectional Useless Cataract Helper. As facial recognition hits the Zeitgeist, OUCH hits you! OUCH does not only know how you look like, it also knows how to be very annoying! Unlike big brother, this machine is very visible and fulfils only one purpose: To make your life a tiny bit shittier. Did you ever forget your sunglasses at home and got surprised by a bright reflection? OUCH lets you relive this moment over and over again. By reflecting light from the brightest light source around you straight in your face, it will make sure that you won't enjoy a single moment around it.

Watch out, or OUCH might be the last thing you'll ever see!

The project was conducted as part of the Computational Design and Digital Fabrication seminar in the ITECH masters program.

August Lehrecke | Max Zorn

Supplies

Electronic Parts:

Arduino

  • Arduino UNO

Raspberry Pi


3D Printed Parts:

OUCH's come in various shapes and sizes. For this version, we used a 3D printer to print custom mechanisms.

  • 4 x Stand
  • 2 x Base S
  • 1 x Base L
  • 2 x Rotation Base Double
  • 1 x Rotation Base Single
  • 1 x Set of Axis Support S
  • 1 x Set of Axis Support M
  • 1 x Set of Axis Support L
  • 1 x Camera Mount
  • 1 x Light Mount
  • 1 x Mirror Mount

Optionally you can use the provided Tower design, to meunt the components to:

  • 1 x Tower (instead of 4 x Stand)
  • 1 x Base S & 1x Base M (instead of 2 x Base S)

Other Parts:

  • Mylar
  • 1 x Rubber band
  • 1 x Zip tie
  • 12 M5 x 160 Flathead Screws
  • 2 M5 x 80 Flathead Screws


Tools:

  • 3D Printer
  • H3.0 Screwdriver
  • Hot Glue Gun

Step 1: Printing the Parts

If you have access to a 3D printer, you can print custom mechanisms to house the Servos and mount the three main components.

For the Face component, we need:

  • 2 x Stands
  • 1 x Base L
  • 1 x Rotating Base Double
  • 1 x Set of Axis Support M
  • 1 x Camera & Distance Sensor Mount

The Light component requires:

  • 1 x Stand
  • 1 x Base S
  • 1 x Rotating Base Double
  • 1 x Set of Axis Support S
  • 1 x Light Mount

The Mirror components consists of the following:

  • 1 x Stand
  • 1 x Base S
  • 1 x Rotating Base Single
  • 1 x Set of Axis Support L
  • Mirror Mount

Lastly, you can also print the provided tower.

If you want to use it as the base for all three components, you will have to adjust the vector math in the code accordingly. Further, connect the Face component with Base M instead of Base L to the tower.

Step 2: Making the Mirror

mylar_mirror_parts1.JPG
mirror_component.JPG

To make your own Mirror component, cut a circular piece of Mylar and place it on top of the 3d printed mirror part. Then first use a rubber band to fix it in place. The rubber band should fit inside the groove around the component. Then use a zip tie to gently secure the connection, do not tighten it too much, yet. Now you can start stretching the Mylar until you get a shiny, mirroring surface. Lastly, tighten the zip tie and enjoy the reflection of your beautiful face!

Step 3: Assembling the Components

Face_Exploded_2_inst-01.png
board.jpg
Light_Exploded_2_inst-01.png
connector.png
Mirror_Exploded_2_inst-01.png
DSC05109.JPG
DSC05115.JPG

Face Component

  1. Hot glue the fist Servo in the according cut-out of the rotating base
  2. Glue the Servo connector into the groove, located at the bottom of the base part
  3. Put the two base parts together, so that the Servo interlocks with the connector
  4. Use the Servo's screw to fix the connector to the Servo
  5. Hot glue the second connector piece into the according groove, located at the top of the axis support
  6. Use 4 M5 bolts to screw the axis support to the rotating base
  7. Hot glue the second Servo to the mount
  8. Slide the camera on the pins
  9. Attach the ultrasonic distance sensor to the mount, either via screwing or hot gluing
  10. Connect the camera / sensor mount to the axis support, the Servo again has to slide into the connector piece
  11. Use the Servo's screw to fix the connector to the Servo
  12. Screw the Raspberry Pi and the servo driver to a piece of plywood (Make sure the spacing matches the holes of Base L)
  13. Screw the Face component to the stands, using M5 bolts

Mirror Component

  1. Follow steps 1 to 7
  2. Connect the Mirror to the axis support
  3. Glue a mirror stand to plywood, so that the Mirror and Face component are aligned
  4. Screw the Mirror component to the stand, using M5 bolts

Light Component

  1. Follow steps 1 to 7 from above
  2. Thread the light sensors through the mounting holes at the bottom of the shading cross
  3. Connect the shading cross to the axis support, the Servo again has to slide into the connector piece
  4. Use the Servo's screw to fix the connector to the Servo
  5. Glue a stand to plywood, so that the Light, Mirror and Face component are aligned and the Mirror is between the Face and Light components
  6. Screw the Face component to the stands, using M5 bolts

*All components could also be attached to the tower, please consider the increased coding and wiring complexity and printing time, though. If you want to use the tower, use the Base M part instead of the Base L for the Face component and screw the Base parts to the tower using the eyelets and M5 bolts.

Step 4: Configure the Boards

FaceTracker_bb.jpg
IMG-5455.jpg
IMG-5456.jpg

Here is the wiring diagram for the three components. The sun tracker acts on its own loop on the Arduino and sends its servo positions to the Rasberry Pi via the serial USB port. An optional distance sensor can be hooked up to the front of the pan/tilt piCamera to create a more robust triangulation of the target. Here we will be lining them up in a straight line and just averaging the vectors so it is not required.

Four servos are hooked up to to the PCA9685 servo driver which is powered by an external 5v power supply. Two of the servos control the pan and tilt for the face tracking camera, while the remaining two, control the pan and tilt for the mirror.

The Code:

sunTrack.jpg

The Code for this project can be broken down into two parts: The Arduino light-tracking code and the python face tracking/mirror positioning code.

Arduino Code:

This code is a slightly modified version of the sun tracking project from geobruce. It is a great reference for finding out more about the solar tracking component and more details can be found on this instructables page. Light intensity values are taken in from the 4 photo-resistors and averaged to find the brightest area and adjust the servos accordingly. We then write out the servo angle values to the serial port.

Python Code:

This code integrates open CV to create a face tracking pan tilt mechanism as well as drives the servos for the mirror. You will have to go through some steps to download open CV on your Raspberry pi. There are many resources for this but I very much like the one by pyimagesearch. A full walk through of this process can be found here. Note: We have downloaded the open CV libraries into a virtual environment which we run all of the code on, if you decided to do this make sure that you download all of the dependencies into the virtual environment that you are running the program on and not the Pi itself.

Once you have downloaded open CV this code will also require some more dependencies (installed on the specific environment you are running) to run:

  • Adafruit ServoKit: A full page on the process for downloading on the raspberry Pi can be found here.
  • imutils
  • numpy
  • gpiozero (if using distance sensor)

For the face tracking, the script requires an argument (--faces) which is an .xml file that openCv uses to find faces. You will have to put this file in the same directory as the python script. I have provided it in the downloads and it can also be found here.

Running the Code

2020-07-19-120713_1920x1080_scrot.png
2020-07-19-120808_1920x1080_scrot.png

Once you have all of the code downloaded in the same directory and set up your virtual environment with open CV, you are ready to run it.

  1. Open the command prompt on your pi
  2. Type workon cv (or whichever name you chose for your virtual environment)
  3. Change the directory to where you have you files stored (cd (path to files))
  4. The last line runs the program and specificies the haar cascade file. (python Face3.py --faces haarcascade_frontalface_default.xml)

When you run it you should see a video stream from the picam pop up on the screen and the command prompt will start printing out the servo values from all six servos.

And you are done! Depending on the quality of servos that you have, you may want to calibrate them each specifically to improve the accuracy of your system. We ended up having to tweak all of the PWM ranges in order for them to work properly.