Shop OBEX P1 Docs P2 Docs Learn Events
Using RFID to change subroutine of robot. — Parallax Forums

Using RFID to change subroutine of robot.

ChrisszChrissz Posts: 6
edited 2009-10-13 14:29 in BASIC Stamp
Hi,
For a school project we are programming a Boe-Bot which uses the Line Rider for navigation.
Also we want it to navigate by just using code.

We mounted a RFID reader underneath the robot and now we want it to Follow a line and at the same time check for any RFID tags in on the ground.

The code we are using right now wil ride a line but when its going to check for a RFID tag it stops. We want it to continue riding the line as long as there is no RFID tag.

Could someone please help us. We have been cracking our heads on this for two full days now...

Our Code so far:
' {$STAMP BS2}
' {$PBASIC 2.5}
' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
Enable          PIN     0                       ' low = reader on
RX              PIN     1                       ' serial from reader
Spkr            PIN     2                       ' speaker output
led             PIN     3                       ' Led Light
' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
T2400           CON     396
' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
buf             VAR     Byte(10)                ' RFID bytes buffer
idx             VAR     Byte                    ' tag byte index
qtis            VAR     Nib                     ' Line follower
counter         VAR     Byte
' -----[noparse][[/noparse] Initialisation ]---------------------------------------------------
OUTB = %1111
' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
main:
DO
  GOSUB rfid
  PAUSE 1
  GOSUB line_rider
  PAUSE 1
LOOP

line_rider:
 FOR counter = 1 TO 16
  GOSUB Check_Qtis
  DEBUG CR, "Riding Line...", CR
  DEBUG BIN4 ? qtis, CRSRUP

  SELECT Qtis
    CASE %1000
      PULSOUT 13, 650
      PULSOUT 12, 650
      PULSOUT 14, 1050
    CASE %1100
      PULSOUT 13, 750
      PULSOUT 12, 650
      PULSOUT 14, 1050
    CASE %0100
      PULSOUT 13, 800
      PULSOUT 12, 650
      PULSOUT 14, 1050
    CASE %0110
      PULSOUT 13, 850
      PULSOUT 12, 650
      PULSOUT 14, 1050
    CASE %0010
      PULSOUT 13, 850
      PULSOUT 12, 700
      PULSOUT 14, 1050
    CASE %0011
      PULSOUT 13, 850
      PULSOUT 12, 750
      PULSOUT 14, 1050
    CASE %0001
      PULSOUT 13, 850
      PULSOUT 12, 850
      PULSOUT 14, 1050
    CASE ELSE
      PAUSE 5
      PULSOUT 14, 1050
    ENDSELECT
    NEXT
    RETURN

rfid:
    LOW Enable
    SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10]  ------------!!** Right now It just stops here because it can't find a tag **!! We just want it to continue riding the line...
    HIGH Enable
    FREQOUT Spkr, 50, 3400
    HIGH led
    FOR idx = 0 TO 9
    DEBUG buf(idx)
    NEXT
    PAUSE 1
    LOW led
 RETURN

Check_Qtis:
  DIRB = %1111
  PAUSE 0
  DIRB = %0000
  PAUSE 0
  qtis = INB
  RETURN


Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-12 14:16
    Look in the Stamp Manual (or the Stamp Editor's help files) for the description of the SERIN statement and you'll see a discussion of a timeout. If you supply a timeout period and a label, the SERIN statement will quit and go to the label if nothing is received by the end of the timeout period.
  • ChrisszChrissz Posts: 6
    edited 2009-10-13 07:53
    So I did what you told me, I've looked into the Basic Stamp Manual. And now I know what you mean, but we just can't figure out how the 'WAIT' and 'LABEL' command is used.
    Could you please tell me what this: ($0A) refers to? It's used in the 'WAIT' label, but how do I modify this to make it wait for 1/100 sec or a second are whatever time period I need.
    It's is not described in my manual "BASIC STAMP Syntax and reference MANUAL" it's the only manual we have at our school.
    In this manual this is what is described about
    Timeout:
    is an option variable/constant/expression (0-65535)
    that tells SERIN how long to wait for incoming data.
    If data does not arrive in time, the program will jump
    to the adress specified by Tlabel

    [noparse][[/noparse]i[noparse][[/noparse]Tlabel:
    is an option label that must be provided along with Timeout,
    indicating where the program should go in the event that data
    does not arrive within the period specified by Timeout.

    Next problem:
    How to make the label direct to another subroutine... STR buf\10
    Right now it's sending to a string where the DATA of the RFID tag is stored right?, please correct me if I'm wrong.

    Please help us..

    smilewinkgrin.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-13 14:02
    The WAIT($0A) is something very different from the Timeout / Tlabel. It's described on pages 404-406 of the Basic Stamp Syntax and Reference Manual.

    The Tlabel is used for a GOTO if the Timeout is exceeded. You'd do something like:
    rfid:
        LOW Enable
        SERIN RX, T2400, 250, nothing, [noparse][[/noparse]WAIT($0A), STR buf\10] ' wait at most 1/4 sec for data
        GOTO doMore
    nothing:
        for idx = 0 to 9 ' Make buf look invalid
            buf(i) = $00
        next
    doMore:
        HIGH Enable
    
  • ChrisszChrissz Posts: 6
    edited 2009-10-13 14:29
    Great!! Found it!
    It's working like a charm!!

    You Rock! [noparse];)[/noparse]

    Thank you very very much.
    When we finish our project I will put some vids and pics online.

    Again, thank you for your help.

    Kind Regards,

    Chris
Sign In or Register to comment.