Shop OBEX P1 Docs P2 Docs Learn Events
basic stamp code ir beacon — Parallax Forums

basic stamp code ir beacon

edited 2012-07-10 15:05 in BASIC Stamp
hello,

i have my boe-bot remote controlled by infrared with a sony remote.
here is my problem: my boe bot is turning around to look for a beacon. if i touch a button on the remote it stops turning and then it drives a straight way.

i want that the boe bot comes to my ir remote as long as i touch the button (like it comes to a beacon).
can anybody help with this code please?

thanks for the help!!

kind regards,
Patrick

Comments

  • ercoerco Posts: 20,256
    edited 2012-07-03 15:56
    I did that with a Scribbler robot, similar to a BoeBot but not exactly. If you add a ServoPal to a BoeBot, you can tweak this code to work with your IR remote: http://www.botmag.com/articles/scribbler.shtml

    Do you have working beacons already that you are tracking to? Are they sending Sony TV codes, or just constant pulses of modulated IR?
  • edited 2012-07-03 22:39
    erco wrote: »
    I did that with a Scribbler robot, similar to a BoeBot but not exactly. If you add a ServoPal to a BoeBot, you can tweak this code to work with your IR remote: http://www.botmag.com/articles/scribbler.shtml

    Do you have working beacons already that you are tracking to? Are they sending Sony TV codes, or just constant pulses of modulated IR?

    Hi have not yet any beacons. i have a sony remote and i got it now working with my boe-bot.
    how can i create an constant pulse out of my remote? the idea is if i press for example the enter button and i hold it ( it think this is a constant pulse), the boe-bot search for this signal and then drive to it.
    please help with the code, i dint know how/where to start.

    thanks again for the help!!
    patrick
  • ercoerco Posts: 20,256
    edited 2012-07-04 01:04
    Did you read the article? It's all there.
  • edited 2012-07-04 04:05
    erco wrote: »
    Did you read the article? It's all there.

    Hi
    yes ive read the article. the part i dont understand is where in the code the boe bot searchs for the ir remote signal and then drive through it.

    if i program it looks like this:

    if remote code is 101 (my enter button on the remote for example).THEN GOSUB ...
    how does my boe bot sees where it have to go?

    thanks for the help

    patrick
  • ercoerco Posts: 20,256
    edited 2012-07-04 11:11
    ' Scribbler Robot PHASE 1
    ' Eric Ostendorff 3/10/2008
    ' modified Parallax readir routine
    ' drive robot with IR remote/Sony TV codes
    ' MUTE button starts track mode, STOP ends track mode
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    ' define variables
    irPulse        VAR     Word                  ' Stores pulse widths
    remoteCode     VAR     Byte                  ' Stores remote code
    trackflag      VAR     Bit                   ' 1 for track mode
    
    main:                                        ' start main program
    trackflag=0                                  ' 0 = driving mode
    LOW 8:LOW 9:LOW 10                           ' LEDs off = driving mode
    GOSUB readir                                 ' read IR remote code
    IF remoteCode=101 THEN GOSUB stopp           'center button=stop
    IF remoteCode=116 THEN GOSUB fwd             'up arrow=forward
    IF remoteCode=117 THEN GOSUB bwd             'down arrow=backward
    IF remoteCode=52  THEN GOSUB left            'left arrow=left
    IF remoteCode=51  THEN GOSUB right           'right arrow=right
    IF remoteCode=20  THEN GOSUB track           'MUTE = track routine
    GOTO main                                  'loop back, ignore other keys
    
    fwd:PULSOUT 12,3000     'right motor forward calibration 3000=max fwd
    PULSOUT 13,3000         'left motor forward calibration
    RETURN
    
    bwd:PULSOUT 12,1050    'right motor backward calibration 1000=max reverse
    PULSOUT 13,1000        'left motor backward calibration
    RETURN
    
    stopp:PULSOUT 12,2000  '2000 = stop right motor
    PULSOUT 13,2000        '2000 = stop left motor
    RETURN
    
    left:PULSOUT 12,3000   'left motor full forward
    PULSOUT 13,2000'       'stop left motor
    RETURN
    
    right:PULSOUT 12,2000  'stop right motor
    PULSOUT 13,3000        'right motor full forward
    RETURN
    
    leftslow:PULSOUT 12,2900   'left motor slow
    PULSOUT 13,2000'           'stop left motor
    RETURN
    
    
    track:
    trackflag=1                           ' set track mode
    HIGH 8:HIGH 9:HIGH 10                 ' turn on 3 LEDs for track mode
    GOSUB readir                          ' read ir remote
    IF remoteCode=20 THEN GOSUB fwd       ' forward if MUTE received
    IF remotecode=0 THEN GOSUB leftslow   ' circle left if MUTE not received
    IF remotecode=101 THEN GOTO main      ' exit on STOP command
    GOTO track
    
    
     readir:                              'Parallax read ir remote subroutine
      remoteCode = 0
    
      RCTIME 6, 1, irPulse
      IF IN7=1 THEN GOSUB stopp:GOTO main   '  if stalled, stop!
      IF irPulse < 1000 THEN endir                 'no start signal, skip ahead
      getdata:PULSIN 6, 0, irPulse                 ' Get data pulses.
      IF irPulse > 500 THEN remoteCode.BIT0 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT1 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT2 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT3 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT4 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT5 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT6 = 1
      IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
      IF (remoteCode = 10) THEN remoteCode = 0
      endir:IF trackflag=1 THEN endread   'tracking, skip ahead
      IF remotecode=0 THEN endread        'zero or no signal, skip ahead
      DEBUG ? remoteCode
      FREQOUT 11,60,730    'beep speaker
      endread:
    RETURN
    

    That's the code. I used mute (code 20) for tracking. The bot goes straight forward when it detects the mute code, and spins left when it doesn't detect it. Your IR detector needs to have IR-proof light shields (blinders) around it so it only sees forward. A typical IR remote blasts a ridiculously strong signal. You can aim the remote at the wall and the bot will go straight where the remote is aimed. If you want it to drive directly towards the remote, you'll have to reduce the signal. You can either mod the remote by adding an internal resistor on the IR LED, or cover the LED with 2 layers of black electrical tape and poke a tiny hole in the tape.
  • edited 2012-07-04 11:38
    erco wrote: »
    ' Scribbler Robot PHASE 1
    ' Eric Ostendorff 3/10/2008
    ' modified Parallax readir routine
    ' drive robot with IR remote/Sony TV codes
    ' MUTE button starts track mode, STOP ends track mode
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    ' define variables
    irPulse        VAR     Word                  ' Stores pulse widths
    remoteCode     VAR     Byte                  ' Stores remote code
    trackflag      VAR     Bit                   ' 1 for track mode
    
    main:                                        ' start main program
    trackflag=0                                  ' 0 = driving mode
    LOW 8:LOW 9:LOW 10                           ' LEDs off = driving mode
    GOSUB readir                                 ' read IR remote code
    IF remoteCode=101 THEN GOSUB stopp           'center button=stop
    IF remoteCode=116 THEN GOSUB fwd             'up arrow=forward
    IF remoteCode=117 THEN GOSUB bwd             'down arrow=backward
    IF remoteCode=52  THEN GOSUB left            'left arrow=left
    IF remoteCode=51  THEN GOSUB right           'right arrow=right
    IF remoteCode=20  THEN GOSUB track           'MUTE = track routine
    GOTO main                                  'loop back, ignore other keys
    
    fwd:PULSOUT 12,3000     'right motor forward calibration 3000=max fwd
    PULSOUT 13,3000         'left motor forward calibration
    RETURN
    
    bwd:PULSOUT 12,1050    'right motor backward calibration 1000=max reverse
    PULSOUT 13,1000        'left motor backward calibration
    RETURN
    
    stopp:PULSOUT 12,2000  '2000 = stop right motor
    PULSOUT 13,2000        '2000 = stop left motor
    RETURN
    
    left:PULSOUT 12,3000   'left motor full forward
    PULSOUT 13,2000'       'stop left motor
    RETURN
    
    right:PULSOUT 12,2000  'stop right motor
    PULSOUT 13,3000        'right motor full forward
    RETURN
    
    leftslow:PULSOUT 12,2900   'left motor slow
    PULSOUT 13,2000'           'stop left motor
    RETURN
    
    
    track:
    trackflag=1                           ' set track mode
    HIGH 8:HIGH 9:HIGH 10                 ' turn on 3 LEDs for track mode
    GOSUB readir                          ' read ir remote
    IF remoteCode=20 THEN GOSUB fwd       ' forward if MUTE received
    IF remotecode=0 THEN GOSUB leftslow   ' circle left if MUTE not received
    IF remotecode=101 THEN GOTO main      ' exit on STOP command
    GOTO track
    
    
     readir:                              'Parallax read ir remote subroutine
      remoteCode = 0
    
      RCTIME 6, 1, irPulse
      IF IN7=1 THEN GOSUB stopp:GOTO main   '  if stalled, stop!
      IF irPulse < 1000 THEN endir                 'no start signal, skip ahead
      getdata:PULSIN 6, 0, irPulse                 ' Get data pulses.
      IF irPulse > 500 THEN remoteCode.BIT0 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT1 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT2 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT3 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT4 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT5 = 1
      RCTIME 6, 0, irPulse
      IF irPulse > 300 THEN remoteCode.BIT6 = 1
      IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
      IF (remoteCode = 10) THEN remoteCode = 0
      endir:IF trackflag=1 THEN endread   'tracking, skip ahead
      IF remotecode=0 THEN endread        'zero or no signal, skip ahead
      DEBUG ? remoteCode
      FREQOUT 11,60,730    'beep speaker
      endread:
    RETURN
    

    That's the code. I used mute (code 20) for tracking. The bot goes straight forward when it detects the mute code, and spins left when it doesn't detect it. Your IR detector needs to have IR-proof light shields (blinders) around it so it only sees forward. A typical IR remote blasts a ridiculously strong signal. You can aim the remote at the wall and the bot will go straight where the remote is aimed. If you want it to drive directly towards the remote, you'll have to reduce the signal. You can either mod the remote by adding an internal resistor on the IR LED, or cover the LED with 2 layers of black electrical tape and poke a tiny hole in the tape.


    Hi this is my code: ive copy pasted it and tweaked it a bit.:
    ' Scribbler Robot PHASE 1
    ' Eric Ostendorff 3/10/2008
    ' modified Parallax readir routine
    ' drive robot with IR remote/Sony TV codes
    ' ENTER button starts track mode, STOP ends track mode


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}


    ' define variables
    irPulse VAR Word ' Stores pulse widths
    remoteCode VAR Byte ' Stores remote code
    trackflag VAR Bit ' 1 for track mode


    main: ' start main program
    trackflag=0 ' 0 = driving mode
    LOW 8:LOW 9:LOW 10 ' LEDs off = driving mode
    GOSUB readir ' read IR remote code
    IF remoteCode=56 THEN GOSUB stopp 'center button=stop
    IF remoteCode=121 THEN GOSUB fwd 'up arrow=forward
    IF remoteCode=122 THEN GOSUB bwd 'down arrow=backward
    IF remoteCode=123 THEN GOSUB left 'left arrow=left
    IF remoteCode=124 THEN GOSUB right 'right arrow=right
    IF remoteCode=11 THEN GOSUB track 'enter = track routine
    GOTO main 'loop back, ignore other keys


    fwd:PULSOUT 12,850 'right motor forward calibration 850=max fwd
    PULSOUT 13,650 'left motor forward calibration
    RETURN


    bwd:PULSOUT 12,650 'right motor backward calibration 650=max reverse
    PULSOUT 13, 850 'left motor backward calibration
    RETURN


    stopp:PULSOUT 12,650 '650 = stop right motor
    PULSOUT 13,850 '850 = stop left motor
    RETURN


    left:PULSOUT 12,850 'left motor full forward
    PULSOUT 13,850' 'stop left motor
    RETURN


    right:PULSOUT 12,650 'stop right motor
    PULSOUT 13,650 'right motor full forward
    RETURN


    leftslow:PULSOUT 12,750 'left motor slow
    PULSOUT 13,850' 'stop left motor
    RETURN




    track:
    trackflag=1 ' set track mode
    HIGH 8:HIGH 9:HIGH 10 ' turn on 3 LEDs for track mode
    GOSUB readir ' read ir remote
    IF remoteCode=11 THEN GOSUB fwd ' forward if enter received
    IF remotecode=0 THEN GOSUB leftslow ' circle left if enter not received
    IF remotecode=56 THEN GOTO main ' exit on STOP command
    GOTO track




    readir: 'Parallax read ir remote subroutine
    remoteCode = 0


    RCTIME 6, 1, irPulse
    IF IN7=1 THEN GOSUB stopp:GOTO main ' if stalled, stop!
    IF irPulse < 1000 THEN endir 'no start signal, skip ahead
    getdata:PULSIN 6, 0, irPulse ' Get data pulses.
    IF irPulse > 500 THEN remoteCode.BIT0 = 1
    RCTIME 6, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT1 = 1
    RCTIME 6, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT2 = 1
    RCTIME 6, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT3 = 1
    RCTIME 6, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT4 = 1
    RCTIME 6, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT5 = 1
    RCTIME 6, 0, irPulse
    IF irPulse > 300 THEN remoteCode.BIT6 = 1
    IF (remoteCode < 10) THEN remoteCode = remoteCode + 1
    IF (remoteCode = 10) THEN remoteCode = 0
    endir:IF trackflag=1 THEN endread 'tracking, skip ahead
    IF remotecode=0 THEN endread 'zero or no signal, skip ahead
    DEBUG ? remoteCode
    FREQOUT 11,60,730 'beep speaker
    endread:
    RETURN

    ive got some problems:
    my servo's are stuttering how come?
    how can i see if my boe-bot receives track code? if i put my remote to the boe-bot debug sees remote code 11 (enter key on my remote).but the boe bot wont drive through it.
    if i pressed stop my servo's are still turning as long as i push the button.

    thanks for the help!!
    patrick
  • ercoerco Posts: 20,256
    edited 2012-07-04 12:10
    Your servos are stuttering because you're not using a ServoPal, per post #2. Right?

    As I said, that's Scribbler code, not BoeBot code. You need to send a stream of pulses to your servos, but your IR read routine will interfere with that.
  • edited 2012-07-04 12:16
    Thanks,

    i dont have a servo pal installed. wil order it here in the netherlands.
    is it possible to change code just for boe-bot or do i still need a servo pal?
  • ercoerco Posts: 20,256
    edited 2012-07-04 19:17
    You'll need a servopal to do it right. Otherwise a hacky workaround is to skip the Sony IR read routine and just track to any detected 38kHz signal. You'll check your IR receiver many consecutive times in a timed loop, equivalent to a pause 20 in between servo pulsouts.

    Are you up to the challenge? I want to see your results!
  • ercoerco Posts: 20,256
    edited 2012-07-05 15:21
    @patrick vdT: A few goodies for you. First, check out this old thread even I forgot about: http://forums.parallax.com/showthread.php?103026-39-kHz-IR-Beacons-for-Robot-Detection-amp-Navigation

    Next, I got my BoeBot tracking to my IR remote today, just as quick & dirty as described previously. It took 4 layers of black construction paper to make an IR-proof baffle! The code is short & simple:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    W3=800 ' left wheel forward always
    
    main:     ' first assume no IR signal is seen
    W2=800    ' right wheel reverse for right turn scan
    
    FOR B0=1 TO 40        'check IR sensor 40x for any low output
    IF IN10=0 THEN W2=710 'any IR seen, drive right wheel forward to go straight to signal
    NEXT
    
    PULSOUT 12,W2 ' drive right wheel
    PULSOUT 13,W3  'drive left wheel
    GOTO main
    

    Pic & video attached below. You could integrate this into a bigger program that uses the full Sony remote IR routine to select other functions. Cheers!
    816 x 612 - 51K
  • Martin_HMartin_H Posts: 4,051
    edited 2012-07-05 17:21
    Erco, that is pretty cool. With three beacons sending different encoded values you could triangulate the robot's position.
  • ercoerco Posts: 20,256
    edited 2012-07-07 06:55
    Martin_H wrote: »
    Erco, that is pretty cool. With three beacons sending different encoded values you could triangulate the robot's position.

    Only using a ServoPal. Without one, it will seek any 38khz signal, can't tell 'em apart.

    patrick, you still got yer ears on?
  • edited 2012-07-08 01:30
    erco wrote: »
    @patrick vdT: A few goodies for you. First, check out this old thread even I forgot about: http://forums.parallax.com/showthread.php?103026-39-kHz-IR-Beacons-for-Robot-Detection-amp-Navigation

    Next, I got my BoeBot tracking to my IR remote today, just as quick & dirty as described previously. It took 4 layers of black construction paper to make an IR-proof baffle! The code is short & simple:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    W3=800 ' left wheel forward always
    
    main:     ' first assume no IR signal is seen
    W2=800    ' right wheel reverse for right turn scan
    
    FOR B0=1 TO 40        'check IR sensor 40x for any low output
    IF IN10=0 THEN W2=710 'any IR seen, drive right wheel forward to go straight to signal
    NEXT
    
    PULSOUT 12,W2 ' drive right wheel
    PULSOUT 13,W3  'drive left wheel
    GOTO main
    

    Pic & video attached below. You could integrate this into a bigger program that uses the full Sony remote IR routine to select other functions. Cheers!


    Hello,

    my boe bot is working now too!!!

    i have to understand how ir signal works (im new with electronics this is a starting hobby).
    but with all the codes and studing boe bots manouvers. i wil getting it.

    thanks for the help!!!
  • ercoerco Posts: 20,256
    edited 2012-07-10 15:05
    patrick: Let's see what you've achieved. Youtube it!

    And have a look at this for more great IR info: http://www.imagineeringezine.com/files/air-bk2.html
Sign In or Register to comment.