12 imp.find_module(
"sensor_msgs")
14 import roslib; roslib.load_manifest(
'jsk_teleop_joy')
18 from diagnostic_msgs.msg
import DiagnosticStatus, DiagnosticArray
21 from jsk_rviz_plugins.msg
import OverlayMenu
24 from diagnostic_updater
import Updater
as DiagnosticUpdater
26 AUTO_DETECTED_CLASS =
None 29 global AUTO_DETECTED_CLASS
30 if AUTO_DETECTED_CLASS:
32 if len(msg.axes) == 27
and len(msg.buttons) == 19:
33 rospy.loginfo(
"auto detected as ps3wired")
34 AUTO_DETECTED_CLASS = PS3WiredStatus
35 elif len(msg.axes) == 8
and len(msg.buttons) == 11:
36 rospy.loginfo(
"auto detected as xbox")
37 AUTO_DETECTED_CLASS = XBoxStatus
38 elif len(msg.axes) == 20
and len(msg.buttons) == 17:
39 rospy.loginfo(
"auto detected as ps3")
40 AUTO_DETECTED_CLASS = PS3Status
41 elif len(msg.axes) == 8
and len(msg.buttons) == 19:
42 rospy.loginfo(
"auto detected as ipega")
43 AUTO_DETECTED_CLASS = IpegaStatus
45 AUTO_DETECTED_CLASS =
"UNKNOWN" 48 STATE_INITIALIZATION = 1
50 STATE_WAIT_FOR_JOY = 3
59 stat.summary(DiagnosticStatus.WARN,
60 "initializing JoyManager")
62 stat.summary(DiagnosticStatus.OK,
64 stat.add(
"Joy stick type", str(self.
JoyStatus))
66 stat.summary(DiagnosticStatus.WARN,
67 "waiting for joy message to detect joy stick type")
71 stat.summary(DiagnosticStatus.ERROR,
"no plugin is loaded")
73 stat.summary(DiagnosticStatus.OK,
77 def __init__(self, plugin_package="jsk_teleop_joy"):
81 self.
menu_pub = rospy.Publisher(
"/overlay_menu", OverlayMenu)
83 self.
plugins = rospy.get_param(
'~plugins', {})
102 s = rospy.Subscriber(
'/joy', Joy, autoJoyDetect)
104 error_message_published =
False 106 while not rospy.is_shutdown():
108 if AUTO_DETECTED_CLASS ==
"UNKNOWN":
109 if not error_message_published:
110 rospy.logfatal(
"unknown joy type")
111 error_message_published =
True 113 elif AUTO_DETECTED_CLASS:
135 rospy.loginfo(
'switching to next plugin')
141 rospy.logfatal(
'no valid plugins are loaded')
151 menu.current_index = index
152 menu.title =
"Joystick" 154 menu.action = OverlayMenu.ACTION_CLOSE
162 if history.new(status,
"down")
or history.new(status,
"left_analog_down"):
167 elif history.new(status,
"up")
or history.new(status,
"left_analog_up"):
172 elif history.new(status,
"cross")
or history.new(status,
"center"):
175 elif history.new(status,
"circle"):
186 if self.
history.new(status,
"center"):
197 rospy.init_node(
'jsk_teleop_joy')
199 result = g_manager.start()
201 rospy.logfatal(
"Fatal Error")
206 if __name__ ==
'__main__':
def forceToPluginMenu(self, publish_menu=False)
def publishMenu(self, index, close=False)
def pluginStatusDiagnostic(self, stat)
def processMenuMode(self, status, history)
def switchPlugin(self, index)
def stateDiagnostic(self, stat)
def __init__(self, plugin_package="jsk_teleop_joy")