+ All Categories
Home > Documents > Arduino Final Project

Arduino Final Project

Date post: 14-Feb-2017
Category:
Upload: bach-nguyen
View: 59 times
Download: 6 times
Share this document with a friend
19
ROVER PROJECT #2: Obstacle Avoidance Robot ROVER PROJECT #1: Maneuvering the Rover Andrew Brouillete, Michael Hernandez, and Bach Nguyen Report by: Bach Nguyen CSIT Department Southeastern Louisiana University Hammond, LA 70401 Contact Number: 985-662-2106 Contact Email: [email protected]
Transcript
Page 1: Arduino Final Project

ROVER PROJECT #2: Obstacle Avoidance Robot

ROVER PROJECT #1: Maneuvering the Rover

Andrew Brouillete, Michael Hernandez, and Bach Nguyen

Report by: Bach Nguyen

CSIT Department

Southeastern Louisiana University

Hammond, LA 70401

Contact Number: 985-662-2106

Contact Email: [email protected]

Page 2: Arduino Final Project

ABSTRACT:

This project is to demonstrate our understanding of how to combine a distance sensor and

the 4 wheels drive vehicle to avoid obstacles to reaches its destination.

INTRODUCTION:

In robotics, obstacle avoidance is the task of satisfying some control objective subject to

non-intersection or non-collision position constraints. In unmanned air vehicles, it is a hot topic.

What is critical about obstacle avoidance concept in this area is the growing need of usage of

unmanned aerial vehicles in urban areas for especially military applications where it can be very

useful in city wars. Normally obstacle avoidance is considered to be distinct from path planning

in that one is usually implemented as a reactive control law while the other involves the pre-

computation of an obstacle-free path which a controller will then guide a robot along.

BACKGROUND:

In this project we combined two of our previous projects to make the obstacle avoiding

rover. Using DFRobot’s mobile platform kit and an ultrasonic sensor with 9 pins to make this

project possible.

METHODOLOGY:

List of material uses:

Ultrasonic Sensor URM37 V 4.0

DF05BB Servo

DFRobot 4WD Pirate Rover

Page 3: Arduino Final Project

DFRobot Arduino Uno

DFRobot Motor Shield V1.2

To connect the servo to the platform we used 4 1/8 in screws with hex bolts to secure the rover in

place. Then we connect the sensor mount to the servo using provided ¼ in screw. Then the

Sensor is mounted to the servo and next we calibrated the servo using the code below.

//Center Servos

#include <Servo.h>

Servo servo;

void setup()

{

servo.attach(11);

}

void loop()

{

servo.write(90);

}

This code makes sure the servo works and can be change the the degree that we needed.

Below is how we connected the sensor and the servo to the Arduino board. Pin 1,2 on the sensor

is 5V and GND therefore its connected to + and – terminal of the circuit board respectively.

Below is the picture of the servos and the sensor connect to the pin of the Arduino perspectively.

Page 4: Arduino Final Project

Figure 1.1 – Pins needed to be connect to the Arduino

Figure 1.2 – How the pins needs to connect to the Arduino

Page 5: Arduino Final Project

Figure 1.2 – Pins connect to the Servo. The 2 White wires are GND and Power and Green is

signal which connect to pin 9 on the Arduino.

We choose to do a tank control mode for the turning since there are no mechanic part of the

rover that let us maneuver it using the default setup. To use the tank control mode of the rover

we connect the left side motors of the rover to the first 2 slots in the motor shield connector and

the right side to the last 2 slots of the motor shield. To make sure the wire stay connected and not

compromise the power connection between the shield and the motors we twist the wires together

to make one single input to the slot. Below is the picture of the finish product should look like.

Figure 1.4 – DC motors connections

Page 6: Arduino Final Project

Now this is the code we use to try to make this obstacles avoidance vehicle system works.

#include <Servo.h> // Include Servo library

Servo myservo; // create servo object to control a servo

int E1 = 5;

int M1 = 4;

int E2 = 6;

int M2 = 7;

int safety = 1516 ;

int pos=0; // variable to store the servo position

int URPWM=3; // PWM Output 0-25000us,every 50us represent

1cm

int URTRIG=10; // PWM trigger pin

boolean up=true; // create a boolean variable

unsigned long time; // create a time variable

unsigned long urmTimer = 0; // timer for managing the sensor reading flash

rate

unsigned int Distance=0;

uint8_t EnPwmCmd[4]={0x44,0x22,0xbb,0x01}; // distance measure command

void setup(){ // Serial initialization

Serial.begin(9600); // Sets the baud rate to 9600

myservo.attach(9); // Pin 9 to control servo

Page 7: Arduino Final Project

PWM_Mode_Setup();

}

void loop(){

forward();

scan90();

PWM_Mode();

rover();

delay(1000);

}

void scan90(){

if(millis()-time>=500){ // interval 0.02 seconds

time=millis(); // get the current time of program

if(up){ // judge the condition

if(pos>=90 && pos<=179){

pos=pos+0; // in steps of 1 degree

myservo.write(pos); // tell servo to go to position in variable 'pos'

}

if(pos>179) up= false; // assign the variable again

}

else {

if(pos>=90 && pos<=180){

pos=pos-0;

Page 8: Arduino Final Project

myservo.write(pos);

}

if(pos<1) up=true;

}

}

if(millis()-urmTimer>50){

urmTimer=millis();

}

}

