This project is insane. Millions of my precious brain cells gave their lives in order to produce this scanner. /sarcasm
No really, this project is extremely difficult. Constructing and coding the servo motor's movement was simple overall but processing the data and creating a 3D image is not a walk in the park. The 3D image is created by
Processing.
Processing
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUVm1RglkZlFx4gHGkHTKM9jLbZHnUrtx0n4U9GqAWdyettsj6hZdTYy1d15KAVV9F6BVCJ2y4SuPhe6ygYPRFHt0CwKLjZyMZe65lqxiF6y9t3C-i2ksZ7Jmisf3Saf5OA_Bl7bVFd7s/s320/WP_000375.jpg)
How does this work? There are 2 servo motors, where one of them is responsible for the panning motion and the other, tilting motion. Once the panning servo completed its 180 degree turn(incremented by 1 degree), the tilting servo will tilt 1 degree, and this process repeats itself. At all times, the sensor will be scanning for objects. The arduino will be sending 3 pieces of data: pan position, tilt position and the distance. These values will be picked up by
Processing and for each set of data,(pan + tilt + distance), a dot will be mapped out.
This is where the fun comes in. We know 2 angles + distance, which could be interpreted as a vector. Using simple trigonometry, we can easily determine the x,y and z components
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCOFujcji7HKDpxrVko8ds1VvP72EFrAydXqEvkF95UPwws4kUDmjeCClSQv6BfoxRe5cbormH0823gkAqpWdB5x8K_B-rSPukO9GI-T_kfMQbqS9422MPIXH2w5cFuor_MUwO8U_iObc/s320/3d-+scan.jpg) |
Note: Ignore the purple dots |
The image on the left is a good visualization of how the scanner works. The pink curve is the very first scan(tilt angle: 0 degrees and the panning angle ranges from 0-180). The green curve is exactly identical to the pink curve, but with a 10 degree tilt angle.
From this point, everything is generally simple. The hard part is to implement a "camera" movement algorithm in order to see the image at various perspectives. To get this to work, there is a massive problem. In order to change the point of view, the camera movement algorithm requires a complete deletion of the current image and redraw it. If I were to merge the camera algorithm with the mapping algorithm, I'll just get a blank screen with 1 dot that is constantly moving. This is because the data collected is not being stored and the image displayed is the current reading. Obviously, this has no use to me.
This is where arrays come in. In order to store these points, an array must be created. However, there is a TON of data. According to my calculation, there should be at least 32,400 points(x,y,z) that will be collected! Next, Each of these points will be written into a text file.
I then created a separate script, responsible for merging both the camera movement algorithm and plot all the points. Unfortunately, it crashes. Why? There is too much data. I wasted countless hours designing an algorithm which will plot the points and implementing a camera movement algorithm, which allows me to see the graph in different perspectives.
Now, I have no choice but to use another software. After some research, I decided to use matlab.All I have to do is copy and paste the coordinates into matlab and write a very simple code to graph these values. Once everything is completed, I decided to run a test trial. Both servos will be operating but the distance sensor will be turned off. Since this is a test trial, the micro controller will be sending "300cm" as the distance reading.
In this trial run, the tilting servo will be incremented by 10 degrees. As you can see, a portion of the image is missing. There is a bug in my code where the micro controller is not sending all the data for some reason.
For my second trial run, the tilting servo will be incremented by 1 degree. This scan took about 12 minutes and the results are beautiful. I can now conclude that my program is functional.
Hardware issues
As for hardware issues, My arduino board couldn't supply enough power to run 2 servo motors simultaneously. An external power source will be required to power 1 of the servo motors. I'll be using 1 micro servo and 1 medium servo(this servo requires more power). I tried using 4AA batteries(measured it with a multimeter and got 5.3v) but it simply wasn't enough to power the servo motor. I guess the batteries wasn't supplying enough current.I have 9 volt batteries but those things die way too quickly(mine is rated at 200 mah and I might be able to power the motor for 1 hour, if I'm lucky).
I decided to get a little creative. The most reliable power source available is my computer. I'll be using the USB port to power both my arduino and my medium servo. I found an old cell phone usb charger, cut off 1 end of the wire and soldered it onto a 2 wires. Next, I measured the voltage using a multimeter and its exactly 5volts! Finally, I tested my circuit and everything is running smoothly.
Future Plans
This project is not yet completed. As of now, the only thing I successfully accomplished is creating a program that can split the readings into 3D points and graph it using a plotting software(matlab). The scanner itself needs some serious improvements. From the images You can see that the sensor's position is changing. (For example, starting position is about 5cm below the tilt servo and the end position is 5cm above the tilt servo). Unfortunately my program assumes that the sensor will always be in the same position. I tried to take this into consideration (software wise) but it's not very effective.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4_-nPLrhyiJaFQjwzrdfKQErHCXvbEPo7zHkFw635qOWnXJW06c1kdXuGL-WAE4RoULHHdUK1kTcuKa175lbCPbWDSR9gkS7_YsASiTTfSlg3HgZ82auDbh-4jktRp-Kw-rIr3vGqLvw/s320/WP_000379.jpg) |
Tilt Angle: 0° |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikhM3jujFdI-wE7sKpdS8c6hTzkxZGxW2YxbgOx4AQvKw5OoBNjG7Dfz5oZ1brXX1u1_h2dWk9m4D9O5UeHvELKYzluVNziYa6NedFhyphenhyphenUcgC5uhr0S5eqFWfo3H25bPnKieeq1zbbvf9I/s320/WP_000380.jpg) |
Tilt Angle: 180° |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrD6lY-tT0Kn-6cYmHtMjmrw5PcpE1FzTUQxbEv1KKW-5Syp6bc7JGT79iD_tQh0sDfguNpwPuBLXle6FpN5pEgT6Wg6iZqHs1p38c-rzygl5qaB-aTCdu2pLZwvlWQd4Mv_JZgaEfirU/s640/corner1.png) |
Top View |
I need to replace my micro servo. Physically, it can only turn up
to 160-170 degrees, which could
explain why the scanned image is not
perfect. The image above shows that the 2 objects are not at a 90 degree angle. On the bright side, the corner readings are pretty accurate. The top right image of my laundry boxes shows that one box is slightly curved in. Thankfully, the infrared sensor noticed this!
This is a very challenging project and I still need to improve my physical scanner. Hopefully by then, I'll get more accurate readings.