Shop OBEX P1 Docs P2 Docs Learn Events
IR problem — Parallax Forums

IR problem

KARIM102KARIM102 Posts: 75
edited 2010-06-12 18:23 in Learn with BlocklyProp
hi everybody
i bluid robort that work by wrieless, there are two mircontroll one is the rmote (TX) the the other in the robort, this robort can go right, left forward and backward... i put two IR detector in the back, they work when u press the backward sw the robort when he come close it an object it should go leftside "left" until the object is passed then it will conutine to go backward... the problem is the is statment doesn't work i don't know actually!!!! could anyone help????????


this is the RX coding ::

'{$STAMP BS2}
'{$PBASIC 2.5}
'
variables
x············· VAR···· Word····· ' Variable for output signal
y············· VAR···· Word····· ' Variable for input signal
eye··········· VAR···· Bit······ ' Variable for IR left
eye1·········· VAR···· Bit······ ' Variable for IR left
'
constants
FwdLtFast····· CON···· 850······ ' Left servo forward full speed
BwdLtFast····· CON···· 650······ ' Left servo backward full speed
FwdRtFast····· CON···· 650······ ' Right servo forward full speed
BwdRtFast····· CON···· 850······ ' Right servo backward full speed
BAUD·········· CON···· 84······· ' Baud set at 9600
'
servo definitions
ltServo······· PIN···· 10······· ' Left Servo Pin
rtServo······· PIN···· 8········ ' Right Servo Pin
'=======================================================================================================
'
main routine
'=======================================================================================================
·LOW 1
·LOW 0
·eye·· = IN4····························································· ' Input for IR reciver left (1)
·eye1· = IN5····························································· ' Input for IR reciver right(2)
·· DO
········································································· 'Sync pulse for the tranimeter
SERIN 3,16780, [noparse][[/noparse]WAIT("!"), x]

·PAUSE 50
·FREQOUT 1, 1, 38500····················································· 'Output from IR LEDs frequecy 40Hz
·FREQOUT 0, 1, 38500
HIGH 11
LOW 13··································································· ' All LEDs turn off, only Green LED will be on
LOW 8···································································· ' tell you that the system on standby mode
LOW 10
LOW 14
LOW 12

IF x=154 THEN
········································································· 'The robot will go ahead
· PULSOUT ltServo, BwdLtFast
· PULSOUT rtServo, BwdRtFast
· PAUSE 15
· HIGH 14
· HIGH 13
· LOW 12
· LOW 11
ELSEIF x=54 THEN························································ 'The robot will turn left
· PULSOUT ltServo, FwdRtFast
· PULSOUT rtServo, FwdRtFast
· PAUSE 15
· HIGH 13
· LOW 12
· LOW 14
· LOW 11
ELSEIF x=210 THEN························································· 'The robot will turn right
· PULSOUT ltServo, FwdLtFast
· PULSOUT rtServo, FwdLtFast
· PAUSE 15
· HIGH 13
· LOW 12
· LOW 14
· LOW 11
ELSEIF x=110 AND (eye = 0) AND (eye1 = 0) THEN······························· 'The robot will turn left
· PULSOUT ltServo, FwdRtFast
· PULSOUT rtServo, FwdRtFast
· PAUSE 15
· HIGH 13
· LOW 12
· LOW 14
· LOW 11
ELSEIF x=110 THEN························································ 'The robot will go backward
· PULSOUT ltServo, FwdLtFast
· PULSOUT rtServo, FwdRtFast
· PAUSE 15
· HIGH 12
· HIGH 13
· LOW 11
· LOW 14
· ELSE····································································· 'Both servo will stop moves
HIGH 11
LOW 13··································································· ' All LEDs turn off, only Green LED will be on
LOW 8···································································· ' tell you that the system on standby mode
LOW 10
LOW 14
LOW 12
ENDIF
LOOP
'======================================== End routine ==================================================


this is the TX coding:


'{$STAMP BS2}
'{$PBASIC 2.5}
'
variables
x······················ VAR Word··· ' Variable for input signal
z······················ VAR Word··· ' Variable for output signal

'============================================================================
'
main routine
'============================================================================

DO
PULSOUT 15, 1200···························· 'Sync pulse for the receiver
SEROUT· 15, 16780, [noparse][[/noparse] "!", x]


IF IN5 = 1 THEN
x = 210
ELSEIF IN0 = 1 THEN
x = 110
ELSEIF IN1 = 1 THEN
x = 54
ELSEIF IN10 = 1 THEN
x = 154
ELSE
x = 232
ENDIF
LOOP
'==================== End routine ==================================

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Comments

  • Spiral_72Spiral_72 Posts: 791
    edited 2010-06-08 16:47
    My mind doesn't seem to want to grasp what you are doing here..... but after all the IF-ELSEIF stuff, you have a "LOOP", but I don't see where the loop is handled. Where is it supposed to go???

    If you intended for the LOOP to start all the IF-ELSEIF checks over again, then it needs to be a goto....... or precede all that stuff with a "DO WHILE"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "puff"...... Smile, there went another one.
  • KARIM102KARIM102 Posts: 75
    edited 2010-06-09 03:59
    i don't think the peoblem with DO LOOP but it is with IF-ELSEIF!!! I Check the IR detector it's working perfectly with if- when it's the only input to the microcontroller,,, but when it's with the with RX coding it's not working!!! that's the only peoblem i got
    "ELSEIF x=110 AND (eye = 0) AND (eye1 = 0) THEN 'The robot will turn left
    PULSOUT ltServo, FwdRtFast
    PULSOUT rtServo, FwdRtFast
    PAUSE 15
    HIGH 13
    LOW 12
    LOW 14
    LOW 11

    this status not working !!! but why????

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • FranklinFranklin Posts: 4,747
    edited 2010-06-09 04:07
    Break your program into smaller pieces and find out where the problem lies. Add back one piece at a time until it breaks again and you will know where your problem is.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • KARIM102KARIM102 Posts: 75
    edited 2010-06-12 18:23
    thx a lot i find the problem but it will be silly to say!!!!!!!!!!!! i just copy the coding and open another page and it work but why??? i couldn't understant what happen??? but now with the same code it's working???????????

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.