interactive.py
Go to the documentation of this file.
1 from easy_markers.generator import MarkerGenerator
2 from visualization_msgs.msg import InteractiveMarker
3 from interactive_markers.interactive_marker_server import InteractiveMarkerServer
4 from visualization_msgs.msg import InteractiveMarkerControl
5 from math import sqrt
6 
7 TYPEDATA = {
8  'rotate_x': [1, 1, 0, 0, InteractiveMarkerControl.ROTATE_AXIS],
9  'rotate_y': [1, 0, 0, 1, InteractiveMarkerControl.ROTATE_AXIS],
10  'rotate_z': [1, 0, 1, 0, InteractiveMarkerControl.ROTATE_AXIS],
11  'move_x': [1, 1, 0, 0, InteractiveMarkerControl.MOVE_AXIS],
12  'move_y': [1, 0, 0, 1, InteractiveMarkerControl.MOVE_AXIS],
13  'move_z': [1, 0, 1, 0, InteractiveMarkerControl.MOVE_AXIS],
14 }
15 SQRT2 = sqrt(2)
16 
17 
18 def default_callback(feedback):
19  print(feedback)
20 
21 
23  def __init__(self, name="interactive_markers"):
26  self.mg.type = 1
27  self.mg.scale = [.25] * 3
28  self.c = 0
29  self.markers = {}
30 
31  def makeMarker(self, callback=None, marker=None, pose=[0, 0, 0], controls=[],
32  fixed=False, name=None, frame="map", description="", imode=0, rot=[0, 0, 0, 1]):
33 
34  if marker is None:
35  marker = self.mg.marker()
36 
37  if callback is None:
38  callback = default_callback
39 
40  if name is None:
41  name = "control%d" % self.c
42  self.c += 1
43 
44  int_marker = InteractiveMarker()
45  int_marker.header.frame_id = frame
46  int_marker.pose.position.x = pose[0]
47  int_marker.pose.position.y = pose[1]
48  int_marker.pose.position.z = pose[2]
49  int_marker.pose.orientation.x = rot[0]
50  int_marker.pose.orientation.y = rot[1]
51  int_marker.pose.orientation.z = rot[2]
52  int_marker.pose.orientation.w = rot[3]
53  int_marker.scale = 1
54  int_marker.name = name
55  int_marker.description = description
56 
57  control = InteractiveMarkerControl()
58  control.always_visible = True
59  control.interaction_mode = imode
60  control.markers.append(marker)
61  int_marker.controls.append(control)
62 
63  for control_name in controls:
64  data = TYPEDATA[control_name]
65  control = InteractiveMarkerControl()
66  control.orientation.w = data[0] / SQRT2
67  control.orientation.x = data[1] / SQRT2
68  control.orientation.y = data[2] / SQRT2
69  control.orientation.z = data[3] / SQRT2
70  control.name = control_name
71  control.interaction_mode = data[4]
72  if fixed:
73  control.orientation_mode = InteractiveMarkerControl.FIXED
74  int_marker.controls.append(control)
75 
76  self.server.insert(int_marker, callback)
77  self.markers[name] = int_marker
78  self.server.applyChanges()
def default_callback(feedback)
Definition: interactive.py:18
def makeMarker(self, callback=None, marker=None, pose=[0, controls=[], fixed=False, name=None, frame="map", description="", imode=0, rot=[0)
Definition: interactive.py:32
def __init__(self, name="interactive_markers")
Definition: interactive.py:23


easy_markers
Author(s): David V. Lu!!
autogenerated on Tue Mar 1 2022 00:06:55