Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: Kohanbash on April 07, 2008, 08:27:42 AM

Title: Sharp IR range detector
Post by: Kohanbash on April 07, 2008, 08:27:42 AM
Hi
Admin (or anyone else) can you say quickly what your experience is with the sharp IR's with respect to error in returned distance and how it changes with different lighting conditions.

Also do you have a recommendation for how far they should be apart from each other in order to avoid false returns (ghost returns, etc...)
Title: Re: Sharp IR range detector
Post by: superchiku on April 07, 2008, 08:48:03 AM
wouldn't it be better if u just look at the sharp ir tutorial
Title: Re: Sharp IR range detector
Post by: Kohanbash on April 07, 2008, 08:56:31 AM
wouldn't it be better if u just look at the sharp ir tutorial
Before posting I checked the tutorial and searched the forum.

The fact that there is an affect from lighting and interference between devices is mentioned, however I am asking from peoples experience what that effect really is so that I can determine whether the sensor will work for my application.
Title: Re: Sharp IR range detector
Post by: superchiku on April 07, 2008, 09:17:05 AM
 well iam a kind of a sharp ir supporter, well yess we do get interference by light when using sharp ir's but the interference is minimum , offcourse sharp ir's wont work well in direct sunlight but normally sharp ir's are pretty powerful sensors and work well indoors, if u want i can supply u a graph which interprets different digital readings at different distances for a gp2d12 and also a general equation which will let u interpret the distance by looking at the digital reading..
Title: Re: Sharp IR range detector
Post by: Kohanbash on April 07, 2008, 09:22:32 AM
Do you have any plots showing reported distance vs actual distance
Title: Re: Sharp IR range detector
Post by: superchiku on April 07, 2008, 09:46:50 AM
i told ya its the reading for distance vs digital reading ,

and the graph is not linear so u have to use the equation which i derives to know the distance for any digital reading
Title: Re: Sharp IR range detector
Post by: Kohanbash on April 07, 2008, 05:46:37 PM
superchiku - Right I understand that. I am going to rephrase my questions.

How repeatable is it (whats the change in voltage between readings at the exact same distance)?
What is the change in voltage output relative to different lighting conditions (at the exact same location)?
Does anyone have experience/suggestions about how close I can put multiple sensors with out needing to worry about false returns?

Thanks,
sdk32285
Title: Re: Sharp IR range detector
Post by: Admin on April 11, 2008, 07:08:15 AM
The sharp IR is VERY noisy as a sensor.

Hook it up to an oscope and you will see. You need to put a noise filter to make it useful. I haven't had time to experiment, but I'm thinking a cap across ground and output might fix it. An averaging algorithm won't work - the nose is too high and throws the average off.

As for environment sensitivity, I'm starting to find that different models are affected differently. I wish I had an answer . . .

Most recently, I tested a GP2Y0A21YK in bright direct sunlight without problems. But I haven't done a controlled 'lab test' . . .
Title: Re: Sharp IR range detector
Post by: benji on April 11, 2008, 10:30:09 AM
Quote
but I'm thinking a cap across ground and output might fix it.
i have this sensor and i will attempt to put a cap between output and ground,but,, what capasitance value is good for this?
the value would totally depend on how fast the out changes(how fast is the noise)

have you seen this on an osci? what value do you recommend?
Title: Re: Sharp IR range detector
Post by: superchiku on April 11, 2008, 10:54:03 AM
i think the admin has already provided an ingenious solution to the problem like using the auto calibrate mode, where the sensor autmatically calibrates the threshold in the intial moments when the robot is switched on no matter what the lighting conditions may be..
Title: Re: Sharp IR range detector
Post by: killsto on April 11, 2008, 08:50:53 PM
An equation for the GP2Y0A21YK would be greatly appreciated. I can find equations for other sensors but not this one. I did find the graph though.
Title: Re: Sharp IR range detector
Post by: superchiku on April 12, 2008, 02:05:41 AM
try to make an eqn urself by taking the digital readings and plotting them in excel
Title: Re: Sharp IR range detector
Post by: Ro-Bot-X on April 12, 2008, 02:14:42 AM
try to make an eqn urself by taking the digital readings and plotting them in excel

You see, exactly how you don't understand how it's done something unless you look exactly at the code, other people may be doing the same. For you it is simple to take the readings, dump them on the PC and plott them in excel. But for others that have no ideea what you are talking about this is chinese. So, if you expect complete answers to your questions, do the same for other people, otherways it's just talk in the wind...
Title: Re: Sharp IR range detector
Post by: superchiku on April 12, 2008, 03:04:11 AM
well , its because benji asked a similar question earlier and i gave a complete reply to that question so i was hoping that the asker would know to look for it but since u say that iam not answering properly then i would answer properly now,

see how u can plot the equation and all , ull find that in the advanced sensor interpretation tutorial..

