International Brain Need to develop Robotic special features

2,260 Views
Forum topic by Canadian Robot on Wed, 2011-09-14 09:49   Posted in Programming
Canadian Robot's picture

Hello everybody !

 

My project use a wheelchair base ( 2 x 24 volts motors ) for power  I use a Sabertooth 2 x 25 V2 motor controller & RC Tx and Rx to drive it

 

Now my new project is ; using the Kawal Arduino Bot electronic ( Arduino Uno &  Robot builder's shield V2  ) to drive my Sabertooth using the motor output of the Robo builder shield  to the Sabertooth 5 volts input

Due to my robot's size I have to replace IR Sharp by 2 long range Sharp.  My question is:   I need help to modify the  code used by Kawal for his Arduino Bot .

The best way for me is a combination of Arduino Bot and Object tracker with two sharp  ( long range ) !!!!!!!!!!!

Thank you for your help, I'll be waiting for your comments.

I'M good in electronic but my bad side is programming !!

Please excuse my english wording because I'm Canadian french

Michel

Canadian Robot

This is the basic code

#include <Servo.h>

Servo head;

int irpin = 3 ;

int headpin = 12;

int lmotorpin1 = 8;

int lmotorpin2 = 9;

int rmotorpin1 = 4;

int rmotorpin2 = 5;

int dist = 0;

int dist1 = 0;

int danger = 400;

int leftdist = 0;

int rightdist = 0;

void setup () {

Serial.begin(9600);

pinMode(lmotorpin1,OUTPUT);

pinMode(lmotorpin2,OUTPUT);

pinMode(rmotorpin1,OUTPUT);

pinMode(rmotorpin2,OUTPUT);

head.attach(headpin);

head.write(90);

}

void loop () {

dist = analogRead(irpin);

if (dist < danger) {

forward();

}

else {

decide();

}

}

void forward() {

digitalWrite(lmotorpin1,LOW);

digitalWrite(lmotorpin2,HIGH);

digitalWrite(rmotorpin1,HIGH);

digitalWrite(rmotorpin2,LOW);

return;

}

void decide() {

hault();

lookleft();

delay(700);

leftdist = analogRead(irpin);

head.write(90);

delay(700);

lookright();

delay(700);

rightdist = analogRead(irpin);

head.write(90);

delay(700);

if (leftdist < rightdist) {

turnleft();

}

else {

turnright();

}

return ;

}

void hault() {

digitalWrite(lmotorpin1,LOW);

digitalWrite(lmotorpin2,LOW);

digitalWrite(rmotorpin1,LOW);

digitalWrite(rmotorpin2,LOW);

head.write(90);

delay(700);

return;

}

void lookleft() {

head.write(140);

return;

}

void lookright() {

head.write(40);

return;

}

void turnleft() {

digitalWrite(rmotorpin2,HIGH);

digitalWrite(rmotorpin1,LOW);

digitalWrite(lmotorpin1,LOW);

digitalWrite(lmotorpin2,HIGH);

delay(400);

return;

}

void turnright() {

digitalWrite(lmotorpin1,HIGH);

digitalWrite(lmotorpin2,LOW);

digitalWrite(rmotorpin1,HIGH);

digitalWrite(rmotorpin2,LOW);

delay(400);

return;

} 

 

 

 

__________________________________________________________________________________________

Comments

Canadian Robot's picture

Answer to Kawal

Kawal Hello, glad to hear from you!

Thank you for your good comments, now I work with ArduPilot but the precision is not very good for my project because I am trying to build a robotic mower and I need a high precision

I developed many project around EZ-Robot, I suggest you visit the web site ; EZ-ROBOT.com it is very easy to use as Arduino

I intend to add some video soon, but I have to wait because it is very cold here now

please gives me again your link to your website

Greeting from Canada

thank you
 

 
Michel Laganière 
kawal's picture

Sorry for taking so long to

Sorry for taking so long to reply .I was busy with the college.

Heres a simple code in which i have used two sharp analog sensors.Considering that you have mounted both the sensors on one servo here is a code which is a revised version of the code you posted here.

The second analog sensor is connected to analog pin 2.


#include <Servo.h>
Servo head;
int irpin = 3 ;
int irpin2 = 2;
int headpin = 12;
int lmotorpin1 = 8;
int lmotorpin2 = 9;
int rmotorpin1 = 4;
int rmotorpin2 = 5;
int dist = 0;
int dist1 = 0;
int danger = 400;
int leftdist = 0;
int rightdist = 0;
int leftdist2 = 0;
int rightdist2 =0;


void setup () {
Serial.begin(9600);
pinMode(lmotorpin1,OUTPUT);
pinMode(lmotorpin2,OUTPUT);
pinMode(rmotorpin1,OUTPUT);
pinMode(rmotorpin2,OUTPUT);
head.attach(headpin);
head.write(90);
}


void loop () {
dist = analogRead(irpin);
dist1= analogRead(irpin2);

if (dist < danger && dist1 < danger) {
forward();
}
else {
decide();
}
}


void forward() {
digitalWrite(lmotorpin1,LOW);
digitalWrite(lmotorpin2,HIGH);
digitalWrite(rmotorpin1,HIGH);
digitalWrite(rmotorpin2,LOW);
return;
}


void decide() {
hault();
lookleft();
delay(700);
leftdist = analogRead(irpin);
leftdist2 = analogRead(irpin2);
head.write(90);
delay(700);
lookright();
delay(700);
rightdist = analogRead(irpin);
rightdist2 = analogRead(irpin2);
head.write(90);
delay(700);
if (leftdist < rightdist && leftdist2 < rightdist2) {
turnleft();
}
else {
turnright();
}
return ;
}


void hault() {
digitalWrite(lmotorpin1,LOW);
digitalWrite(lmotorpin2,LOW);
digitalWrite(rmotorpin1,LOW);
digitalWrite(rmotorpin2,LOW);
head.write(90);
delay(700);
return;
}


void lookleft() {
head.write(140);
return;
}


void lookright() {
head.write(40);
return;
}


void turnleft() {
digitalWrite(rmotorpin2,HIGH);
digitalWrite(rmotorpin1,LOW);
digitalWrite(lmotorpin1,LOW);
digitalWrite(lmotorpin2,HIGH);
delay(400);
return;
}


void turnright() {
digitalWrite(lmotorpin1,HIGH);
digitalWrite(lmotorpin2,LOW);
digitalWrite(rmotorpin1,HIGH);
digitalWrite(rmotorpin2,LOW);
delay(400);
return;
}

If you need further help then please let me know.

Canadian Robot's picture

Problem ??

HI Kawal, I tried this code and one  of my motor dont work ?? view from the back the left motor dont work ? do you have an idea where the problem is on the code ?

 

Thanks for your help

 

Canadian Robot

Michel

Canadian Robot's picture

Thank you very much Kawal !!!!!!!!!!!!

Yes I have a other question for you ; I expect also to add  4 micro switch
on my robot ( like bumber switch ) to prevent shock ( impact ) 2 on the
front and 2 on the back do you know how modify this code to add this option
?

when my project is finish ( very soon ) with your help ,,, thanks again,

my next step is addition of a GPS on it , do you have any experience with GPS ? I expect to use Arduipilot ?

Regards Kawal

Have a nice day

Michel  tyuuuuugggFFFFFFiii

Anonymous's picture

You could add micro switches

You could add micro switches as you like the code modification yoll need to make is

elseif((forntswitch1==1)||(frontswitch2==1))
reverse();
elseif((backswitch1==1)||(backswitch2==1))
forward();

you'll need to declare the pin numbering of the switches in the setup and before it

also gps can be used first I'd recommend finishing this and then coming back for more information

Cheers
Roopak Jada
www.robotspace.in

Canadian Robot's picture

Thanks !

HI Roopak, thank you very much for your help !! please can you just help me to know where in the code I can put this modification and the pin numbering ?

 

Excuse my question but I'M zero on program ??

 

Thanks again

 

Michel

Add a new comment

Login or register to post comments