Shop OBEX P1 Docs P2 Docs Learn Events
following within a distance Via IR — Parallax Forums

following within a distance Via IR

KelthKelth Posts: 1
edited 2006-11-21 16:17 in Robotics
Hello All!, New to the boards, how embarassing my first post is one asking for assistance. :-p Ah well. Im haveing a bit of problems with my program, It is for a class assignment, every other student did a pretty much half-assed job copying directly out of the book. I decided to try and actualy write my own program for our BOE-Bot assignment. What we need to do is follow behind an object, the object will move foward, stop, and back up, then move foward again. We need to make our machine, follow behind the toy (the thing that is moveing), makeing sure we dont ram into it. I use the LOOKUP function for the BS2 controller to achive distance monitoring, but im hitting a snag in the beginning of my code.

Attached is my full code, shown below is the code im having problems with, its looking to see the alignment of the object "left IR sensor, Right IR sensor, or center (both Left and Right IR sensors), or if neither then move foward untill you detect an object.


'=============[noparse][[/noparse] IRdetect ]====================================================
IRdetectt:······ ' detects left or right or center IR, if no IR is found then go foward
Alinement = 0
DO UNTIL Alinement > 0
FREQOUT 2,1, 41500
FREQOUT 8,1, 41500
IF (IN0 = 0) AND (IN9 = 0) THEN··· 'detect center·· (3)
···· Alinement = 3
···· DEBUG "Detect Both, Alinement = 3"
ELSEIF (IN0 = 1) AND (IN9 = 0) THEN········· 'detect left (2)
···· Alinement = 2
···· DEBUG "Detect Left, Alinement = 2"
ELSEIF (IN0 = 0) AND (IN9 = 1) THEN········· 'detect right (1)
···· Alinement = 1
···· DEBUG "Detect Right, Alinement = 1"
ELSEIF (IN0 = 1) AND (IN9 = 1) THEN········· 'detect none = go foward
···· Alinement = 0
···· PULSOUT 12, 700
···· PULSOUT 13, 800
···· DEBUG HOME, "No Object Detected"
ENDIF
LOOP
RETURN

the problem is that the it is getting hung up on the final elseif, its not seeing any object even when they are right infront of it, so its getting stuck in the loop, i tested the IR sensors and they seem to work fine.


attached is the rest of my code, if something can be optimized, let me know! thanks [noparse]:)[/noparse]

Comments

  • CCraigCCraig Posts: 163
    edited 2006-11-21 15:13
    I don't know why it's not seeing it. You might lower the freq. out to extend it's range some.

    Take a look at this: http://forums.parallax.com/showthread.php?p=561496

    It's a neat idea and works great.



    HTH, Chris
  • ZootZoot Posts: 2,227
    edited 2006-11-21 16:17
    You potentially have several issues here, but for now I'll address the most noticeable problem -- your method for detecting the IR emitter freqouts will probably not give you the best results. Each detector needs to be checked for IR *immediately* following the FREQOUT, one at a time. You need to read the light before it vanishes at, well, the speed of light. I would think by the time you work through your IF...THENs you will not be able to detect IR accurately.

    Here's some of your code slightly reworked. Note that the value of the detector is stored so you can then parse it with your logic statements:

    
    IRleft   VAR   Bit    'for storing the value of the left IR detector
    IRright   VAR   Bit    'for storing the value of the right IR detector
    
    IRdetectt:       ' detects left or right or center IR, if no IR is found then go foward
    Alinement = 0
    DO UNTIL Alinement > 0
    FREQOUT 2,1, 41500
           IRright = IN0     'immediately read and store the value returned by the detector
    FREQOUT 8,1, 41500
            IRleft = IN9    'ditto for the right
    
    ' now you've got the status of the detectors saved as bit variables...run through your logic
    IF (IRright = 0) AND (IRleft = 0) THEN    'detect center   (3)
         Alinement = 3
         DEBUG "Detect Both, Alinement = 3"
    ELSEIF (IRright = 1) AND (IRleft = 0) THEN          'detect left (2)
         Alinement = 2
         DEBUG "Detect Left, Alinement = 2"
    ELSEIF (IRright = 0) AND (IRleft = 1) THEN          'detect right (1)
         Alinement = 1
         DEBUG "Detect Right, Alinement = 1"
    ELSEIF (IRright = 1) AND (IRleft = 1) THEN          'detect none = go foward
         Alinement = 0
         PULSOUT 12, 700
         PULSOUT 13, 800
         DEBUG HOME, "No Object Detected"
    ENDIF
    LOOP
    RETURN
    
    



    That should at least give you accurate IR status data. I would also try a base frequency out of 38,500 and then perhaps change out your resistors to the IR LEDs to adjust detectable distance.

    Now, I'm not sure if your code is just a fragment, but it looks like you are not doing anything with your motors when the alignments are 1-3? In any case, you may want to think about your logic in a little more detail -- what should happen when.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
Sign In or Register to comment.