now abt the uart what u got to do is that use my code which i have written and connect ur serial port of ur computer to the serial of ur uart . just connect the analog voltage out of the sharp ir to the pin no 0 of atmega16's port a and when u switch your hyperterminal on you will be to see your digital reaings at a gap of 2 secs... if you are using any other mcu of avr series then change the appropriate mux value in the code , if  you are using any other mcu then i  guess you have to make your own code by looking at the uart tutorial of this site..

here is the code

Code: [Select]
# include<stdio.h>
# include<avr/io.h>

# include<util/delay.h>
# include<avr/interrupt.h>
# include<stdlib.h>
# include<string.h>
# include<avr/pgmspace.h>



#define USART_BAUDRATE 38400
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL)))- 1)


 char u[11]="adcvalue\r\n";
 char *d;
 char b[10];
 char *p;
 
 unsigned int a;

void adcinitialize();
void uartinitialize();
void adcgetvalue();
void transferusart();
void printvalue(char *);

 int main(void)
  {
   adcinitialize();
   uartinitialize();
   while(1)
    {
adcgetvalue();

     
p=itoa(a,b,10);

strcat_P(b,PSTR("\r\n"));

d=&u[0];

transferusart();

     
     }       
   

   return(0);
   }
 
 
 
 void adcinitialize()
  {
   
  ADCSRA|=_BV(7)|_BV(ADPS2)|_BV(ADPS1);
  ADMUX=0x60;
  ADCSRA|=(1<<ADSC);
  while(!(ADCSRA & (1<<ADIF)));
  ADCSRA|=(1<<ADIF);
  TCCR1B|=(1<<CS12);
 
  }
 
  void uartinitialize()
   {
    UCSRB= (1<<RXEN) | (1<<TXEN);
    UCSRC= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
    UBRRL=BAUD_PRESCALE;
UBRRH=(BAUD_PRESCALE>>8);
   }
void adcgetvalue()
 {
 
   ADMUX=0x61;
   ADCSRA|=(1<<ADSC);
  while(!(ADCSRA & (1<<ADIF)));
  ADCSRA|=(1<<ADIF);
  a=ADCH;
 }
 
void transferusart()
 {
   
   while (*d != '\0')
    {

     while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it
      UDR =*d ; // Echo back the received byte back to the computer
      d++;
}
TCNT1=0;
while(TCNT1<=60000){};
TCNT1=0;
 printvalue(p);
 }
 
 void printvalue(char *l)
  {
   
   while (*l != 0x00)
    {
 

  while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it
      UDR =*l ; // send out each bit of charcter to your computer
     
     
     l++;
    }
TCNT1=0;
while(TCNT1<=60000){};
TCNT1=0;
  }
 

   

oh yes i configured my atmega16 for the 8mhz internal oscillator and used a baud rate of 38400 , u can do the same or change as per ur requirement.
Title: Re: Sharp IR range detector
Post by: paulstreats on April 12, 2008, 05:08:49 AM
Quote
but I'm thinking a cap across ground and output might fix it. An averaging algorithm won't work - the nose is too high and throws the average off.
I may try this at some point, it should leave less work to do in software.

I have noticed though that when i increase the adc aquisition time, I get barely no spikes whatsoever. It just takes longer to take a reading. I think that the internal adc capacitor smooths the noise and the spikes itself if you give it a chance to. (I only did this last night while trying to find the best setting for my ir emitter/detector pairs using hyperterminal to view the changeing values, my ouput print function samples all sensors and outputs them to hyperterminal, and i was surprised to see the sharp ir not producing any spikes)
Title: Re: Sharp IR range detector
Post by: killsto on April 12, 2008, 07:46:08 AM
try to make an eqn urself by taking the digital readings and plotting them in excel

I don't have excel.
Title: Re: Sharp IR range detector
Post by: superchiku on April 12, 2008, 08:32:26 AM
well in order to get the eqn u need to have ms excel coz i dont know of any other software which can help ...
Title: Re: Sharp IR range detector
Post by: AndrewM on April 12, 2008, 09:19:18 AM
The sharp IR is VERY noisy as a sensor.

Hook it up to an oscope and you will see. You need to put a noise filter to make it useful. I haven't had time to experiment, but I'm thinking a cap across ground and output might fix it. An averaging algorithm won't work - the nose is too high and throws the average off.

Do you think a 0.1 uF capacitor would be enough (or too much) to smooth out the noise from what you saw on the oscope? 
Title: Re: Sharp IR range detector
Post by: superchiku on April 12, 2008, 12:16:35 PM
may be may be not but i guess it will be, if it doesnt work just use a higher value
Title: Re: Sharp IR range detector
Post by: benji on April 12, 2008, 03:26:34 PM
Quote
I don't have excel.
  use MATLAB, the function is called polyfit

