Final Report of Lab 2
In this lab, we embarked on the journey of creating a 3Dscanner utilizing two Hobbying servo motors, a Sharp Infrared Distance Sensor, and an Arduino Uno. We created a connector that would allow us to secure a reliable connection between our Arduino and IR sensor. We patiently assembled the connector by crimping three JST connectors onto appropriately stripped wires to fit into a 3pin JST connector.
We tested the functionality of the primary parts: the sensor, the Arduino, and the servos. We adjusted and ran the AnalogInput example from the Arduino example library, which caused our sensor to blink at an increased rate whenever an object was nearby. Similarly, we ran AnalogOutSerial from the Arduino library, which allowed us to verify that values were being transmitted and that they consistently changed when an object was nearby. Lastly, we made sure our servos worked and could be controlled, using the "Sweep” example to rotate the servos.
After confirming the functionality of our parts, we started the process of calibrating our IR sensor. We wanted to find the mathematical relationship between the analog sensor readings and the actual, known distances of objects. To do this, we manually mapped out a series of distances, making sure that our surface was not too reflective for this could skew our sensor readings. Then, using AnalogOutSerial, we recorded the values displayed on the serial monitor when a reflective, sturdy piece of white paper was held up to 50 inches. We graphed the relationship between the analog readings and known distances, and we fit a 4th degree polynomial curve to the data. The fit of our trendline was excellent, with an R-squared value of .997. (The data was similar to that in the provided datasheet.)
Next, we moved onto programming our mechanism so that it could function as a 3D scanner. So that we could program accurate angles into our program, we created the object that we would ultimately scan a foam cutout of a merged H and F to represent the first initials of our last names. Then, we placed the object in front of our sensor at a distance that was accurately detected (30 inches) and measured the angles from our sensor at the origin to the four quadrants of our object (from left to right, top to bottom). To begin our code, we focused on using just one servo, the “pan”, in order to begin building our program and producing a 2D representation. We did this by again using the example Sweep program to create “stupidSweep”. In stupidSweep, we controlled the servo to move at the range we measured across the xaxis of our object. We then programmed stupidSweep to display both the angle reading of the servo and the distance in the serial monitor. After we got this working, we needed a way to capture the values displayed in our serial monitor so that we could plot them using Matlab.
Since the Arduino is only a microcontroller, it has no way of actually writing serial outputs. Luckily, we found the program CoolTerm, which is a simple serial port application which takes the place of Arduino’s serial monitor but allows you to write readings to a text file. We were able to store the readings to be plotted in Matlab. After collecting the data for stupidSweep, we built the stupidOutput function in Matlab. We wrote the function plotOutput, which takes the same inputs at stupidOutput, but instead creates a 3D representation of the object being scanned. In order to use plotOutput, we first built our Aruduino function panTiltFull, which takes into account the height of the object by controlling the “tilt” servo. We built panTiltFull so that it would tilt and scan the vertical distance of the object for every pan movement. We then changed the serial output so that the angle of tilt was also displayed.
Finally, we encountered multiple obstacles in developing a method to draw information from the Arduino serial to the MATLAB plotter. We began by trying to sample data solely from the sensor and used fopen(comPort) to create a scatter plot. However, although values were being printed in the serial, MATLAB was receiving no data to plot. It took us several trials and much research to understand how connections worked between Arduino and MATLAB. Once we were able to successfully make a connection, our team discussed how to store data from the Arduino as the program does not easily export to text files. We explored using commaseparated values (csv) formatting of the distance, height and sensor readings that could be read and printed to file by MATLAB. However, we ended up using a program called CoolTerm that draws from Arduino serials to develop txt files and then designed a MATLAB code to read directly from txt files. In doing so, we were able to plot the values accordingly and learned the about various routes for ArduinoMATLAB programming.
We tested the functionality of the primary parts: the sensor, the Arduino, and the servos. We adjusted and ran the AnalogInput example from the Arduino example library, which caused our sensor to blink at an increased rate whenever an object was nearby. Similarly, we ran AnalogOutSerial from the Arduino library, which allowed us to verify that values were being transmitted and that they consistently changed when an object was nearby. Lastly, we made sure our servos worked and could be controlled, using the "Sweep” example to rotate the servos.
After confirming the functionality of our parts, we started the process of calibrating our IR sensor. We wanted to find the mathematical relationship between the analog sensor readings and the actual, known distances of objects. To do this, we manually mapped out a series of distances, making sure that our surface was not too reflective for this could skew our sensor readings. Then, using AnalogOutSerial, we recorded the values displayed on the serial monitor when a reflective, sturdy piece of white paper was held up to 50 inches. We graphed the relationship between the analog readings and known distances, and we fit a 4th degree polynomial curve to the data. The fit of our trendline was excellent, with an R-squared value of .997. (The data was similar to that in the provided datasheet.)
Next, we moved onto programming our mechanism so that it could function as a 3D scanner. So that we could program accurate angles into our program, we created the object that we would ultimately scan a foam cutout of a merged H and F to represent the first initials of our last names. Then, we placed the object in front of our sensor at a distance that was accurately detected (30 inches) and measured the angles from our sensor at the origin to the four quadrants of our object (from left to right, top to bottom). To begin our code, we focused on using just one servo, the “pan”, in order to begin building our program and producing a 2D representation. We did this by again using the example Sweep program to create “stupidSweep”. In stupidSweep, we controlled the servo to move at the range we measured across the xaxis of our object. We then programmed stupidSweep to display both the angle reading of the servo and the distance in the serial monitor. After we got this working, we needed a way to capture the values displayed in our serial monitor so that we could plot them using Matlab.
Since the Arduino is only a microcontroller, it has no way of actually writing serial outputs. Luckily, we found the program CoolTerm, which is a simple serial port application which takes the place of Arduino’s serial monitor but allows you to write readings to a text file. We were able to store the readings to be plotted in Matlab. After collecting the data for stupidSweep, we built the stupidOutput function in Matlab. We wrote the function plotOutput, which takes the same inputs at stupidOutput, but instead creates a 3D representation of the object being scanned. In order to use plotOutput, we first built our Aruduino function panTiltFull, which takes into account the height of the object by controlling the “tilt” servo. We built panTiltFull so that it would tilt and scan the vertical distance of the object for every pan movement. We then changed the serial output so that the angle of tilt was also displayed.
Challenges with Lab 2
As we are still learning Arduino and, at the start, had little experience with Servo motors, our team underwent several challenges. First, developing the connector for the infrared sensor proved difficult in that one) we had placed the wire connections backwards and, after fixing them, the wires had difficulty staying inside the plastic piece during testing. We eventually replaced the wires with others that had been better crimped to ensure that we had a secure connection to the Arduino. Secondly, in calibrating the sensor, we questioned how precisely we needed record analog readings for distance measurements. We began by measuring the readings every 20 cm out to a distance of 100cm, then every 10 cm to the same length, and finally, 1 inch to a length of 50in. We had to adapt our precision based on the looseness of the trendline equations we were gathering from Excel. Deciding to use a polynomial fit rather than a logarithmic or exponential equation guided us in our measurements for calibration.Finally, we encountered multiple obstacles in developing a method to draw information from the Arduino serial to the MATLAB plotter. We began by trying to sample data solely from the sensor and used fopen(comPort) to create a scatter plot. However, although values were being printed in the serial, MATLAB was receiving no data to plot. It took us several trials and much research to understand how connections worked between Arduino and MATLAB. Once we were able to successfully make a connection, our team discussed how to store data from the Arduino as the program does not easily export to text files. We explored using commaseparated values (csv) formatting of the distance, height and sensor readings that could be read and printed to file by MATLAB. However, we ended up using a program called CoolTerm that draws from Arduino serials to develop txt files and then designed a MATLAB code to read directly from txt files. In doing so, we were able to plot the values accordingly and learned the about various routes for ArduinoMATLAB programming.
Comments
Post a Comment