void scan180(){

if(millis()-time>=500){ // interval 0.02 seconds

time=millis(); // get the current time of programme

if(up){ // judge the condition

if(pos>=0 && pos<=179){

pos=pos+90; // in steps of 1 degree

myservo.write(pos); // tell servo to go to position in variable 'pos'

}

if(pos>179) up= false; // assign the variable again

}

else {

if(pos>=1 && pos<=180){

pos=pos-90;

Page 9: Arduino Final Project

myservo.write(pos);

}

if(pos<1) up=true;

}

}

if(millis()-urmTimer>50){

urmTimer=millis();

}

}

void rover(){

while(Distance > safety){

forward();

PWM_Mode();

}

if(Distance <= safety){

avoid();

}

}

void avoid(){

backward();

left();

forward();

Page 10: Arduino Final Project

right();

left();

}

void PWM_Mode_Setup(){

pinMode(URTRIG,OUTPUT); // A low pull on pin COMP/TRIG

digitalWrite(URTRIG,HIGH); // Set to HIGH

pinMode(URPWM, INPUT); // Sending Enable PWM mode command

for(int i=0;i<4;i++){

Serial.write(EnPwmCmd[i]);

}

}

void PWM_Mode(){ // a low pull on pin COMP/TRIG triggering a

sensor reading

digitalWrite(URTRIG, LOW);

digitalWrite(URTRIG, HIGH); // reading Pin PWM will output pulses

unsigned long DistanceMeasured=pulseIn(URPWM,LOW);

if(DistanceMeasured==15000){ // the reading is invalid.

Serial.print("Invalid");

}

else{

Page 11: Arduino Final Project

Distance=DistanceMeasured; // every 50us low level stands for 1cm

}

Serial.print("Distance=");

Serial.print(Distance);

Serial.println("cm");

}

void forward(){

digitalWrite(M1,HIGH); //forward

digitalWrite(M2, HIGH);

analogWrite(E1, 150); //PWM Speed Control

analogWrite(E2, 150); //PWM Speed Contro

delay(1000);

}

void backward(){

digitalWrite(M1,LOW); //backwards

digitalWrite(M2, LOW);

analogWrite(E1, 150); //PWM Speed Contro

analogWrite(E2, 150); //PWM Speed Control

delay(1000);

}

Page 12: Arduino Final Project

void right(){

digitalWrite(M1,HIGH); //clockwise turn right

digitalWrite(M2, LOW);

analogWrite(E1, 100); //PWM Speed Control

analogWrite(E2, 150); //PWM Speed Control

delay(1000);

}

void left(){

digitalWrite(M1,LOW); //counter clockwise turn left

digitalWrite(M2, HIGH);

analogWrite(E1, 150); //PWM Speed Control

analogWrite(E2, 100); //PWM Speed Control

delay(1500);

}

void hault(){

digitalWrite(M1, LOW);

digitalWrite(M2, LOW);

analogWrite(E1, 0);

analogWrite(E2, 0);

delay(1000);

}

Page 13: Arduino Final Project

Here is how the code works. For the sensor we use the PWM mode. The PWM trigger, pin

COMP/TRIG produces a low level of triggered pulse signal starting distance measurement

operation once. The program started out by going forward and scanning what is in front of it. If

the distance measured smaller than 1516 which is 12 inches then the rover will start a function

called avoid, which supposedly will help he rover maneuver around the object and continue on

its merry way. After it done maneuver around the object the code which is on a loop. The code

reset and the rover will scan again after it finishes the function avoid and it continue till it stops

by the user or the terrain. The resources for the sensor and the motor shield are from DFRobot

website that we have modified and implemented into our design.

RESULT

The result for this project is extremely underwhelming. The project we attempted to do is

incomplete. The rover can avoid the object but once the rover goes around the obstacles the

wheels refuses to have the right traction we needed for it to go forward. Instead the traction

keeps leading it to another way that we cannot seems to control whether how much time to

calibrate it. The sensor decided to stop working in autonomous mode but after being changed to

PWM mode seems to work but not as accurate.

CONCLUSION

Even though this project is a fascinating experience, we encountered numerous bugs and

roadblock that can’t seems to be pass. For example, in the last report the traction was our worst

Page 14: Arduino Final Project

enemy. It took us way too much time to calibrate it and still it was a pain to get through. Hours

and hours was put into just to get the wheels to turn a certain degree. The sensor was inaccurate

for the longest time and we have to use PWM mode instead of TTL mode, auto measure mode.

In the end, we could not complete the project due to the insufficient of time for more research

and incompetent equipment. If we have a choice of doing things differently we would have

choose to reverse engineer an RC car and then build the project from there with a less

complicated sensor since there is no need for an industrial ultrasonic sensor if we just wanted to

get the distance of some object.

REFERENCE:

Seale, Eric. "DC Motors -- Background and History." DC Motors -- Background and

History. Solarbotics Websites, n.d. Web. 10 May 2016.

"Motor Shield v 1.2." - Robot Wiki. N.p., n.d. Web. 10 May 2016.

"Obstacle Avoidance." Wikipedia. Wikimedia Foundation, n.d. Web. 10 May 2016.

"URM37 v 4.0" - Robot Wiki. N.p., n.d. Web. 10 May 2016.


Recommended