Shop OBEX P1 Docs P2 Docs Learn Events
Need IR code for Propeller powered boe bot — Parallax Forums

Need IR code for Propeller powered boe bot

bomberbomber Posts: 297
edited 2011-08-11 09:28 in Propeller 1
I am building a boe bot controlled by a Propeller and I need some code that uses the same pinouts as the boe bot code below. The pinouts are the same for the boe-bot IR code (page 238 in Robotics with the Boe-Bot).
 
' Robotics with the Boe-Bot - FastIrRoaming.bs2
' Higher performance IR object detection assisted navigation
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
irDetectLeft VAR Bit ' Variable Declarations
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
DO ' Main Routine
FREQOUT 8, 1, 38500 ' Check IR Detectors
irDetectLeft = IN9
FREQOUT 2, 1, 38500
irDetectRight = IN0
' Decide how to navigate.
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseLeft = 650
pulseRight = 850
ELSEIF (irDetectLeft = 0) THEN
pulseLeft = 850
pulseRight = 850
ELSEIF (irDetectRight = 0) THEN
pulseLeft = 650
pulseRight = 650
ELSE
pulseLeft = 850
pulseRight = 650
ENDIF
PULSOUT 13,pulseLeft ' Apply the pulse.
PULSOUT 12,pulseRight
PAUSE 15
LOOP ' Repeat Main Routine

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2011-08-03 14:11
    Hi bomber,

    and welcome to the propeller-forum

    If I see it right you posted basic stamp code. I guess accidently you have chosen the wrong forum.
    As you are already here I would like to invite you to take a look at the $25 QuickStart-Propeller-Board

    It can do more as 8 basic stamps can do. In speed and in parallel and if you want IR-code for it
    look into the Propeller-code OBEX for example this object http://obex.parallax.com/objects/37/

    But there are some more

    keep the questions coming
    best regards

    Stefan
  • bomberbomber Posts: 297
    edited 2011-08-03 14:14
    I forgot to mention that I have plans to use my PropBOE for this experiment
  • bomberbomber Posts: 297
    edited 2011-08-03 14:17
    I also was hoping for some complete code as I am not that good at Spin or assembly programming.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-08-03 14:24
    oops ! You just wrote already in the titel propeller-powered. Sorry

    Can you please add a verbal description of what the posted basic-code above is doing?
    Of course I can read the code and try to conclude. But I guess you have the "page 238 in Robotics with the Boe-Bot). "
    handy and can describe what it is doing

    keep the questions coming
    best regards

    Stefan
  • bomberbomber Posts: 297
    edited 2011-08-03 14:36
    The code sends a 38.5 kHz signal to the left IR LED and imediatley afterward, reads the state of the I/O pin connected to the left IR reciever. It does the exact same thing for the right IR LED and right IR detector. It then decides how to move based on the readings from the IR detectors. for more info, I would recomend reading chapter 7 in Robotics with the Boe-Bot.
  • localrogerlocalroger Posts: 3,452
    edited 2011-08-03 15:35
    The only semi-wrinkle here is generating the 38.5 kHz waveforms for the IR LED's, but it's not that hard; it's slow enough that you can do it completely in Spin but you have to generate the waveform manually with a repeat loop, !outa[pin], and waitcnt to set the frequency. There is a good tutorial about manually flipping pins in the Propeller 1.0 manual, and a good description of how to use WAITCNT to make an accurate waveform in the current version under the WAITCNT command itself.
  • bomberbomber Posts: 297
    edited 2011-08-03 15:43
    I don't have any signal reading equipment, so it would be easier if someone could give me an exact number for gennerating the 38.5 kHz waveform for the waitcnt command itself.
  • localrogerlocalroger Posts: 3,452
    edited 2011-08-03 16:23
    It's actually very easy to work that out. You'll need a half-wave time to alternate the pin output level, or 77 khz. Standard prop boards run at 80 MHz (5 MHz crystal + PLL16), which gives you 80,000,000 / 77,000 = 1038.9 cnts. I'd use 1039, and use the trick in the WAITVID doc to eliminate jitter. It should look something like this (not tested):
    outa[pin]~  'make sure it starts low
    t := cnt 'initialize this
    'make 8 cycles of 38.5 khz
    repeat 16 'even number, so it ends low!
      !outa[pin] 'toggle pin
      waitcnt(t += 1039)
    'done
    
  • bomberbomber Posts: 297
    edited 2011-08-11 09:28
    I found some code in the PE kit manual. I have modified it to work with my Stingray robot. It also uses an Xbee to comunicate. I will post the code soon.
Sign In or Register to comment.