Society of Robots - Robot Forum

Software => Software => Topic started by: maverick monk on January 14, 2008, 02:54:39 PM

Title: IR sharp rangefinder
Post by: maverick monk 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
Title: Re: IR sharp rangefinder
Post by: maverick monk on January 15, 2008, 02:44:22 PM
anyone?? please guys i need some help with this. I searched but I cant find anything.
Title: Re: IR sharp rangefinder
Post by: bukowski on January 15, 2008, 02:54:27 PM
just use the code off the $50 robot tut.
Title: Re: IR sharp rangefinder
Post by: SmAsH on January 15, 2008, 03:16:56 PM
or if your terrified of microcontrollers like me use the $40 robot ::)
Title: Re: IR sharp rangefinder
Post by: maverick monk 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
Title: Re: IR sharp rangefinder
Post by: maverick monk 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
Title: Re: IR sharp rangefinder
Post by: DomoArigato 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.
Title: Re: IR sharp rangefinder
Post by: maverick monk 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
Title: Re: IR sharp rangefinder
Post by: DomoArigato 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.
Title: Re: IR sharp rangefinder
Post by: Admin 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.
Title: Re: IR sharp rangefinder
Post by: maverick monk 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?
Title: Re: IR sharp rangefinder
Post by: Admin 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.
Title: Re: IR sharp rangefinder
Post by: maverick monk 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
Title: Re: IR sharp rangefinder
Post by: paulstreats 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
Title: Re: IR sharp rangefinder
Post by: maverick monk on January 17, 2008, 07:11:19 PM
ok, im not getting good readings from this thing, what could be wrong???
Title: Re: IR sharp rangefinder
Post by: airman00 on January 17, 2008, 07:21:48 PM
connect an LCD to it ( if you have one) to see the values in real time
Title: Re: IR sharp rangefinder
Post by: maverick monk 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)
Title: Re: IR sharp rangefinder
Post by: paulstreats 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
Title: Re: IR sharp rangefinder
Post by: maverick monk 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
Title: Re: IR sharp rangefinder
Post by: airman00 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!
Title: Re: IR sharp rangefinder
Post by: paulstreats 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 (http://www.arduino.cc/en/Tutorial/Knock)
it uses analogRead(0) for pin 0 and not analogRead(1).

Could this be your problem?
Title: Re: IR sharp rangefinder
Post by: frank26080115 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 (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
Title: Re: IR sharp rangefinder
Post by: maverick monk 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 :) !
Title: Re: IR sharp rangefinder
Post by: maverick monk 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.
Title: Re: IR sharp rangefinder
Post by: Bubbles 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
Title: Re: IR sharp rangefinder
Post by: maverick monk 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
Title: Re: IR sharp rangefinder
Post by: airman00 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
Title: Re: IR sharp rangefinder
Post by: maverick monk 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.
Title: Re: IR sharp rangefinder
Post by: airman00 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
Title: Re: IR sharp rangefinder
Post by: maverick monk 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
Title: Re: IR sharp rangefinder
Post by: Bubbles on January 22, 2008, 11:22:08 PM
By:

now it doesnt seem to have any formal thought at all... it just does whatever, whenever

do you mean that it is making random movements or is it seemingly picking random tasks you have already defined? i.e. sometimes it will turn left as if it has sensed something, that kind of thing.
Title: Re: IR sharp rangefinder
Post by: lavren on October 13, 2008, 04:45:38 PM
Wow, for someone requesting help, Maverick sure is a rude S.O.B.
Title: Re: IR sharp rangefinder
Post by: airman00 on October 14, 2008, 04:16:34 PM
did it end up working?