Fast sensor sweep help
Special_K
Posts: 162
I have a small programming issue that I am hoping that someone can help me out with. I have several sensors in a bracket looks like this /""\ . So both IR and sonar are on each surface (left, center and right)
I am using the GPD02 I know they are not the best but I have done some work with the code that comes with them and have made them cycle faster and convert the output to CM to match the pings output. My solution was to fire all the IR units at once and then wait for the first unit/pin to receive data process it and then go back to looking for the other unit/pins to got inputs. The problem is in this portion of code
The unit that is read last in the if then statement always returns a 0 for distance. In this code it is the center unit but if I switch the code position with right or left IR units they will return a 0. Any help would be greatly appreciated. Full program code bellow
I am using the GPD02 I know they are not the best but I have done some work with the code that comes with them and have made them cycle faster and convert the output to CM to match the pings output. My solution was to fire all the IR units at once and then wait for the first unit/pin to receive data process it and then go back to looking for the other unit/pins to got inputs. The problem is in this portion of code
ircheck: XA=XA+1 x=0 IF IN1<>0 THEN GOTO inleft ELSEIF IN3<>0 THEN GOTO inright ELSEIF IN5<>0 THEN 'code problem... GOTO incenter 'code problem.. ELSEIF XA<160 THEN GOTO ircheck ENDIF RETURN
The unit that is read last in the if then statement always returns a 0 for distance. In this code it is the center unit but if I switch the code position with right or left IR units they will return a 0. Any help would be greatly appreciated. Full program code bellow
Comments
One real issue I would solve first is the fact that you’re using GOTO to jump to a subroutine ending in RETURN. This can cause real problems including restarting the program. Correct these types of problems and that may clear up your other problems. The two may in fact be related. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I'd tried just enabling each detector one a time, clocking in the data from each, reporting the results? I know you don't want to take like 230ms to do all three, but if they test OK that way, you've at least narrowed down where the problem is. Is the 160 count a timeout or something? Are you timing out on both the detectors and in your code? 160 loops through there would be very fast -- a lot less than the 70ms that the detector might need to be ready.
There's also the possibility of interference if all three pulse at once; checking each one in order would help see if that's the case also.
While the jumps within your subs may be considered by some to be poor style, I don't *think* there are any errors there per se, since you're using the GOTO from within a called subroutine already. I have only done this when I've hit my limit of 4 nested subroutine calls or because I have shared code for the tail ends of two or more subroutines.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
and make them
With this change Now the right IR sensor returns a 0. There is something with wrong in the code.
You might try something like the following just to eliminate some of the questions regarding the calling structure of your code: