hardware_ros_driver.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -- coding: utf-8 --
3 # license removed for brevity
4 
5 import serial
6 import json
7 import time
8 import rospy
9 from uwb_hardware_driver.msg import AnchorScan
10 
11 port = "/dev/ttyACM1"
12 baud_rate = 19200
13 
14 ser = serial.Serial(port, baud_rate)
15 
17 
18  anchor_info = {
19  0: [2.675, -0.09, 1.94], # S
20  1: [3.42, 4.58, 2.07], # C
21  2: [12.475, -0.015, 2.4], # B
22  3: [12.473, 4.543, 2.35] # A
23  }
24 
25  return anchor_info
26 
27 
28 def pub():
29 
30  rospy.init_node("hardware_ros_driver", anonymous = True)
31  pub = rospy.Publisher('IPS', AnchorScan, queue_size = 2)
32  rate = rospy.Rate(5)
33 
34  anchor_info = init_anchors()
35  anchor_id = list(anchor_info.keys())
36  anchor_coords = list(anchor_info.values())
37 
38  anchor_coords_x = list()
39  anchor_coords_y = list()
40  anchor_coords_z = list()
41 
42  for item in anchor_coords:
43  anchor_coords_x.append(item[0])
44  anchor_coords_y.append(item[1])
45  anchor_coords_z.append(item[2])
46 
47 
48  while not rospy.is_shutdown():
49 
50  msg = AnchorScan()
51 
52  msg.header.stamp = rospy.Time.now()
53  msg.AnchorID = anchor_id
54  msg.x = anchor_coords_x
55  msg.y = anchor_coords_y
56  msg.z = anchor_coords_z
57 
58  data = ser.readline()
59 
60  if data[0] == "{":
61  parsed_data = (json.loads(data))
62  print(json.dumps(parsed_data)) #, indent=4))
63  #print(parsed_data)
64 
65  msg.tdoa_of_anchors = [float(parsed_data["DCS"])/100, float(parsed_data["DBS"])/100, float(parsed_data["DAS"])/100]
66 
67  pub.publish(msg)
68  rate.sleep()
69 
70 
71 if __name__ == '__main__':
72  try:
73  pub()
74  except rospy.ROSInterruptException:
75  pass


uwb_hardware_driver
Author(s):
autogenerated on Wed Dec 18 2019 03:20:46