Goliath Fall 2016

Rapid Prototyping of Ultrasonic and Sharp IR Sensors

By: Sou Thao (Electronics and Control)

Approved by Kristen Oduca (Project Manager)

Table of Contents

Introduction

Requirement: Goliath shall follow the Biped at a fixed distance of 20 inches with a margin of error of 15%.

In order for Goliath to run autonomously, two rapid prototype models were created using different sensors.  The first model was created using the ultrasonic HC-SR04 ultrasonic sensors as shown in Figure 1. The second model was created using Sharp GP2Y0A60SZLF Analog Distance Sensors as shown in Figure 2.  

Figure 1 - Ultrasonic Sensor Rapid Prototype

Figure 1 – Ultrasonic Sensor Rapid Prototype

Figure 2 - Sharp IR Sensor Rapid Prototype

Figure 2 – Sharp IR Sensor Rapid Prototype

The two models were tested and compared with one another to determine their capabilities in tracking an object accurately. This also works as an experiment to determine, which would be better for our project.

Preparing the Goliath

First, we took the previous Goliath and removed its custom PCB and 3DoT board.  Next we attached a breadboard and an Arduino Leonardo to the top of the Goliath. We did not use a 3Dot board because at the time there was an issue uploading the library onto the board.  A 5V battery pack was attached to the inside body to provide power to the motors and to the sensors.  We used a L293D H-Bridge Dual Motor Driver IC to control our motors based on the feedback from the sensors.  To connect the L293D IC, pins 4, 5, 12, and 13 are grounded.  Pins 8 and 16 are connected to the 5V source.  Pin 1 and 9 are connected to the digital pins from the Leonardo to enable the motor driver to turn on.  Pin 2 and 7 are connected to the digital pins of the Leonardo to control motor A.  Pins 10 and 15 are the connected to the digital pins of the Leonardo to control motor B.  Finally pins 3,6,11, and 14 are connected to the motors. This is shown in Figure 3.  Now that we have a platform to set up our sensors to, we tested the ultrasonic and IR sensors. This is shown in Figure 3.

Figure 3 - Preparing the Goliath

Figure 3 – Preparing the Goliath

Code to Control the Motor

In order to set up the code to control the motors, there will be five scenarios that we will face.

  1. If the Goliath is too far from the tracked object, the motors will both rotate forward to allow Goliath to move forward.
  2. If the Goliath is within a the range from the tracked object, the motors will turn on and Goliath will come to a stop.
  3. If the Goliath is too close to the tracked object, the motors will both rotate backwards to allow Goliath to move in reverse.
  4. If the left sensor detects the object is closer than the right one does, the right motor will rotate forwards while the left motor is left stationary, thus creating a left turn.
  5. If the right sensor detects the object is closer than the left one does, the left motor will rotate forwards while the right motor is left stationary, thus creating a right turn.


These five scenarios are the basis for the functions we will call to after receiving the distance from both sensors.  Below is the the Arduino code for setting up the motor controls.

int enable1Pin = 13; // pin 1 on L293D

int motor1Pin1 = 12; // pin 2 on L293D

int motor1Pin2 = 11; // pin 7 on L293D

int enable2Pin = 8; // pin 9 on L293D

int motor2Pin1 = 9; // pin 10 on L293D

int motor2Pin2 = 10; // pin 15 on L293D

void stop()                    //stop

{

 digitalWrite(motor1Pin1,LOW);

 digitalWrite(motor1Pin2,LOW);    

 digitalWrite(motor2Pin1,LOW);   

 digitalWrite(motor2Pin2,LOW);    

}   

void advance()          //forward

{

 digitalWrite(motor1Pin1,LOW);

 digitalWrite(motor1Pin2,HIGH);    

 digitalWrite(motor2Pin1,LOW);   

 digitalWrite(motor2Pin2,HIGH);  

}  

void back_off()          //backward

{

 digitalWrite(motor1Pin1,HIGH);

 digitalWrite(motor1Pin2,LOW);    

 digitalWrite(motor2Pin1,HIGH);   

 digitalWrite(motor2Pin2,LOW);  

}

void turn_L()             //left

{

 digitalWrite(motor1Pin1,LOW);

 digitalWrite(motor1Pin2,LOW);    

 digitalWrite(motor2Pin1,LOW);   

 digitalWrite(motor2Pin2,HIGH);  

}

void turn_R ()             //right

{

 digitalWrite(motor1Pin1,LOW);

 digitalWrite(motor1Pin2,HIGH);    

 digitalWrite(motor2Pin1,LOW);   

 digitalWrite(motor2Pin2,LOW);  

}  

