After reading my first blog post about the Coffee capsules Vending Machine Gamification I hope it was interesting enough for you to read more about the milestones I worked on in this blog post! I will walk you through the mechanics parts and the image processing for the capsules detection.
There were different parts and components of the project:
- The Axes mechanics (X,Y,Z)
- The Gripper
- The 3D printed parts
- The Libraries used in the Arduino codes
- The Libraries used in the Python (Raspberry Pi) codes.
The Components used:
- Six Steel Rods
- Connectors(3D printed)
- Rubber bands
- Joy Stick
- Coin acceptor
- 3 Stepper motors (Nema 17)
- 3 Big Easy Drivers
- 1 servo motor
- Scissors stand(3D printed)
- Gripper(3D printed)
- Cardboard Box
- Raspberry Pi
The Axes Mechanics:
There were four steel rods used to support the two Axes, along which the motion happens. The motion is transferred from the motor to the rods by using rubber bands rolling around the pulleys. This setup has been proven to be precisely working as it has been inspired from 3D printers mechanism. The point of intersection between X and Y axes is the point where the gripper is installed.
The connectors used to get the whole setup (the 6 rods and the rubber bands) together were 3D designed and printed using OpenSCAD and Cura.
Two Stepper motors (Nema 17) would get signals from the Arduino about the motion; its rotation direction and period. The rotation of the motor is transferred to the four supporting rods (on the sides), then again another rubber band with the help of the connectors transfer the motion to the two rods forming the X and Y axes, where it is translated into displacement made by their point of intersection. This displacement (distance in specific direction) is made to reach the place of the capsule to be grabbed.
The Arduino gives the signals to the motors after doing some calculations either on the joystick input or on the serial input from the Pi according to the chosen mode.
As this vending machine can play on its own, the motion should be very precise. So positioning the gripper to be hanging from above was not the most practical and precise option but rather I decided to make the ground move up and down instead for better precision.
In order to achieve that, a stepper motor is used with a spiral shaft. The ground is connected to a nut that would move up and down when the motor rotates. In order to support the ground in its movement, I used 3D printed scissors stand.
The challenges in the Axes Mechanism part were:
- Finding the right drivers for the motors, I had to try out different that would support the needed current without getting burnt.
- Finding the best optimizations in the Arduino code for two things;
- The motors should only be turned on in time of motion and then turned off again once reached the target place.
- The motion would be in reasonable speed.
I overcame those challenges after some investigations and trials by using Big easy drivers with heat sincs and using AccelStepper Library for Arduino that helps in controlling more than one stepper motor at a time.
The challenge was to find a grabber that would have a tight grip on the capsule without letting it slip. I decided to 3D print the gripper using a flexible material called Ninja Flex. The gripper’s design was imported from http://www.thingiverse.com/thing:2303095.
A servo motor is used to control the opening and closing of the gripper. This gripper design was the best option since it provided the needed tight grip; because it’s fingers can bend over the grabbed capsule. When the motor rotates it pulls the nylon cables inside the fingers in its direction, and it either opens or closes the gripper.
The Arduino would give signal to the servo motor to open or close the gripper according to the inputs coming from the buttons in case of playing mode, and in case of the auto play mode the gripper is set to be open when the the X,Y are in the right position and after the ground comes up the gripper closes to grab the capsule. The gripper is set to be opened again when it reaches the vending outlet to dispense the capsule.
Key points of Arduino code:
As mentioned before AccelStepper Library is used to control the multiple steppers.
The control depends on different inputs according to the mode, either the joystick and buttons (signals) or serial input (coordinates).
Key Points of Python code :
In order to do some image processing on the photos, I used four different libraries; OpenCv, Numpy, Scikit and Imutils. Also the pyimagesearch website tutorials were very helpful for me as I was totally new to image processing.
In case of playing-with-joystick mode the sequence of the code is:
Upon using the Joystick to take the capsule;
- Take two pictures (First one upon choosing the mode and the Second after taking the capsule),
- Finding the differing area between the two picture
- Finding the contours of the differing area and
- Finding the differing area’s center point in the second photo
- Accessing the the center point pixels in the first photo
- Detecting the color Range of the accessed pixels in the first photo to keep track of the stock.
In case of auto-play mode the sequence of the coding is:
Upon choosing the needed capsule with specific color;
- Take a picture
- Finding maximum connected areas of same chosen color range
- Detecting the contours of this area and
- Finding its center point (X,Y co-ordinates)
For better results in the image processing part:
HSV color space and Blur median effect were used for the color range detection. Gray scale should be used for finding the contours.
These pictures show the output marking the needed capsule and showing their coordinates in pixels.
By now most of mile stones (1 & 2) are tried out and showed good results.
Due to time restrictions milestone 3 is left for future work, maybe with some better casing and some help of laser cutting would be good.
For me making this project was a very nice and exciting adventure specially beacuse it introduced me to 3D printing and image processing world.
I will always cherish this experience and being part of HybrisLabs team =)
At the end I hope you enjoyed reading these blog posts, maybe it encouraged you to pursue any crazy idea you have =)