Author Topic: IR sharp rangefinder  (Read 7820 times)

0 Members and 1 Guest are viewing this topic.

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
IR sharp rangefinder
« on: January 14, 2008, 02:54:39 PM »
hey, its me again... sorry guys ive been a bit of a pest with this. but... my major accomplishment

the robot runs in a strait line...

the drawback...

thats all it can do  ::)

I need your help with 3 things.

what is the exact code in C to gather a value from my sharp IR range finder
how do I convert the number to volts and then to feet or inches???
how do I make my robot turn its servo 45 and 90 degrees left and right??? Ive looked at the things on the arduino playground and they are confusing the crap out of me, please help, i have till the 20th to get this thing working

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #1 on: January 15, 2008, 02:44:22 PM »
anyone?? please guys i need some help with this. I searched but I cant find anything.

Offline bukowski

  • Robot Overlord
  • ****
  • Posts: 219
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #2 on: January 15, 2008, 02:54:27 PM »
just use the code off the $50 robot tut.

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: IR sharp rangefinder
« Reply #3 on: January 15, 2008, 03:16:56 PM »
or if your terrified of microcontrollers like me use the $40 robot ::)
Howdy

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #4 on: January 15, 2008, 03:54:12 PM »
smash, the robots done dude... i just need to program it...

new error, im using the arduino programmer and i got this


hardware\libraries\servo/avrlibtypes.h:70: error: expected unqualified-id before numeric constant


Couldn't determine program size: C:\Documents and Settings\Nick.GATEWAY\My Documents\winavr\arduino\arduino-0010\hardware/tools/avr/bin/avr-size: 'C:\DOCUME~1\NICK~1.GAT\LOCALS~1\Temp\build14969.tmp\forward_reverse.hex': No such file
« Last Edit: January 15, 2008, 03:56:03 PM by maverick monk »

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #5 on: January 16, 2008, 05:49:32 PM »
sorry for double posting like this but my deadline is comming up FAST! need some help. thanks in advance

Offline DomoArigato

  • Full Member
  • ***
  • Posts: 54
  • Helpful? 1
Re: IR sharp rangefinder
« Reply #6 on: January 16, 2008, 07:23:48 PM »
What chip are you using?  ATMega168?  What part of the programming is making it difficult?  The software, or just loading it on?  To get input from the IR Rangefinder you have to use the ADC on the chip.  To output to a servo, you'll probably want to use the Timer in PWM mode.  I have some code for the 128 if it would help.

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #7 on: January 16, 2008, 07:25:39 PM »
i get that error every time i test it to see if it works, it cant find the hex file in the temp folder

Offline DomoArigato

  • Full Member
  • ***
  • Posts: 54
  • Helpful? 1
Re: IR sharp rangefinder
« Reply #8 on: January 16, 2008, 10:45:59 PM »
I haven't actually made the 50$ robot.  So I'm not sure how much I can help you.  Does the code compile with that numeric constant error?  Is there a hex file in that directory where the programmer is looking or is it failing to build the hex file because of the compile error? C:\DOCUME~1\NICK~1.GAT\LOCALS~1\Temp\build14969.tmp\forward_reverse.hex  You may have more luck if you start a topic like "Trouble loading hex file onto Arduino"  so people with experience there will open up the thread.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,663
  • Helpful? 169
    • Society of Robots
Re: IR sharp rangefinder
« Reply #9 on: January 17, 2008, 09:27:30 AM »
To use the sharp IR, you just need to read the analog pin.

Code: [Select]
IR_value = analogRead(0);//use pin 0 for analog
for servos, do something like this:

Code: [Select]
digitalWrite(13, HIGH);    // turns port 13 on
delay(120);                  // delay determines servo speed/position
digitalWrite(13, LOW);    // turns port 13 off

I don't know exactly what delay will work, so guess some values between like 30 and 300 until it works.

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #10 on: January 17, 2008, 05:12:50 PM »
thanks for the help but, How do i find the right integer for my IR, its always enabled it seems

