Engineering Analysis - parmsco/Line-Following-Robot GitHub Wiki

Engineering Analysis: Mechanical

The group measured that each lap of the track was roughly 18 feet. From this, decisions were made on motor speed and wheel diameter. As soon as the competition was released, Scott ordered a number of parts from China with extended delivery times. These parts included the line following sensors, wire, and three speeds of motors; 100 RPM, 150 RPM, and 200 RPM. The team wanted to design the fastest robot possible without being out of control. Of the motors, the group had available the 150 RPM motor was chosen as the best as it provided more torque than the 200 RPM motor. The combination of the 150 RPM motor with 3-inch diameter wheels led to a speed of 1.96 ft/sec. Two styles of IR reflectance sensors were experimented with throughout testing. One set of sensors had a preset black/white threshold and the other had a potentiometer that allowed the user to select a reflectance threshold. The group performed tests with each set of sensors and decided that the adjustable sensors were too sensitive and would not be a great choice. The preset sensors seemed to be easy to program with and were largely successful without modification to the actual sensors. The group decided to use these sensors in all following designs.

Engineering Analysis: Programming Throughout the project, each member of the group underwent a large learning curve in the area of Arduino coding and the use of electronics. Several of the members have had previous experience with coding in Java and RobotC or utilizing Arduino in previous high school projects. This experience greatly helped and improved the quality of the final product and encouraged the group to use an Arduino instead of relying on a solely mechanical solution.

Sonar Code (Ultrasonic Sensors) The robot went through several design changes including the attempt at using sonar sensors to center the robot on the track. These sonar sensors were to be used in only if the line following sensors lost the line due to a collision or damage to the black line. The sonar sensors worked by sending out a burst of 40 kHz sound waves and measuring the amount of time it takes for the sound bursts to reflect off of the border of the track. This time was converted to a distance and compared to the distance measured by another sonar sensor on the other side of the robot. If one of the measurements was shown to be larger than the other, the robot would adjust the motors accordingly in order to center the robot on the track. The initial testing code is shown in Appendix A (Page 146) controls led lights on a breadboard which would eventually be replaced by motors for testing. Ultimately, the sonar sensors were unable to be incorporated into the team’s final robot for a number of reasons. Through the testing, it was found that the sensors were unreliable at distances under 4 centimeters; with the distance between the walls of the track and the robot being between 0 and 5 centimeters, this was a major issue. The sonar waves also bounced unreliably off of the curved walls of the test tracks which gave unreliable distance values. Because of these limitations, sonar was not considered to be a viable navigation method for the robot. Due to this, ultrasonic sensors were replaced with bumper sensors. Bumper sensors ended up being much more reliable, and due to the small width of the track, performed better than ultrasonic sensors could.

Initial Line Following Code (Without Ultrasonic Sensors) As seen in the brainstorming exercises, a line following robot was the highest rated design to pursue. The code for this part of the robot underwent many iterations and improvements as testing progressed but was always rooted in the use of IR reflectance sensors to track the black line on the track. The code from the initial attempt did not incorporate bumper sensors or ultrasonic navigation. This code was fairly reliable when the robot was using 4 AA batteries in series. When 6 batteries were used the robot tended to hit the walls when turning as well as colliding with the track at the intersection. To mitigate this, ultrasonic sensors were then programmed into the navigation routine. Early Line Following Code (With Ultrasonic Sensor) Ultrasonic sensors were included in the previous code for testing. The sensors were not functioning as expected (due to the close proximity of the walls, and their use was put aside and bumper sensors took their place. While ultrasonic sensors would have been the preferred navigation backup technique, bumper sensors performed nearly as well.

Final Line Following Code The final code built upon the programming done previously but with bumper sensors rather than ultrasonic sensors. Earlier versions of code used roughly 14% of the Arduino Uno’s memory and contained extended boot times due to poor variable definition and extraneous functions. The final code converted all “int” variables into “#define” statements (for unchanging values) or “byte” values. Along with this, the program no longer includes any serial monitor debugging so the “serial.begin” function was eliminated. These two processes decrease boot times by roughly 2 seconds. With an upgraded battery pack and increased rear weight, the robot tended to “wheelie” at the beginning of matches and lost track of the line. To mitigate this, the final code performs a ramping-up process before starting to navigate on the line. This completely solved the “wheelie” problem and further decreased startup times. Beyond this, the robot was calibrated to drive straight and turning values were tuned with full batteries before the competition.

Final Line Following Code Explanation

  1. Include Adafruit Motor Shield library and define variables and calibration factors
  2. Set up the motor driver and define bumper pins to be inputs with pull-up resistors on
  3. Begin navigation loop
  4. Read IR reflectance sensor values as well as the values of the bumper sensors
  5. Create an array of IR sensor readings to be used later
  6. Perform a one-time ramping function to slowly speed up motors from rest
  7. Read bumper sensor values and perform pivoting motions to re-align with the line
  8. If bumpers are not pressed, compare the sensor array to various preset readings and perform turning, pivoting and driving functions depending on the comparison result
  9. If the sensor array is sensing fully “white” the robot performs correction measures to find the line again using the last known sensor values to determine which side of the line the robot is on
  10. Navigation loop repeats indefinitely
  11. Driving functions are defined after the navigation loop; these could also be included in the setup portion of the code