subscriber_generator.py
Go to the documentation of this file.
1 import functools
2 import rospy
3 import geometry_msgs.msg as gm
4 import visualization_msgs.msg as vm
5 
6 def process_feedback(feedback=None):
7  pass
8 
9 class SubscriberGenerator(object):
10  def __init__(self, server):
11  self._server = server
12 
13  def generate(self, name):
14  node_name = rospy.get_name()
15  rospy.Subscriber('/'.join([node_name, name, 'update_interactive_marker']),
16  vm.InteractiveMarker,
17  functools.partial(self._update_interactive_marker, name))
18  rospy.Subscriber('/'.join([node_name, name, 'update_pose']), gm.Pose,
19  functools.partial(self._update_interactive_marker_pose, name))
20  rospy.Subscriber('/'.join([node_name, name, 'add_control']),
21  vm.InteractiveMarkerControl,
22  functools.partial(self._add_interactive_marker_control, name))
23  rospy.Subscriber('/'.join([node_name, name, 'remove_control']),
24  vm.InteractiveMarkerControl,
25  functools.partial(self._remove_interactive_marker_control, name))
26 
27  def _update_interactive_marker(self, name, int_marker):
28  int_marker_org = self._server.get(name)
29  name_org = int_marker_org.name
30  int_marker_org = int_marker
31  int_marker_org.name = name_org
32  self._server.insert(int_marker_org, process_feedback)
33  self._server.applyChanges()
34 
35  def _update_interactive_marker_pose(self, name, pose):
36  self._server.setPose(name, pose)
37  self._server.applyChanges()
38 
39  def _add_interactive_marker_control(self, name, control):
40  int_marker = self._server.get(name)
41  cntrl = [c for c in int_marker.controls if c.name == control.name]
42  if len(cntrl) == 0:
43  int_marker.controls.append(control)
44  else:
45  cntrl[0] = control
46  self._server.insert(int_marker, process_feedback)
47  self._server.applyChanges()
48 
49  def _remove_interactive_marker_control(self, name, control):
50  int_marker = self._server.get(name)
51  int_marker.controls = [c for c in int_marker.controls if c.name != control.name]
52  self._server.insert(int_marker, process_feedback)
53  self._server.applyChanges()


ez_interactive_marker
Author(s):
autogenerated on Mon Jun 10 2019 13:15:06