void setup()
{
}
void loop()                     
{
 int IR_value;
 int IR_Loop;
 //Forward Motion
 digitalWrite(2, LOW);   //lReverse
 analogWrite(3, 255);       //lForward
 digitalWrite(4, HIGH);   //lEnable
 analogWrite(5, 0);     //rReverse
 analogWrite(6, 255);       //rForward
 digitalWrite(7, HIGH);   //rEnable
 delay(20);
 digitalWrite(2, LOW);   //lReverse
 analogWrite(3, 0);       //lForward
 digitalWrite(4, LOW);   //lEnable
 analogWrite(5, 0);     //rReverse
 analogWrite(6, 0);       //rForward
 digitalWrite(7, LOW);      //rEnable
 delay(20);
 
 IR_value = analogRead(1);//use pin 0 for analog
 
 if(IR_value <=110)
 {
   digitalWrite(2, LOW);   //lReverse
   analogWrite(3, 255);       //lForward
   digitalWrite(4, HIGH);   //lEnable
   analogWrite(5, 255);     //rReverse
   analogWrite(6, 0);       //rForward
   digitalWrite(7, HIGH);   //rEnable
   delay(2000);
   
 }
}

when it turns on it goes strait to the if block and wont leave, no matter what i make the IF statement, what am I doing wrong?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,663
  • Helpful? 169
    • Society of Robots
Re: IR sharp rangefinder
« Reply #11 on: January 17, 2008, 06:12:14 PM »
This is because your delay values are totally off . . . and that you aren't doing proper servo control:

turn port on
delay
turn port off

Don't try to do everything at once, just try to get one servo to change directions first.

When that works, then add the sensor, then the other servos.

This makes debugging much easier. Try a delay of like 220 and see what happens.

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #12 on: January 17, 2008, 06:28:33 PM »
thats not with the servo, thats with the hbridge, i just cant get the if statement right to get a normal threshold for the IR

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: IR sharp rangefinder
« Reply #13 on: January 17, 2008, 06:43:26 PM »
okay, i have similar issues with C18 for pics. If I use <=  or >= in an if statement it doesnt work, I need to just use <  or > and then an else for the middle vale

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #14 on: January 17, 2008, 07:11:19 PM »
ok, im not getting good readings from this thing, what could be wrong???

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: IR sharp rangefinder
« Reply #15 on: January 17, 2008, 07:21:48 PM »
connect an LCD to it ( if you have one) to see the values in real time
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #16 on: January 17, 2008, 07:23:59 PM »
If i could pull a lcd outa my butt and programm it... thatd be great!, is there a way to printf the variable to the arduino programming environment in real time??? if so, how, (exactly how, im realy not so good at this yet)

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: IR sharp rangefinder
« Reply #17 on: January 17, 2008, 08:31:27 PM »
I think the arduino has a max232 serial comms chip on board, you can just do a serial transfer with it if so. Use hyperterminal in windows to view the output. See admins uart tutorial for more info

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #18 on: January 17, 2008, 08:46:11 PM »
why cant it just work??? can anyone help me diagnose this thing? i dont have time to do a uart thing with a serial port adapter or anything like that

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: IR sharp rangefinder
« Reply #19 on: January 17, 2008, 09:13:14 PM »
why cant it just work??? can anyone help me diagnose this thing? i dont have time to do a uart thing with a serial port adapter or anything like that

You mean you dont have patience  :P .

Listen , knowing how to do UART is a very good skill to have . Learn it now!
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: IR sharp rangefinder
« Reply #20 on: January 17, 2008, 09:31:07 PM »
okay,

so ive never used an arduino board, but i checked a tutorial just for you.....

Quote
IR_value = analogRead(1);//use pin 0 for analog


in this url http://www.arduino.cc/en/Tutorial/Knock
it uses analogRead(0) for pin 0 and not analogRead(1).

Could this be your problem?

