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
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
Note: Ignore the purple dots |
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.
Tilt Angle: 0° |
Tilt Angle: 180° |
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.
Fantastic project , may I ask where I can find the source code please
ReplyDeleteKind regards
Fantastic project , may I ask where I can find the source code please
ReplyDeleteKind regards