Shop OBEX P1 Docs P2 Docs Learn Events
ActivityBot infrared/led sensors distance — Parallax Forums

ActivityBot infrared/led sensors distance

djgsi974djgsi974 Posts: 16
edited 2014-02-21 09:07 in Robotics
Hello everybody.

I've got a question about the infrared led/sensors included with the activitybot.
In the tutorial (roaming), all we can do is to detect an object or not.
I'd like to know if it is possible to know at what distance the object is detected (like the ping sensors that already do this job).
I'd like to use the infrared sensors in addition to the ping sensors.

thanks in advance.

Comments

  • PublisonPublison Posts: 12,366
    edited 2014-02-09 10:12
    djgsi974 wrote: »
    Hello everybody.

    I've got a question about the infrared led/sensors included with the activitybot.
    In the tutorial (roaming), all we can do is to detect an object or not.
    I'd like to know if it is possible to know at what distance the object is detected (like the ping sensors that already do this job).
    I'd like to use the infrared sensors in addition to the ping sensors.

    thanks in advance.
    Your best bet would be to go with the Sharp IR Sensor to get a good distance measurement with the built in ADC.

    You could also use the technique to use IR Sensors in Chapter 8 of the Robotics with BoeBot text to give you zones.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-02-09 11:13
    The problem here is the way these particular IR sensors work. The just detected reflected IR. A lot of things will effect how well the IR sensor detects the reflected light. One is distance. If the obstacles were all the same color and placed at the same angle to the robot, you might be able to use the sensor information to detect distance. But in the real world it's hard to get an accurate distance reading from these sorts of simple IR sensors.

    The sensor Publison linked to is made to measure distance and would work much better in this application.

    Even though it's not easy to measure distance accurately, the technique Publison linked to might give you some ballpark figures.

    I'm guessing you're using C with your ActivityBot? I think it was Phil who came up with a better technique than used in the BoeBot book for measuring distance with the simple IR sensors. I think he varied the modulation frequency of the IR. I'm pretty sure the technique was done in Spin but if you're interested, I could help you find the thread.

    I believe Phil used this same technique with the Scribbler 2's IR sensor.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-02-09 11:52
    I'm not sure if this if the thread I was thinking of or not. Post #6 of the thread has some code. Make sure and check the various links posted in the thread. I think there's enough information to get some distance information from your sensors.
  • edited 2014-02-10 11:03
    The ActivityBot has a Ping))) Ultrasonic Distance Sensor in the kit for measuring cm distances up to 3 meters. http://learn.parallax.com/activitybot/navigate-ultrasound

    You can still measure distances with the ActivityBot's IR sensors if you want. Just keep in mind that unlike the Ping))), infrared distance with the ActivityBot's parts is dependent on how reflective the material is. A cool thing about measuring infrared distance is you don't even need to modify the circuit from the Navigate with Infrared Flashlights tutorial. Just modify the code as shown below.

    Infrared Tutorial: http://learn.parallax.com/activitybot/navigate-infrared-flashlights
    Infrared Circuit: http://learn.parallax.com/activitybot/build-ir-sensor-circuits
    Infrared Code: (just for objects): http://learn.parallax.com/activitybot/test-ir-sensor-circuits

    Distances in SimpleIDE Terminal

    attachment.php?attachmentid=106800&d=1392059007

    Object Detection Code Modified for Distance
    /*
      Test IR Detectors for Distance.c
    
      Detects distance with same circuit and modified code from the 
      Navigate by Infrared Flashlights tutorial at:
      learn.parallax.com/activitybot/navigate-infrared-flashlights
    
      Circuit:
      learn.parallax.com/activitybot/build-ir-sensor-circuits
    
      Modifications in comments are changes from Test IR Distance.c, 
      which is here:
      learn.parallax.com/activitybot/test-ir-sensor-circuits
    */
    
    #include "simpletools.h"
    
    int irLeft, irRight;
    
    int main()
    {
      low(26);                                   
      low(27);                                   
    
      while(1)
      {
        irLeft = 0;                                     // <- add
        irRight = 0;                                    // <- add
    
        for(int dacVal = 0; dacVal < 160; dacVal += 8)  // <- add
        {                                               // <- add
          dac_ctr(26, 0, dacVal);                       // <- add
          freqout(11, 1, 38000);                        // <- add
          irLeft += input(10);                          // <- modify
      
          dac_ctr(27, 1, dacVal);                       // <- add
          freqout(1, 1, 38000);
          irRight += input(2);                          // <- modify
        }                                               // <- add
    
        print("%c irLeft = %d, irRight = %d%c",         // <- modify
               HOME,   irLeft, irRight, CLREOL);        // <- modify
        pause(100);
      }
    }
    


    The for... loop increases the voltage at the IR LED's cathode time through. This makes the overall voltage across the LED circuit lower with each repetition, which in turn makes the LED flashlights dimmer, which makes the IR sensor more nearsighted. The for... loop also has code added that counts the number of times the object was not detected. More not-detections means larger distance.

    The value that is currently 160 can be adjusted. It can be increased if the measurement zeros out way before the object is right in front of the IR LED or decreased if you have a constant value > 0 up-close.

    The value that is currently 8 can be increased for higher resolution. For example, reducing 8 to 4 would give a range of 0 to 40 instead of 0 to 20.
    557 x 240 - 16K
  • djgsi974djgsi974 Posts: 16
    edited 2014-02-13 09:17
    Thanks a lot everybody.
    i will buy the sharp ir sensor later but
    Actually i want to lurn with the kit i have.
    Thank to andy for the code.
    See you soon.
  • djgsi974djgsi974 Posts: 16
    edited 2014-02-13 11:01
    Sorry Andy, but if i understand your explanation, i think there is an error in your code :
    don't you think i must replace "dac_ctr(26,..." and "dac_ctr(27,..." with "dac_ctr(11,..." and "dac_ctr(1,..." ?
    We want to increase the voltage at the IR LED's cathode, but not the voltage at the LED cathode (integrated on the board that are using port 26 and 27) ?

    I'm waiting for your answer, i don't want to test if it is not that (which would mean that I did not understand).
    And sorry for my poor english, i'm from Reunion Island in the indian ocean.

    bye.
  • ercoerco Posts: 20,255
    edited 2014-02-14 11:52
    I'm still waiting for someone smarter than me (Duane or PhiPi, I dare not even dream of getting Tracy Allen involved) to do some quick Propeller experiments with the fixed-gain, continuous-signal compatible Vishay TSOP4038 (very different from other IR receivers). From http://www.vishay.com/company/press/releases/2010/100628irsensors, these have the unique ability to measure relative signal strength directly from the length of the reflected pulse:

    Many applications require a reflective sensor that detects not only presence but also proximity by measuring the strength or weakness of the reflected signal. Instead of a fixed detection threshold, analog information from the sensor is needed. This is possible with the TSOP4038, TSOP58038, and TSOP58P38 IR proximity sensors. The length of the sensor’s output pulse in response to the emitter signal varies in proportion to the amount of light reflected from the object being detected. For near objects, the output pulse approaches 100 % of the emitted pulse, for far objects the output pulse becomes shorter.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-02-14 12:31
    erco wrote: »
    I'm still waiting for someone smarter than me (Duane or PhiPi, I dare not even dream of getting Tracy Allen involved) to do some quick Propeller experiments with the fixed-gain, continuous-signal compatible Vishay TSOP4038 (very different from other IR receivers). From http://www.vishay.com/company/press/releases/2010/100628irsensors, these have the unique ability to measure relative signal strength directly from the length of the reflected pulse:

    Those look like cool sensors and it would probably be easier to write distance detecting code for those sensors than the current sensors used in the AB and S2. But the AB and S2's sensors can detect distance if the input to the IR LED is varied. This can be done by making the IR LED vary in brightness and use the brightness information as part of the distance calculation or one can vary the modulation frequency of the IR LED. I think Phil used the later technique in the S2.

    Both techniques' readings are influenced by the how reflective the object being detected is. Objects reflecting a lot of IR will seem closer than those not reflecting as much IR. I think the Vishay sensor would have the same limitations.
  • edited 2014-02-14 14:23
    Originally posted by djgsi974:

    Sorry Andy, but if i understand your explanation, i think there is an error in your code :
    don't you think i must replace "dac_ctr(26,..." and "dac_ctr(27,..." with "dac_ctr(11,..." and "dac_ctr(1,..." ?
    We want to increase the voltage at the IR LED's cathode, but not the voltage at the LED cathode (integrated on the board that are using port 26 and 27) ?


    That's a healthy level of caution, and hopefully for you, it will result in fewer encounters with the magic blue smoke that electronic parts make just before they die! :)

    In answer to your question, there is not an error in the code. I tested it before posting with the IR receivers in the ActivityBot kit that have the silver metal cases, and it worked better than I expected. Both sides give me detections in the 0 to 20 ranges for roughly equivalent distances. In contrast, the similar Boe-Bot approach only resulted in 0 to 4 measurement ranges with considerably more measurement noise. The Boe-Bot still does really well following objects, so I'm looking forward to testing for improved performance with less noise and the 0 to 20 detection range.

    With reference to the circuit in:

    http://learn.parallax.com/activitybot/build-ir-sensor-circuits

    ...and the code in:

    http://forums.parallax.com/showthread.php/153755-ActivityBot-infrared-led-sensors-distance?p=1241755&viewfull=1#post1241755

    Let's focus on the left IR detector circuit: P11.....1 k ohm.....(anode)-IRLED-(cathode).....D/A0.

    The code switches P11 on/off (3.3 V / 0 V) at 38 kHz.

    The code also sweeps the D/A0 voltage (which is controlled by P26) from 0 V to 2 V in 0.1 V steps (all approximations).

    When D/A0 (set by P26) is 0 V, the voltage across the IR LED circuit is 3.3 V when P11 is high and 0 V when P11 is low. When P11 is high, the 3.3 V across the circuit makes current flow, and the IR LED glows (IR light on). When P11 is low, the voltage across the circuit is 0 V, so no current flows through the circuit and the IR LED does not glow (IR light off).

    Let's now think about what happens half way through the loop, when dacVal is 80 and the D/A0 voltage is about 1 V. When P11 is high, the voltage across the IR LED circuit is 3.3 V - 1 V = 2.3 V. Less voltage, less current. So the IR light is on, but not as bright as it was with 3.3 V. This makes the IR receiver more nearsighted.

    When P11 is low, the voltage across the circuit is 0 V - 1 V = -1 V. Keep in mind that an LED is a one-way current valve. Almost no current travels through when it's reverse biased. No current, no light. So, the LED stays off for the low time, and we still have our 38 kHz IR light on/off signal that the IR receiver needs to detect reflections from objects. And reverse bias voltages in the 0 to -3.3 V range will not hurt the IR LED.

    Side notes:

    I have not yet tested the black plastic IR detectors in the kit. They are a little more sensitive than the metal ones, and that's not necessarily a good thing. I typically use larger resistors in series with the IR LEDs to offset for that higher sensitivity with the black plastic detectors. That prevents them from detecting the floor in front of the robot, which is not supposed to be detected as an obstacle.

    For initial testing, close the blinds to keep direct sunlight out of your area. I have not tested the effects of direct sunlight yet, but from past experiences, it has tended to swamp the IR, making it very nearsighted, or even blind.
  • ercoerco Posts: 20,255
    edited 2014-02-14 15:34
    I have not yet tested the black plastic IR detectors in the kit. They are a little more sensitive than the metal ones, and that's not necessarily a good thing. I typically use larger resistors in series with the IR LEDs to offset for that higher sensitivity with the black plastic detectors.

    There is a dizzying array of IR receiver types, each with different characteristics, "optimized" for something, noisy environments, sunlight, etc. Vishay's catalog shows several receiver types in both tin can packages and also black epoxy. Long story short, there is often no way to ID any particular IR receiver, other than what marked supplier bag it came out of, and there is room for error there, too. BTW, Radio Shack sells two wildly different receivers in the same package, same part number. The metal frame one is continuous-signal compatible, the black epoxy one is not.
  • edited 2014-02-14 16:20
    For those of you reading along, adventures like Erco's are common when switching IR receiver part sources. That said, I assure you that Parallax IR receivers are not like that "box of chocolates" adventure. We have significant hours, tests and procedures for ensuring that our IR parts behave consistently.

    The silver IR are optimized for Boe-Bot/ActivityBot forward detection. The black are optimized for SumoBot without being "too" different from the silver ones. They are slightly more sensitive, which is good for better opponent detection, and IR bouncing off the black sumo ring surface is not as likely to be detected as it is with an ActivityBot on wood floor or carpet.

    The black ones were added to the ActivityBot kit for planned future activities that have more flex, and calibration will be used to keep our options of switching to all silver ones. We also make sure to document when the difference matters. For example, the circuit page cited in this thread has a nice red check-mark with this instruction: "Find the IR receivers in your kit. If you have two different kinds, use the ones with the silver metal cases for this activity."

    Source: http://learn.parallax.com/activitybot/build-ir-sensor-circuits

    ...and while it's true that maybe you or somebody you know may have gotten an out of spec detector from us at some point, we also go the extra mile to make it right if it happens. As in, we send replacements immediately and also raid stock to find and eliminate the offending batch-o-receivers.
  • djgsi974djgsi974 Posts: 16
    edited 2014-02-14 20:15
    Ok Andy this is exactly what i need.
    I tested it and it works perfectly.
    Thanks to all.
    See you soon.
  • oakguyoakguy Posts: 21
    edited 2014-02-21 08:42
    I was curious if I could use the Sharp IR 2Y0A21 sourced to the Activity Bots I/O pins. They draw 30 ma each and I have four of them I would like to switch to possibly save power. However, if they draw too much I don't want to damage anything. Thanks!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-02-21 09:07
    oakguy wrote: »
    I was curious if I could use the Sharp IR 2Y0A21 sourced to the Activity Bots I/O pins. They draw 30 ma each and I have four of them I would like to switch to possibly save power. However, if they draw too much I don't want to damage anything. Thanks!

    The sensor needs 5V power and the Prop's I/O pins output 3.3V power.

    You could use a latching (or normal) relay on the sensor's power line and use the Prop to turn it on and off through the relay.

    Edit: Even if the sensor were a 3.3V device, I'm not sure it would be a good idea. Many devices draw short bursts of high current that could either damage the Prop pin or cause he sensor not to work correctly. I've tried powering some nRF24L01+ transceivers from a Prop pin with mixed results. Most of my transceivers wouldn't work when powered from an I/O pin even though they only draw 17mA of current. I'm not sure just why they wouldn't work this way but I'd thought I'd offer my experience as a warning.

    Cluso99 wrote a post on this topic. You might want to see if you could find it (if I find it I'll post a link).

    Edit again: I found Cluso99's thread.
Sign In or Register to comment.