Offline frank26080115

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: IR sharp rangefinder
« Reply #21 on: January 18, 2008, 12:23:15 AM »
okay,

so ive never used an arduino board, but i checked a tutorial just for you.....

Quote
IR_value = analogRead(1);//use pin 0 for analog


in this url http://www.arduino.cc/en/Tutorial/Knock
it uses analogRead(0) for pin 0 and not analogRead(1).

Could this be your problem?


You bet, and damn, I was reading the entire thread thinking nobody was going to pick it up.

I can see you are using something like an L298
You are supposed to use PWM on the enable pin, not the digital inputs

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #22 on: January 18, 2008, 09:59:08 AM »
im using analog pin 1 instead of 0, hence the 1 instead of the 0, does that cause a problem???

the drive works fine, everything powerrelated is working fine but the sensor wont give me a good value. I realy dont have time to mess with uart, i need to have atleast a basic version (without sensor/servo sweep) working by tuesday. so,

do I need to use analog port 0? or can I use 1 like im doing now?
im assuming that whatever port im using goes in the ()'s.  right?
or is it somthing else? like starting value or somthing... maby robotics wasnt a good idea for a sophmore highschool science fair... oops  ::)

edit!: it works... turns out sparkfun got the lables for their analog pins on the sheild kit backwards, i was pluged into pin 4 even tho it said 1 on the sheild (which covered up the origional kits markings...)

dont you love it when the small stuff doesnt work??? testing my code now,but im getting values from my sensor now :) !
« Last Edit: January 18, 2008, 02:39:26 PM by maverick monk »

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #23 on: January 20, 2008, 11:59:02 AM »
Ok, now i got the IR working flawlessly, thanks to all of your help. but no matter what I do  the only way I can get the servo to go is to the right, how do I get it to go back to the left??? thanks in advance to any answers.

Offline Bubbles

  • Full Member
  • ***
  • Posts: 53
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #24 on: January 21, 2008, 08:11:37 PM »
This should help you a bit with making the servos go the other way:

http://www.societyofrobots.com/robotforum/index.php?topic=2724.0

good luck!  ;D

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #25 on: January 22, 2008, 05:37:18 PM »
ill try to figure that out,thanks, but now my robot keeps traveling in circles! wtf??? the code worked 2 days ago???? I hate this project...im trying to figure this out, but now my trax keep falling off and I need to build a tensioner

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: IR sharp rangefinder
« Reply #26 on: January 22, 2008, 05:46:28 PM »
Quote
OK tjpark11 I GOT IT , IT JUST POPPED INTO MY HEAD!!!   Cheesy


BUY THE SAME SERVOS  ( regular clockwise for both)

then when you get the servos , open one of them up and reverse the wires going to the motor . There you got one going clockwise and one going anticlockwise on the same pulse!

I just thought of this now and I'm going to be doing this for all my servos in the future. After I modify them , ill switch the wires of one of them so I have one universal pulse for forward and one for backward.

ADMIN PUT THIS IN YOUR SERVO MODIFYING TUTORIAL!!!

an idea which popped into my head today, I posted this response elsewhere on the forum
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #27 on: January 22, 2008, 06:01:10 PM »
what does that have to do with anything???

im not using servo's for drive, im using a dualH bridge.

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: IR sharp rangefinder
« Reply #28 on: January 22, 2008, 06:29:16 PM »
oh sorry I thought you were using servos   ::)

so how is it going in circles, one going forward one backward or just one forward
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline maverick monkTopic starter

  • Robot Overlord
  • ****
  • Posts: 204
  • Helpful? 0
Re: IR sharp rangefinder
« Reply #29 on: January 22, 2008, 07:22:35 PM »
it doesnt go in circles anymore... the track gears stripped and I had to make some bs wheels (hot glue and rc car wheels) now it doesnt seem to have any formal thought at all... it just does whatever, whenever, i think the sensor might be getting junk readings. but im realy begining to HATE THIS THING!

btw... i got 54 hours to get this thing working, aproximatly

 


Get Your Ad Here