dwm1001_displayMap.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import copy
5 from interactive_markers.interactive_marker_server import InteractiveMarkerServer
7 from visualization_msgs.msg import (InteractiveMarkerControl, Marker, InteractiveMarker )
8 from geometry_msgs.msg import Point
9 from localizer_dwm1001.msg import Anchor
10 from localizer_dwm1001.msg import Tag
11 
12 
13 server = None
14 rospy.init_node("display_map")
15 server = InteractiveMarkerServer("DWM1001_Anchors_And_Tag_Server")
16 
17 
19 
20 
21  def processFeedback(self, feedback):
22  """
23  Process feedback of markers
24 
25  :param: feedback of markers
26 
27  :returns: none
28 
29  """
30  p = feedback.pose.position
31  rospy.loginfo(feedback.marker_name + " is pluginsnow at " + str(p.x) + ", " + str(p.y) + ", " + str(p.z))
32 
33 
34  def makeBoxControlTag(self,msg):
35  """
36  Create a box controll for tag
37 
38  :param: msg from marker
39 
40  :returns: control
41 
42  """
43 
44  control = InteractiveMarkerControl()
45  control.always_visible = True
46  control.markers.append( self.makeWhiteSphereTag(msg) )
47  msg.controls.append( control )
48  return control
49 
50  def makeBoxControlAnchor(self, msg):
51  """
52  Create a box control for anchor
53 
54  :param: msg from marker
55 
56  :returns: control
57 
58  """
59  control = InteractiveMarkerControl()
60  control.always_visible = True
61  control.markers.append( self.makeGreyCubeAnchor(msg) )
62  msg.controls.append( control )
63  return control
64 
65  def makeWhiteSphereTag(self, msg ):
66  """
67  Create a white sphere for tag
68 
69  :param: msg from marker
70 
71  :returns: marker
72 
73  """
74 
75  marker = Marker()
76  marker.type = Marker.SPHERE
77  marker.scale.x = msg.scale * 0.45
78  marker.scale.y = msg.scale * 0.45
79  marker.scale.z = msg.scale * 0.45
80  marker.color.r = 1
81  marker.color.g = 1
82  marker.color.b = 1
83  marker.color.a = 1.0
84  return marker
85 
86 
87  def makeGreyCubeAnchor(self, msg):
88  """
89  Create a grey cube for anchor
90 
91  :param: msg from marker
92 
93  :returns: marker
94 
95  """
96 
97  marker = Marker()
98 
99  marker.type = Marker.CUBE
100  marker.scale.x = msg.scale * 0.45
101  marker.scale.y = msg.scale * 0.45
102  marker.scale.z = msg.scale * 0.45
103  marker.color.r = 0.5
104  marker.color.g = 0.5
105  marker.color.b = 0.5
106  marker.color.a = 1.0
107  return marker
108 
109 
110 
111  def makeTagMarker(self, position, name):
112  """
113  Make coordinates and control for tag
114 
115  :param: position of tag
116  :param: name for tag
117 
118  :returns:
119 
120  """
121 
122  int_marker = InteractiveMarker()
123  int_marker.header.frame_id = "map"
124  int_marker.pose.position = position
125  int_marker.scale = 1
126 
127  int_marker.name = name
128  int_marker.description = name
129 
130  self.makeBoxControlTag(int_marker)
131 
132  control = InteractiveMarkerControl()
133  control.orientation.w = 1
134  control.orientation.x = 0
135  control.orientation.y = 1
136  control.orientation.z = 0
137  control.interaction_mode = InteractiveMarkerControl.MOVE_ROTATE
138  int_marker.controls.append(copy.deepcopy(control))
139  control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
140  int_marker.controls.append(control)
141 
142  server.insert(int_marker, self.processFeedback)
143 
144 
145 
146  def makeAnchorMarker(self, position, name):
147  """
148  Make coordinates and control for anchor
149 
150  :param: position of anchor
151  :param: name for anchor
152 
153  :returns:
154 
155  """
156 
157  int_marker = InteractiveMarker()
158  int_marker.header.frame_id = "map"
159  int_marker.pose.position = position
160  int_marker.scale = 1
161  int_marker.description = name
162  int_marker.name = name
163 
164  self.makeBoxControlAnchor(int_marker)
165 
166  control = InteractiveMarkerControl()
167  control.orientation.w = 1
168  control.orientation.x = 0
169  control.orientation.y = 1
170  control.orientation.z = 0
171  control.interaction_mode = InteractiveMarkerControl.MOVE_ROTATE
172  int_marker.controls.append(copy.deepcopy(control))
173  control.interaction_mode = InteractiveMarkerControl.MOVE_AXIS
174  int_marker.controls.append(control)
175 
176  server.insert(int_marker, self.processFeedback)
177 
178 
179 
180  def Anchor0callback(self,data):
181  """
182  Callback from topic /dwm1001/anchor0
183 
184  :param: data of anchor 0
185 
186  :returns:
187 
188  """
189  global server
190 
191  # Get the coordinates of the Tag in this format 0 0 0, then split this string using .split() function
192  try:
193  # Create a new marker with passed coordinates
194  position = Point(data.x, data.y, data.z)
195  # Add description to the marker
196  self.makeAnchorMarker(position, "Anchor 0")
197  # TODO remove this after, Debugging purpose
198  rospy.loginfo("Anchor0 x: " + str(data.x) + " y: " + str(data.y) + " z: " + str(data.z))
199  except ValueError:
200  rospy.loginfo("Value error")
201 
202 
203 
204  def Anchor1callback(self,data):
205  """
206  Callback from topic /dwm1001/anchor1
207 
208  :param: data of anchor 1
209 
210  :returns:
211 
212  """
213 
214  global server
215 
216  # Get the coordinates of the Tag in this format 0 0 0, then split this string using .split() function
217  try:
218  # Create a new marker with passed coordinates
219  position = Point(data.x, data.y, data.z)
220  # Add description to the marker
221  self.makeAnchorMarker(position, "Anchor 1")
222 
223  # TODO remove this after, Debugging purpose
224  rospy.loginfo("Anchor1 x: "+ str(data.x) + " y: " + str(data.y) + " z: " + str(data.z))
225 
226  except ValueError:
227  rospy.loginfo("Value error")
228 
229 
230 
231  def Anchor2callback(self,data):
232  """
233  Callback from topic /dwm1001/anchor2
234 
235  :param: data of anchor 2
236 
237  :returns:
238 
239  """
240 
241  global server
242 
243  # Get the coordinates of the Tag in this format 0 0 0, then split this string using .split() function
244  try:
245  # Create a new marker with passed coordinates
246  position = Point(data.x, data.y, data.z)
247  # Add description to the marker
248  self.makeAnchorMarker(position, "Anchor 2")
249  # TODO remove this after, Debugging purpose
250  rospy.loginfo("Anchor2 x: " + str(data.x) + " y: " + str(data.y) + " z: " + str(data.z))
251 
252  except ValueError:
253  rospy.loginfo("Value error")
254 
255  def Anchor3callback(self,data):
256  """
257  Callback from topic /dwm1001/anchor3
258 
259  :param: data of anchor 3
260 
261  :returns:
262 
263  """
264 
265  global server
266 
267  # Get the coordinates of the Tag in this format 0 0 0, then split this string using .split() function
268  try:
269  # Create a new marker with passed coordinates
270  position = Point(data.x, data.y, data.z)
271  # Add description to the marker
272  self.makeAnchorMarker(position, "Anchor 3")
273  # TODO remove this after, Debugging purpose
274  rospy.loginfo("Anchor3 x: " + str(data.x) + " y: " + str(data.y) + " z: " + str(data.z))
275 
276  except ValueError:
277  rospy.loginfo("Value error")
278 
279  def TagCallback(self,data):
280  """
281  Callback from topic /dwm1001/tag
282 
283  :param: data of tag
284 
285  :returns:
286 
287  """
288  global server
289 
290  # Get the coordinates of the Tag in this format 0 0 0, then split this string using .split() function
291  try:
292  # Create a new marker with passed coordinates
293  position = Point(data.x, data.y, data.z)
294  # Add description to the marker
295  self.makeTagMarker(position, "Tag")
296  # Publish marker
297  server.applyChanges()
298 
299  # TODO remove this after, Debugging purpose
300  rospy.loginfo("Tag x: " + str(data.x) + " y: " + str(data.y) + " z: " + str(data.z))
301 
302  except ValueError:
303  rospy.loginfo("Value error")
304 
305 
306 
307  def start(self):
308  rospy.Subscriber("/dwm1001/anchor0", Anchor, self.Anchor0callback)
309  rospy.Subscriber("/dwm1001/anchor1", Anchor, self.Anchor1callback)
310  rospy.Subscriber("/dwm1001/anchor2", Anchor, self.Anchor2callback)
311  rospy.Subscriber("/dwm1001/anchor3", Anchor, self.Anchor3callback)
312  rospy.Subscriber("/dwm1001/tag" , Tag , self.TagCallback)
313  rospy.spin()
314 
315 
316 
317 def main():
318  displayInRviz = DisplayInRviz()
319  displayInRviz.start()
320 
321 if __name__=="__main__":
322  main()
323 
def makeTagMarker(self, position, name)
def makeAnchorMarker(self, position, name)


dwm1001_ros
Author(s):
autogenerated on Mon Jun 10 2019 13:05:20