Shop OBEX P1 Docs P2 Docs Learn Events
RFID comparing — Parallax Forums

RFID comparing

ChrisszChrissz Posts: 6
edited 2009-11-06 03:05 in Accessories
I'm trying to let my robot do a specific task which is given by 1 of my 3 different tags.

So I have a BoeBot bot a RFID reader underneath it wich reads tags in the road.
Now I want to let my BoeBot drive a specific route (specified in a sub-routine) according to on which tag it's driving.

So for instance:
Tag1 = Straight ahead
Tag2 = Right Turn
Tag3 = Left Turn

My robot is driving on a line and when the line stops the RFID reader will be activated and waits for a tag. Which is right beneath the reader when the robot stops, and then decide where to go.

So my question is:
How do I point a Tag to a 'gosub' (Sub Routine)?

In super simple code:
IF Tag1 = RfidTag THEN GOSUB route1 ELSE
IF Tag2 = RfidTag THEN GOSUB route2 ELSE
IF Tag3 = RfidTag THEN GOSUB route3 ELSE
repeat whole sequence
ENDIF


I would really appreciate some help with this.

This is what I got right now:
And this only gives me this text in my DEBUG Console:
Door Closed
blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1
blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1blok1
0: Acces Denied






' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------

Enable          PIN     0                       ' low = reader on
RX              PIN     1                       ' serial from reader
Spkr            PIN     2                       ' speaker output
Latch           PIN     12                      ' lock/latch control


' -----[noparse][[/noparse] Constants ]-------------------------------------------------------

    T2400       CON     396
    T4800       CON     188
SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     T2400


LastTag         CON     3
' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
  buf           VAR     Byte(10)                ' RFID bytes buffer
tagNum          VAR     Nib                     ' from EEPROM table
idx             VAR     Byte                    ' tag byte index
char            VAR     Byte                    ' character from table
pulse           VAR     Byte

' -----[noparse][[/noparse] EEPROM Data ]-----------------------------------------------------

Tag1            DATA    "0F0296ADFD"            ' valid tags
Tag2            DATA    "0F0296D21E"
Tag3            DATA    "0F0296ADEB"

Name0           DATA    "Acces Denied", CR, 0
Name1           DATA    "Acces Granted, Welcome Tag 1(White)", CR, 0
Name2           DATA    "Acces Granted, Welcome Tag 2(Black)", CR, 0
Name3           DATA    "Tag 3 (Small Round)", CR, 0


' -----[noparse][[/noparse] Initialization ]--------------------------------------------------

Reset:
  HIGH Enable                                   ' turn of RFID reader
  'GOSUB close_door
  DEBUG "Door Closed", CR                              ' lock the door!


' -----[noparse][[/noparse] Program Code ]----------------------------------------------------

Main:
  LOW Enable                                    ' activate the reader
    SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10]    ' wait for hdr + ID
  HIGH Enable                                   ' deactivate reader

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 (Tag1 <> buf(idx)) THEN
    GOSUB route1
    ELSEIF (Tag2 <> buf(idx)) THEN
    GOSUB route2
    ELSEIF (Tag3 <> buf(idx)) THEN
    GOSUB route3    ' compare tag to table
    ELSE
    GOSUB main
    ENDIF
  NEXT

Bad_Char:                                       ' try next tag
  NEXT

  END


' -----[noparse][[/noparse] Subroutines ]-----------------------------------------------------

route1:
DEBUG "blok1"
RETURN

route2:
DEBUG "blok2"
RETURN

route3:
DEBUG "blok3"
RETURN




Post Edited (Chrissz) : 11/5/2009 11:22:23 AM GMT

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-11-05 14:19
    First, fix your indentation. The Check_list subroutine isn't formatted correctly. Next, you are changing the right hand side of the equation, but not the left. You are always comparing to the first byte (?) of the tag data, not the entire string. You'll need to add an index to that too. Thirdly, you're not actually comparing right. You need to compare the entire string (or some set part) before you GOSUB anywhere. Theoretically the code could got to all three subroutines if the scanned tag managed to match the three in memory in three different locations. Also, why are you comparing with <> (not equal to)? but using that as a condition to go somewhere? Next, you have a read command in there but you are not using the data that you read. It's not used, so you can take it out. Finally, you are calling the function recursively. Why? You have an "Else GOSUB Main", but the main doesn't have a return function. It falls through into Check_list, calls main again, and so on. The BS2 can support something like 6 levels of recursion, so after that it's just broken.
  • ChrisszChrissz Posts: 6
    edited 2009-11-05 22:12
    Thanks for your quick reply,

    I already thought I screwed up the code pretty bad.
    I noticed my mistakes when I read your post. [noparse]:)[/noparse]
    Definitely going to fix that tomorrow.

    Could you please give me a small example of how I could compare multiple Tags with the EEPROM stored tags, because I really couldn't figure it out.

    I only can get it working like it's been explained in the RFID manual on the Parallax product page, where the scanned tag is being compared to the EEEPROM data and as long if it's stored in the EEEPROM, all the tags will trigger the same action. And I want to trigger three different actions with three different tags...

    Hope someone can help me with this because I really need to get it working tomorrow morning, else we're stuck again and we will waste a lot of precious time at school.
    And since there's no teacher on my school who knows how BStamp works, I totally rely on you guys.

    I really appreciate all of your help. And I don't know where else I could find more specific information about this, other than the parallax website.
  • SRLMSRLM Posts: 5,045
    edited 2009-11-06 00:27
    You need to think about it in a different way. Forget about PBASIC: it doesn't matter. It is just a tool. Instead, think of how you want to compare the tags. Probably the most straight forward way is to compare it the same way you would in real life:

    Look at the first number of the unidentified tag
    Compare to each of the first numbers of the known tag
    Record which tags are a match for the first number.
    Go back to the beginning, but look at the second number.
    Repeat for the entire length of the string
    
    



    The challenge now is to convert that to PBASIC. But, if you just remember that there is a reason behind the code you can come up with a solution.

    BTW, I say number and not character or letter because the string is a sequence of hex numbers (in ASCII, true, but it is still represents a number). If you aren't familiar with hex I suggest that you find an online tutorial and work it out. It will help immensely.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-11-06 03:05
    This is all you need to do what you want to do
    Tag_Found:
    ON tagNum GOSUB Routine0,· Routine1, Routine2, Routine3

    I· hope this helps

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 11/6/2009 3:12:20 AM GMT
Sign In or Register to comment.