CAD software used - SolidWorks
Manufactured - 3D Printed
I was recommended some cool projects on YouTube using OpenCV and decided to do something on my own.
This project constantly evolved over my Spring 2023 semester as this is a combination of the things I learned in mechanical design and intro to robotics.
I used positional analysis learned in my design class, and utilized PWM differences to create a specific rotational range on my servos which is something I learned in my robotics class.
The way this robot arm works is it takes a picture of the objects on the wooden slab which consists of 3 different colored magnets, and it figures out their position then picks them up and sorts them accordingly.
This project required me to do a lot of work on paper, which included drawing diagrams to help visualize what the camera sees and to solve my equations for position. This robot arm is technically a four-bar mechanism, but since the link from the ground to the first part of the arm is stationary I was able to use law of cosine to get my equations.
The problem that needed to be solved was how I was going to take the coordinates from the picture, and convert that into multiple angles to turn my servos to get to those coordinates.
The first step I took was figuring out how to line up the arm along the hypotenuse of the objects x and y coordinates. Since the camera can't take a picture of the base of the robot arm I had to create a diagram that extended the picture the camera takes to include the base of the arm. I then found the range the arm needs to turn to cover the bottom left corner and bottom right corner of the picture the camera takes. I then reflected this range in my PWM max and min values, so a value of -1 sent to the servo covers the bottom left corner and a value of 1 cover the bottom right corner.
Next I started with figuring out the boundaries of where I wanted my arm to go. I decided that having the end of the arm hover about 0.6 inches above the board to catch the magnet was sufficient, since the radius of the magnet holder was 0.7 inches, I was able to subtract those two values from the initial height of the arm to setup my problem.
From there I found my cosine equations to solve for the angles of "F, C, and A". I then used these equations to solve the maximum and minimum angles I wanted my arm to move by choosing my max and min lengths. I used this max and min range in angles to choose the max and min PWM values.
When writing the code I had to convert the values from the camera which were in a pixels "unit" and convert them to inches because that's how I measured the lengths of the arms. I did this by measuring the camera's boundaries in inches and creating a ratio to convert between pixels and inches
After I successfully solved the positional problem of my arm I implemented these equations I derived into my code and began on programming the computer vision aspect of the project.
This part required a lot of learning and research as I didn't know anything about computer vision before this.
After figuring out how to find colored objects in a picture I started on the code. First step was to take a picture and I orientated my servos so the camera was perpendicular to the board, then I converted the image from a BGR to a HSV to find the colors in a given range. Next, I masked the image 3 times for each magnet and each color so I could get the binary image of each object on its own. I then used OpenCV's function findContours to find the boundary of each object. Then I used boundingRect to get the x and y coordinates of each pixel that makes up the contour. I then saved these values into an array and averaged the array to get my x and y coordinate for each object. The mean of these values would, in theory, represent the center of the object, since the contour represents the boundary of the object.
Now I had 3 x and y coordinates for my magnets and I simply looped through my positional analysis for each object and grabbed each magnet to sort them to their correct colors.
And this is the equation I used to get the correct range for the gpiozero library
This project was a success and I learned how to merge the methods taught in both mechanical design and robotics into one project. I did encounter some problems that I managed to solve. One of these problems revolved around the initialization of the camera. When creating the camera object I had an error that wouldn't allow me to use it with the Raspberry Pi; however I went onto various forums where people had similar errors and managed to find a solution that involved me passing the code cv2.CAP_V4L to the cv2 library. Another issue I had was in the beginning stages of the project when I was building the arm. At first I didn't have a base, but when I started writing simple code to just get the motors to rotate I noticed that rotating the bottom servo made the arm shake from vibrations, and if it shaked at the right frequency it began to shake uncontrollably. I fixed this by adding a base for the arm and adding bearings on the side of the disk attached to the bottom servo to spin on the base.
Here is a video demonstration of my robot arm.