Quote
Do you think a 0.1 uF capacitor would be enough (or too much) to smooth out the noise from what you saw on the oscope? 
its all a matter of how fast the output changes ,,you have to check it with an osci then evaluate best cap value as you have 1/(2(pi).f.c) as the impedance .
Title: Re: Sharp IR range detector
Post by: AndrewM on April 12, 2008, 06:56:37 PM
If I had an oscope or even a sharp IR sensor I suppose I could hook it up and see.  I have 4 sensors on order and when they get here I was hoping for a ballpark based on someone elses observations so I could avoid hours of trial and error (once again, still no oscope).
Title: Re: Sharp IR range detector
Post by: benji on April 13, 2008, 10:20:58 AM
Quote
I could avoid hours of trial and error

these are the stuff that builds ya  ;)
Title: Re: Sharp IR range detector
Post by: superchiku on April 13, 2008, 01:52:36 PM
a scope is very costly , i dont know if other people have but i atleast dont have it...

besides a certain degree of error can be dealt with , its not wise to spend $$$ on a scope for just minor error detection
Title: Re: Sharp IR range detector
Post by: benji on April 13, 2008, 02:10:17 PM
i would never buy a scope, i go to the college to try my stuff ;D
Title: Re: Sharp IR range detector
Post by: AndrewM on April 13, 2008, 04:39:09 PM
i would never buy a scope, i go to the college to try my stuff ;D

Show off  :P

But if you happen to have a sharp ir with you next trip to the electronics lab, please let me know what freq and voltage you see any noise at.  Or even the rate of change for normal detection.  I know all the sharp irs are going to be different,e specially between models, but a good ball park to base my guessing off would be helpful.
Title: Re: Sharp IR range detector
Post by: benji on April 14, 2008, 03:49:50 AM
Quote
But if you happen to have a sharp ir with you next trip to the electronics lab, please let me know what freq and voltage you see any noise at.  Or even the rate of change for normal detection.  I know all the sharp irs are going to be different,e specially between models, but a good ball park to base my guessing off would be helpful.

dont worry , i will
Title: Re: Sharp IR range detector
Post by: Admin on April 20, 2008, 03:33:25 PM
Quote
I have noticed though that when i increase the adc aquisition time, I get barely no spikes whatsoever. It just takes longer to take a reading.
Yea I do that too, but its still not enough. This is just a hardware averager, like my capacitor idea.

Ideally, you need a filter that passes low spikes but completely ignores large spikes.

To determine what capacitor to use, get several and look at how the output changes. I'm guessing like a 1uF range would do it.

Quote
I don't have excel.
You just need graphing software. OpenOffice, although buggy, could probably do it.

If you guys haven't read this post already, please do:
http://www.societyofrobots.com/robotforum/index.php?topic=2712.0
It includes my oscope reading of a sharp IR.
Title: Re: Sharp IR range detector
Post by: benji on April 21, 2008, 11:33:27 AM
about the GP2Y0A02YK,,,,,
i did try to get readings by a micro controller atmega32 sending readings to hyperterminal
when im reaching ranges about 100 cm and above the thing is totally giving weird outs
i dont have a clue now about it
its gives acceptable outs before reachin 100 cm ranges
im using single converstion mode in the adc
,,what could be wrong ???
Title: Re: Sharp IR range detector
Post by: superchiku on April 21, 2008, 11:49:27 AM
my sharp ir has a range of 10 to 80 cm dont you think that signifiess anything if the distance is under 10 cm then the analog reaing will be gibberish , same can be applied to your sensor, just look at the graph it may explain something
Title: Re: Sharp IR range detector
Post by: pomprocker on April 21, 2008, 12:02:42 PM
try to make an eqn urself by taking the digital readings and plotting them in excel

I don't have excel.

try http://www.openoffice.org (http://www.openoffice.org)
Title: Re: Sharp IR range detector
Post by: benji on April 21, 2008, 03:40:55 PM
Quote
is under 10 cm then the analog reaing will be gibberish
my sensor says thats it gets 20-150 cm ranges
and its still givin gibberish at 100-150
 :-\
Title: Re: Sharp IR range detector
Post by: superchiku on April 22, 2008, 08:11:55 AM
hmm .. can u esactly tell what the actual values are ..
Title: Re: Sharp IR range detector
Post by: benji on April 22, 2008, 10:03:52 AM
well i dont have em at the moment my friend is doin this thing so once they are done ill get em 4 ya
Title: Re: Sharp IR range detector
Post by: superchiku on April 22, 2008, 10:07:19 AM
ok ! are they numerical but strange numerical values or they are completely not recognisable
Title: Re: Sharp IR range detector
Post by: benji on April 22, 2008, 11:14:00 AM
pretty much numerical,,but sometimes unexpected..specially after 100 cm it starts to out values the same as 70 cm,,,weird!!!
Title: Re: Sharp IR range detector
Post by: superchiku on April 23, 2008, 12:37:05 AM
then it isnt gibberish , see my sharp ir has a range of 80 cm but i get gibberish value from 75 cm onwards like as if it is equal to 12 cm may be this is one of the disadvantages of sharp ir's