PDA

View Full Version : Looking for some help with an RFID Program...



Element
01-15-2007, 06:36 AM
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.

Unsoundcode
01-15-2007, 07:35 AM
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.

LSB
01-15-2007, 10:32 AM
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).

LSB
01-15-2007, 10:50 AM
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_sam
01-15-2007, 12:43 PM
Element (http://forums.parallax.com/member.php?u=48386)

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



' -----[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·http://forums.parallax.com/images/smilies/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 Walker
01-16-2007, 12:06 AM
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...

Element
01-16-2007, 10:19 AM
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! http://forums.parallax.com/images/smilies/smile.gif