environment_plane_modeling_client.py
Go to the documentation of this file.
1 from jsk_teleop_joy.joy_plugin import JSKJoyPlugin
2 from jsk_rviz_plugins.msg import OverlayMenu
3 from std_srvs.srv import Empty
4 
5 import rospy
6 
8  def __init__(self, name, args):
9  JSKJoyPlugin.__init__(self, name, args)
10  self.menu_pub = rospy.Publisher("/overlay_menu", OverlayMenu)
11  self.menus = [
12  ["Append Pre-defined Polygon", self.appendPreDefinedPolygon],
13  ["Register Current GridMap", self.registerCurrentGridMap],
14  ["Clear Environment", self.clearEnvironment],
15  ["Exit", self.exit]]
16  self.clear_maps_srv = rospy.ServiceProxy(
17  self.getArg("clear_maps", "/env_server/clear_maps"), Empty)
18  self.register_current_map_srv = rospy.ServiceProxy(
19  self.getArg("register_current_map", "/env_server/register_to_hisotry"), Empty)
20  self.register_completed_map_srv = rospy.ServiceProxy(
21  self.getArg("register_completed_map", "/env_server/register_completion_to_hisotry"), Empty)
22  self.current_index = 0
23  def joyCB(self, status, history):
24  # self.pub.publish(status.orig_msg)
25  if history.new(status, 'up'):
26  self.upCursor()
27  elif history.new(status, 'down'):
28  self.downCursor()
29  #publish menu anyway
30  if history.new(status, 'cross'):
31  self.publishMenu(close=True)
32  rospy.sleep(0.2)
33  self.manager.forceToPluginMenu(publish_menu=False)
34  elif history.new(status, 'circle'):
35  # call the function
36  func = self.menus[self.current_index][1]
37  func()
38  else:
39  self.publishMenu()
40  def downCursor(self):
41  if self.current_index == len(self.menus) - 1:
42  self.current_index = 0
43  else:
44  self.current_index = self.current_index + 1
45  def upCursor(self):
46  if self.current_index == 0:
47  self.current_index = len(self.menus) - 1
48  else:
49  self.current_index = self.current_index - 1
50  def exit(self): #same to cross button
51  self.publishMenu(close=True)
52  rospy.sleep(0.2)
53  self.manager.forceToPluginMenu(publish_menu=False)
55  try:
57  except rospy.ServiceException as e:
58  rospy.logfatal("failed to register current map: %s" % (e))
60  try:
62  except rospy.ServiceException as e:
63  rospy.logfatal("failed to register completed current map: %s" % (e))
64  def clearEnvironment(self):
65  try:
66  self.clear_maps_srv()
67  except rospy.ServiceException as e:
68  rospy.logfatal("failed to clear_map: %s" % (e))
69  def publishMenu(self, close=False):
70  menu = OverlayMenu()
71  menu.menus = [m[0] for m in self.menus]
72  menu.current_index = self.current_index
73  menu.title = self.name
74  if close:
75  menu.action = OverlayMenu.ACTION_CLOSE
76  self.menu_pub.publish(menu)
77 
def getArg(self, key, default=None)
Definition: joy_plugin.py:19


jsk_teleop_joy
Author(s): Ryohei Ueda
autogenerated on Sun May 28 2023 03:03:37