ips_map.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """
3 This node publishes tf transforms between the frame_id set in the config file and the beacon positions in that zone.
4 You can use these transforms for visualization in rviz to make sure you have set up your environment correctly.
5 
6 Published tf's:
7  - beacon.frame_id -> beacon.eid
8  Transforms for all zones and beacons defined in the config file. Transforms are broadcasted from the zone
9  frame_id to the position of the beacon in that frame
10 
11 Parameters:
12  - ~config_file (string, default='config/zones.yml'):
13  Path to the configuration file of zones and beacons relative to the package directory
14  - ~rate (double, default=0.1):
15  The publishing rate of transforms in transforms per second
16 """
17 
18 import os
19 import rospy
20 import tf2_ros
21 import rospkg
22 from geometry_msgs.msg import TransformStamped
23 from indoor_positioning.positioning import Positioning
24 
25 
26 class IPSMap:
27  """
28  Get all beacons from the configuration file and store them in a list. Then publish tf transforms for every beacon
29  from the zone's frame_id to the position of the beacon.
30  """
31  def __init__(self):
32  # get directory of config file
33  config_dir = rospy.get_param('~config_file') if rospy.has_param('~config_file') else 'config/zones.yml'
34  abs_dir = os.path.join(rospkg.RosPack().get_path('indoor_positioning'), config_dir)
35  # initialize positioning class
36  positioning = Positioning(abs_dir)
37 
38  # get all beacon objects
39  self.beacons = []
40  for z in positioning.zones:
41  for b in z.beacons:
42  self.beacons.append(b)
43 
44  # initialize transform broadcaster
45  self.br = tf2_ros.StaticTransformBroadcaster()
46 
47  # publishing rate
48  self.rate = rospy.Rate(rospy.get_param('~rate')) if rospy.has_param('~rate') else rospy.Rate(0.1)
49 
50  def publish(self):
51  """Publish static tfs for beacon positions and zone polygons"""
52  tf = TransformStamped()
53  while not rospy.is_shutdown():
54  # publish transforms for all positions
55  tf.header.stamp = rospy.Time.now()
56  for b in self.beacons:
57  tf.header.frame_id = b.frame_id
58  tf.child_frame_id = b.eid
59 
60  tf.transform.translation.x = b.position[0]
61  tf.transform.translation.y = b.position[1]
62  tf.transform.translation.z = b.position[2]
63 
64  tf.transform.rotation.x = 0
65  tf.transform.rotation.y = 0
66  tf.transform.rotation.z = 0
67  tf.transform.rotation.w = 1
68 
69  self.br.sendTransform(tf)
70  rospy.sleep(0.5)
71  # wait for next iteration
72  self.rate.sleep()
73 
74 
75 if __name__ == '__main__':
76  # start node
77  rospy.init_node('ips_map', anonymous=True)
78  # initialize IPSReceiver class
79  ips = IPSMap()
80  try:
81  # publish receiver messages
82  ips.publish()
83  except rospy.ROSInterruptException:
84  pass
def publish(self)
Definition: ips_map.py:50
def __init__(self)
Definition: ips_map.py:31


indoor_positioning
Author(s): Christian Arndt
autogenerated on Mon Jun 10 2019 13:33:13