Close

Step 10. All Hardware and Software Updated: UV Rerflector & OpenCV

A project log for UV Sanitizing Autonomous Robot

Cost-effective robotic solution for surface sanitization in home

Guillermo Perez GuillenGuillermo Perez Guillen 10/11/2021 at 17:340 Comments

This is a nice project and I have updated it. Below you can see the particular goals:

Notes: 

UV Reflector

We will print several parts that will be used to assemble UV Reflector with the "4WD Robot Car" chassis. In the figure below I show you the image of UV Reflector holder - part 1.

And the UV Reflector holder - part 2.

Below I show you the piece that helped me to make the UV reflector (you must print 4 pieces and cover them with aluminum foil).

Below, I show you all the assembled parts. Note: Fix the servo as shown in the picture.

Finally, below I show you how to mount the UV reflector on the chassis of the autonomous robot.

Close-up of the image where we can see the Arduino Pro Mini board

Mounting the Raspberry Pi camera.

A view from the opposite side we can see the Raspberry Pi board.

OpenCV

A nice tutorial for installing OpenCV on my Raspberry Pi is: https://pimylifeup.com/raspberry-pi-opencv/

The steps to make the classifier are shown below:

Notes:

Schematic Diagram

Now, we must assemble our schematic diagram as shown in the figure below.

I also made my own cable for connections between Raspberry Pi, Arduino board and the battery:

Codes:

On my Raspberry Pi board, I must run the next code: uv_autonomous_robot.py

# AUTHOR: GUILLERMO PEREZ GUILLEN
# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import serial
import struct
a=0
b=0
x1=0
y1=0
ser = serial.Serial('/dev/ttyUSB0',9600)

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))

#Load a cascade file for detecting faces
backless_stool_cascade = cv2.CascadeClassifier('backless_stool.xml')

# allow the camera to warmup
time.sleep(0.1)
count = 0

# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
        image = frame.array
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        backless_stool = backless_stool_cascade.detectMultiScale(gray, 1.3, 5)
        for (x,y,w,h) in backless_stool:
                a=int((2*x+w)/2)
                b=int((2*y+h)/2)
                x1=int(a/3.66)
                y1=int(b/2.55)
                ser.write(struct.pack('>BB', x1,y1))
                cv2.rectangle(image, (x,y), (x+w,y+h), (255,0,0), 2)
                count += 1
        # show the frame
        cv2.imshow("Frame", image)
        key = cv2.waitKey(1) & 0xFF

        # clear the stream in preparation for the next frame
        rawCapture.truncate(0)

        # if the `q` key was pressed, break from the loop
        if key == ord("q"):
                break

This code finds the horizontal and vertical position of the first vertex of the object (backless stool). Then I send the data through the serial port (ttyUSB0) to the Arduino board. On my Arduino Pro Mini board, I must load the next code: arduino_pro_mini.ino

// AUTHOR: GUILLERMO PEREZ GUILLEN

#include <Servo.h>
int data_x = 0;
int data_y = 0;
int data[1];
Servo myservo_x;
Servo myservo_y;// create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo_x.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo_y.attach(10);
  myservo_x.write(90);
  myservo_y.write(90);
}

void loop() {
  while (Serial.available() >= 2) {
    for (int i = 0; i < 2; i++) {
      data[i] = Serial.read();
    }

    myservo_x.write(data[0]);
    myservo_y.write(data[1]);

    Serial.println(data[0]);
    Serial.println(data[1]);
  }  
}

This code uses only the horizontal coordinate, and by means of a servo connected to pin 9 we move the reflector towards the backless stool.

Test

In the video below I show you the tests. As you can see, the reflector follows the movement of the image of the backless stool. In this way we make sure that it concentrates the ultraviolet radiation on the desired object. 

Discussions