tm_usbpro.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ## Grabs RFID detection data from the ThingMagic USBPro RFID reader and publishes
4 ## thingmagic_usbpro/RFID_Detection messages to the RFID_detections
5 
6 import rospy
7 from thingmagic_usbpro.msg import RFID_Detection
8 import mercury
9 
10 '''
11 RFID_Detection message format:
12 string epc
13 int8 antenna
14 int8 read_count
15 int8 rssi
16 '''
17 
18 
19 banner='''
20  _____ _ _ __ __ _
21 |_ _| |__ (_)_ __ __ _| \/ | __ _ __ _(_) ___
22  | | | '_ \| | '_ \ / _` | |\/| |/ _` |/ _` | |/ __|
23  | | | | | | | | | | (_| | | | | (_| | (_| | | (__
24  |_| |_| |_|_|_| |_|\__, |_| |_|\__,_|\__, |_|\___|
25  |___/ |___/
26  _ _ ____ ____ ____ _____ ___ ____
27 | | | / ___|| __ ) _ __ _ __ ___ | _ \| ___|_ _| _ \
28 | | | \___ \| _ \| '_ \| '__/ _ \ | |_) | |_ | || | | |
29 | |_| |___) | |_) | |_) | | | (_) | | _ <| _| | || |_| |
30  \___/|____/|____/| .__/|_| \___/ |_| \_\_| |___|____/
31  |_|
32  ____ _
33 | _ \ ___ __ _ __| | ___ _ __
34 | |_) / _ \/ _` |/ _` |/ _ \ '__|
35 | _ < __/ (_| | (_| | __/ |
36 |_| \_\___|\__,_|\__,_|\___|_|
37 '''
38 
39 
41 
42  pub = rospy.Publisher('RFID_detections', RFID_Detection, queue_size=10)
43  rospy.init_node('RFID_node', anonymous=True)
44  rospy.loginfo(banner)
45 
46  port_param = rospy.get_param('/rfid_detector_node/port', '/dev/ttyACM0')
47  region_param = rospy.get_param('/rfid_detector_node/region', 'NA')
48  rate_param = rospy.get_param('/rfid_detector_node/rate', 10)
49 
50 
51  rospy.loginfo("Got port name param: "+port_param)
52  rospy.loginfo("Got region param: "+region_param)
53  rospy.loginfo("Got publishing rate param: "+str(rate_param))
54 
55  try:
56  reader = mercury.Reader("tmr://" + port_param)
57  except Exception as e:
58  rospy.loginfo("Couldn't open RFID reader on port: "+str(port_param))
59  raise rospy.exceptions.ROSInitException("couldn't open port for RFID reader, check Launch file for port name")
60  quit(1)
61 
62  try:
63  reader.set_region(region_param)
64  except Exception as e:
65  rospy.loginfo("Couldn't set RFID reader's region to: "+str(region_param))
66  raise rospy.exceptions.ROSInitException("couldn't set region for RFID reader")
67  quit(1)
68 
69  rate = rospy.Rate(int(rate_param)) #hz
70 
71  while not rospy.is_shutdown():
72  result = reader.read(5)
73  for tagdata in result:
74  rospy.loginfo("Antenna:%i Read_Count:%i RSSI:%i EPC:%s" %(tagdata.antenna, tagdata.read_count,tagdata.rssi,tagdata.epc))
75  detect_msg = RFID_Detection(str(tagdata.epc),tagdata.antenna,tagdata.read_count,tagdata.rssi)
76  pub.publish(detect_msg)
77  rate.sleep()
78 
79 if __name__ == '__main__':
80  try:
82  except rospy.ROSInterruptException:
83  pass
84 


thingmagic_usbpro
Author(s):
autogenerated on Sun Apr 16 2017 02:24:49