following within a distance Via IR
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]
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
Take a look at this: http://forums.parallax.com/showthread.php?p=561496
It's a neat idea and works great.
HTH, Chris
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:
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