Shop OBEX P1 Docs P2 Docs Learn Events
Looking for some help with an RFID Program... — Parallax Forums

Looking for some help with an RFID Program...

ElementElement Posts: 9
edited 2007-01-16 02:19 in BASIC Stamp
I am trying to develop a program for use with RFID tags. What I am trying to do is have a database of RFID tag information and depending on what order the tags are read the output would vary.

For example if I have 3 RFID tags labeled One, Two, and Three and my robot read RFID Tag 1 and then 2, the robot would then turn left. However if the Robot read Tag 3 then 2, it would turn right instead.

I am using a BS 2 and a Parallax RFID Reader. I am also using a modified RFID Parallax Tag Reader Program.

Any help would be much appreciated.

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-01-14 23:35
    Hi Element, you might try looking at the Branch statement or the Lookup/Lookdown statements in the Pbasic help file. These commands can store data that can be referenced from a conditional statement.

    Jeff T.
  • LSBLSB Posts: 175
    edited 2007-01-15 02:32
    Element,
    As often, it is difficult to give a specific answer without code; however, you may store the card IDs as read in an array and then shift the array elements as the 'bot encounters cards as:
    FOUND CARD => gosub NEWCARDENCOUNTERED

    NEWCARDENCOUNTERED:
    For CardsRead = 1 to 5
    CardArray(CardsRead-1)=CardArray(CardsRead) 'SHIFT ELEMENTS BACKWARD EACH TIME A NEW CARD IS ENCOUNTERED
    Next CardsRead
    CardArray(5)=NewestCardEncountered
    Return

    This (or something similar) will give you a 'list' of the last five cards encountered indexed by order. The card last encountered is always in position 5, the prevoius card is in position 4, the prevoius to that in 3... A count of the non-zero elements will indicate how many cards you've passed (< the number of array elements).
  • LSBLSB Posts: 175
    edited 2007-01-15 02:50
    He he--oops, forgot to explain the second part-- use IF and AND as (using variables in previous post):

    If (CardArray(5)=128) AND (CardArray(4)=101) then Gosub RIGHTTURN 'Robot is on the right track
    If (CardArray(5)=101) AND (CardArray(4)=128) then Gosub LEFTTURN 'Wrong way--cards found in opposite order
    If (CardArray(4)=128) AND (CardArray(5)<>111) then Gosub LOST 'From previous card 128, expected next cart should have been 111--and it wasn't!

    I suspect there are more complex data structures that might be more efficient, but if you are only interested in the current and previous cards the possibilities are probably limited enough that if/then and AND will get you through. Just construct your logic carefully using AND, OR, >, <, =, and NOT and look carefully at what combinations are possible.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-01-15 04:43
    Element

    This is a routine that i wrote for a Soldering Station Time Controller that i built
    and used this card routine now i know is for one card at·a time so i do not know if this will help you or not
    but i post any way

    Check_List:
    · FOR tagNum = 1 TO LastTag··········································· ' scan through known tags
    ··· FOR idx = 0 TO 9·················································· ' scan bytes in tag
    ····· READ (tagNum - 1 * 10 + idx), char······························ ' get tag data from table
    ····· #IF __No_SPRAM #THEN
    ······· IF (char <> buf(idx)) THEN Bad_Char···························· ' compare tag to table
    ····· #ELSE
    ······· GET idx, chkChar················································ ' read char from SPRAM
    ······· IF (char <> chkChar) THEN Bad_Char······························ ' compare to table
    ····· #ENDIF
    ··· NEXT
    ··· GOTO Tag_Found······················································· ' all bytes match!

    Bad_Char:································································ ' try next tag
    · NEXT

    Bad_Tag:
    · tagNum = 0
    · GOSUB Show_Name·························································· ' print message
    · GOTO Routine0


    Tag_Found:
    ON tagNum GOSUB Routine0,· Routine1, Routine2, Routine3



    '
    [noparse][[/noparse]Card's Subroutines ]

    ' To use differnet Card for differnet amount of Time
    ' Card # 0 is fot Unauthorized CARD
    ' Card # 1 is fot 15 Minutes and 00 Seconds
    ' Card # 2 is fot 30 Minutes and 00 Seconds
    ' Card # 3 is fot 59 Minutes and 59 Seconds

    '
    ·· 'Unauthorized CARD Routine
    ··········································································· 'Unauthorized CARD Led Light......
    · Routine0:
    ·· mins=$00
    ·· secs=$00

    · GOSUB Set_Time

    · HIGH· Invaild_Card························································ 'Turn ON Led

    · DO
    · HIGH·· tick
    · PAUSE 500
    · LOW·· tick
    ··· GOSUB Get_Time
    ··· IF mins=$00 AND secs=$20 THEN EXIT
    ·· DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR
    ·· DEBUG CR, CR, "Unauthorized CARD", CR
    · LOOP

    · DEBUG CLS, CLS···························································· ' Turn OFF Led
    · LOW· Invaild_Card
    · GOTO main

    ·'15 Minutes CARD Routine

    · Routine1:
    · mins=$00
    · secs=$00
    · GOSUB Set_Time
    ·· GOSUB Get_Time

    · DO
    · HIGH·· tick
    · PAUSE 30
    · LOW·· tick

    ·· IF mins=$00 AND secs=$05 THEN
    · HIGH·· relay························································· ' Turn ON· Relay
    · HIGH·· card15······················································· 'Turn on 15 min led
    · ENDIF
    ················································································
    ··· IF mins=$15 AND secs=$00 THEN EXIT
    ·· GOSUB Get_Time
    · DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR
    · DEBUG CR, CR, "15 MIN CARD ", CR
    · LOOP

    · DEBUG CLS, CLS
    · LOW· relay
    · LOW· card15······ ···························································· ' Turn OFF· Relay
    · GOTO main

    ·'30 Minutes CARD Routine

    · Routine2:

    · mins=$00
    · secs=$00

    · GOSUB Set_Time
    ·· GOSUB Get_Time

    · DO
    · HIGH·· tick
    · PAUSE 30
    · LOW·· tick
    ·· IF mins=$00 AND secs=$05 THEN
    · HIGH·· relay······························································· ' Turn ON· Relay
    · HIGH·· card30·························································· ·'·Turn on 30 min led
    · ENDIF

    · IF mins=$30 AND secs=$00 THEN EXIT
    ·· GOSUB Get_Time
    · DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR
    · DEBUG CR, CR, "30 MIN CARD "
    · LOOP

    · DEBUG CLS, CLS
    · LOW· relay
    · LOW· card30······· ··························································· ' Turn OFF· Relay
    · GOTO main

    · '60 Minutes CARD Routine

    · Routine3:

    · mins=$00
    · secs=$00
    · GOSUB Set_Time
    · GOSUB Get_Time
    · DO
    · HIGH·· tick
    · PAUSE 30
    · LOW·· tick
    · IF mins=$00 AND secs=$05 THEN················································ ' Turn ON Relay
    · HIGH·· relay
    · HIGH·· card60·········································································· '·Turn on 60 min Led
    ·· ENDIF
    ··· IF mins=$59 AND secs=$59 THEN EXIT
    ·· GOSUB Get_Time······························································ ' 60 MIN CARD
    · DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR
    · DEBUG CR, CR, "60 MIN CARD "
    · LOOP
    · DEBUG CLS, CLS
    · LOW·· relay
    · LOW·· card60·································································· ' Turn OFF· Relay
    · GOTO main

    I hope this helps you in what you want to

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 1/15/2007 4:47:17 AM GMT
  • Tom WalkerTom Walker Posts: 509
    edited 2007-01-15 16:06
    Google "Finite State Machines"...his topic has come up before on these fora and seems a likely candidate·for this problem.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • ElementElement Posts: 9
    edited 2007-01-16 02:19
    Okay, thanks for the help!!! I'm still trying to do what you guys said, and continue to have problems, if any of you know a way to help me in any way, that would be great! smile.gif
Sign In or Register to comment.