Implementing the HC-SR04 Ultrasonic Sensors

Each HC-SR04 Ultrasonic Sensor has 4 pins: Vcc, Trig, Echo, and Gnd.  The Trig pin is used to transmit the sound waves while the Echo pin is used to receive the reflected sound.  We tied the two ultrasonic sensors to the front of the Goliath with rubber bands, and connected the Trig and Echo pins to the digital pins of the Leonardo.  To code the ultrasonic sensors, we first must perform a digitalWrite to set the trigger pins low.  Then after a delay of 2 microseconds, we set the trigger pins high and wait 10 microseconds to reset the trigger pins back to low.  From this situation, we can perform a pusleIn function on the echo pins to detect the amount of time it takes for the sound wave to be transmitted and reflected back.  Then we divide this time by 58.2 to get the distance the object is away in cm [1].  By performing this action on both sensors, we can compare the two sensor values to move the Goliath. Figures 4 and 5 below show the Fritzing Diagram and Breadboard Photo for the ultrasonic sensors.  Attached to the bottom of this blog post is the code implemented using the ultrasonic sensors.

Figure 4 - Fritzing Diagram of Ultrasonic Sensors

Figure 4 – Fritzing Diagram of Ultrasonic Sensors

Figure 5 - Breadboard Photo of Ultrasonic Sensors

Figure 5 – Breadboard Photo of Ultrasonic Sensors

Code for the HC-SR04 Ultrasonic Sensors

The following link is a downloadable file with the code for the ultrasonic sensors. https://drive.google.com/file/d/0B2uuXSsK9_mMQlhIQXZGa2R6Zjg/view?usp=sharing

Implementing the Sharp IR Sensors

Each Sharp IR Sensor have 4 pins: EN, OUT, VCC, and GND.  EN is not connected to any pins, while VCC and GND are connected to the positive 5V and ground terminals of the breadboard respectively.  The OUT pin is connected to the analog pin of the Leonardo, which gives voltage readings from 0 to 5V based on the distance an object is detected.  The Sharp sensor has an integrated signal processor implemented into it, and can be powered from a 3 to 5V source.  We taped the IR sensors to the front of the Goliath, and connected its pins to the power terminals and the analog pins of the Leonardo.  After this process, the code was written to follow an object [2] [4].  Because the analog pins detect voltage ranges, we have to find a way to convert the voltage readings to distance measurements. Figures 6 and 7 below show the Fritzing Diagram and Breadboard Photo for the Sharp IR sensors. [3]

Figure 6 - Fritzing Diagram of Sharp IR Sensors

Figure 6 – Fritzing Diagram of Sharp IR Sensors

Figure 6 - Breadboard Diagram of Sharp IR Sensors

Figure 6 – Breadboard Diagram of Sharp IR Sensors

From the data sheet, we notice there were no linear relationship between the voltage and distance. [5]

Figure 9 - Sharp IR Sensor Data Sheet

Figure 9 – Sharp IR Sensor Data Sheet

In order for the sensors to work accurately, an equation must be used to determine the relationship between the voltage readings and the distances.  By doing a search online, we found a suitable equation so we can test our sensors.  The equation is shown in Figure 9.

figure-9-relationship-between-distance-and-voltage

Now that we were able to determine the distance an object is detected, we compare the two sensor values and moved our motors based on the the movement of the object.  Attached to the bottom is the code implemented with the Sharp IR Sensors.

Code for the Sharp IR Sensors

The following link is a downloadable file with the code for the sharp IR sensors. https://drive.google.com/open?id=0B2uuXSsK9_mMYjlMQllyQ2ROZjA

Result and Analysis

From the test of both prototypes, we noticed that the ultrasonic sensors were more reliable in tracking an object.  Both sensors were able to turn as the object turned, however, sometimes the prototype implemented with the IR sensor would track a wall or something else and follow that object instead.  We noticed that the measurements from the IR sensors were distorted due to the level of light coming from the sun and the light bulbs in the room.  Because the ultrasonic sensors used sound waves, its signals were less prone to distortion from outside sources.  This resulted in better movements and trackability.  Also, there were jitters in the movement of the Goliath which was caused by the unstable measurements from the sensors.  The code will be refined and will need to be implemented with a control algorithm and an average summing filter to smooth out the input signals.  

Conclusion

From the test of the prototypes, the ultrasonic is the most ideal sensor to use for our application.  It tracked objects better than the IR sensor, and its signals had less distortion.  These prototypes showed a proof of concept that Goliath should be able to track an object autonomously using only two sensors.  The code will need to be refined to improve the jitters noticed from the tests.