visualize_navigation_goals.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import sys
19 import rospy
20 import tf
21 from visualization_msgs.msg import Marker
22 from visualization_msgs.msg import MarkerArray
23 from dynamic_reconfigure.server import Server
24 from cob_helper_tools.cfg import HelperToolsConfig
25 
27  def __init__(self):
28  self.text_size = 0.5
29  self.srv = Server(HelperToolsConfig, self.reconfigure_callback)
30  self.pubGoals = rospy.Publisher('visualize_navigation_goals', MarkerArray, queue_size=1, latch=True)
31 
32  def reconfigure_callback(self, config, level):
33  self.text_size = config.text_size
34  return config
35 
36  def pubMarker(self):
37  navigation_goals = rospy.get_param("/script_server/base", {})
38 
39  markerarray = MarkerArray()
40  i=0
41  for name, pose in list(navigation_goals.items()):
42 
43  # check if pose is valid
44  if len(pose) != 3:
45  continue
46 
47  # arrow
48  marker_arrow = Marker()
49  marker_arrow.header.stamp = rospy.Time.now()
50  marker_arrow.header.frame_id = "map"
51  marker_arrow.ns = "/"+name
52  marker_arrow.id = i
53  marker_arrow.type = Marker.ARROW
54  marker_arrow.action = Marker.ADD
55  marker_arrow.scale.x = 1.0
56  marker_arrow.scale.y = 0.1
57  marker_arrow.scale.z = 0.1
58  marker_arrow.color.r = 0.0
59  marker_arrow.color.g = 0.0
60  marker_arrow.color.b = 1.0
61  marker_arrow.color.a = 1.0
62  marker_arrow.pose.position.x = pose[0]
63  marker_arrow.pose.position.y = pose[1]
64  marker_arrow.pose.position.z = 0.2
65  quaternion = tf.transformations.quaternion_from_euler(0, 0, pose[2])
66  marker_arrow.pose.orientation.x = quaternion[0]
67  marker_arrow.pose.orientation.y = quaternion[1]
68  marker_arrow.pose.orientation.z = quaternion[2]
69  marker_arrow.pose.orientation.w = quaternion[3]
70  markerarray.markers.append(marker_arrow)
71 
72  # text
73  marker_text = Marker()
74  marker_text.header.stamp = rospy.Time.now()
75  marker_text.header.frame_id = "map"
76  marker_text.ns = "/"+name
77  marker_text.id = i + 1000000
78  marker_text.type = Marker.TEXT_VIEW_FACING
79  marker_text.action = Marker.ADD
80  marker_text.scale.z = self.text_size
81  marker_text.color.r = 0.0
82  marker_text.color.g = 0.0
83  marker_text.color.b = 1.0
84  marker_text.color.a = 1.0
85  marker_text.pose.position.x = pose[0]
86  marker_text.pose.position.y = pose[1] + 0.2
87  marker_text.pose.position.z = 0.2
88  quaternion = tf.transformations.quaternion_from_euler(0, 0, pose[2])
89  marker_text.pose.orientation.x = quaternion[0]
90  marker_text.pose.orientation.y = quaternion[1]
91  marker_text.pose.orientation.z = quaternion[2]
92  marker_text.pose.orientation.w = quaternion[3]
93  marker_text.text = name
94  markerarray.markers.append(marker_text)
95 
96  i = i + 1
97 
98  self.pubGoals.publish(markerarray)
99 
100 if __name__ == "__main__":
101  rospy.init_node('navigation_goal_visualizer')
103  r = rospy.Rate(1)
104  while not rospy.is_shutdown():
105  p.pubMarker()
106  try:
107  r.sleep()
108  except rospy.exceptions.ROSInterruptException as e:
109  pass


cob_helper_tools
Author(s): Felix Messmer
autogenerated on Wed Apr 7 2021 03:03:09