def __init__(self): rospy.loginfo('Joystick base init ...') self.pub = rospy.Publisher('base/cmd_vel', Twist, queue_size=1) self.pub_priority = rospy.Publisher('base/master_cmd_vel', Twist, queue_size=1) self.cancel_goal_client = rospy.ServiceProxy('/bender/nav/goal_server/cancel', Empty) # control self.is_paused = False # load configuration self.b_pause = rospy.get_param('~b_pause', 'START') self.b_cancel = rospy.get_param('~b_cancel', 'B') self.b_priority = rospy.get_param('~b_priority', 'LB') a_linear = rospy.get_param('~a_linear', 'LS_VERT') a_angular = rospy.get_param('~a_angular', 'LS_HORZ') self.max_linear_vel = rospy.get_param('~max_linear_vel', 0.5) self.max_angular_vel = rospy.get_param('~max_angular_vel', 0.5) key_mapper = xbox.KeyMapper() self.b_idx_pause = key_mapper.get_button_id(self.b_pause) self.b_idx_cancel = key_mapper.get_button_id(self.b_cancel) self.b_idx_priority = key_mapper.get_button_id(self.b_priority) self.a_idx_linear = key_mapper.get_axis_id(a_linear) self.a_idx_angular = key_mapper.get_axis_id(a_angular) # check self.assert_params() # ready to work rospy.Subscriber('joy', Joy, self.callback, queue_size=1) rospy.loginfo('Joystick for base is ready')
def __init__(self): rospy.loginfo('Joystick TTS init ...') # connections self.tts_client = rospy.ServiceProxy('tts/say', BenderString) # load tts configuration self.tts_phrases = rospy.get_param('~tts_phrases', []) self.b_pause = rospy.get_param('~b_pause', 'START') b_increment = rospy.get_param('~b_increment', 'UP') b_decrement = rospy.get_param('~b_decrement', 'DOWN') b_phrase_1 = rospy.get_param('~b_phrase_1', 'LEFT') b_phrase_2 = rospy.get_param('~b_phrase_2', 'RIGHT') key_mapper = xbox.KeyMapper() self.b_idx_pause = key_mapper.get_button_id(self.b_pause) self.b_idx_increment = key_mapper.get_button_id(b_increment) self.b_idx_decrement = key_mapper.get_button_id(b_decrement) self.b_idx_phrase_1 = key_mapper.get_button_id(b_phrase_1) self.b_idx_phrase_2 = key_mapper.get_button_id(b_phrase_2) # check self.assert_params() # control self.is_paused = False self.tts_level = 0 # ready to work rospy.Subscriber('joy', Joy, self.callback, queue_size=1) rospy.loginfo('Joystick for TTS is ready')
def params_are_valid(self): """ checks whether the user parameters are valid or no. """ assert isinstance(self.proxy_button, str) assert isinstance(self.default_channel, str) assert isinstance(self.channels, dict) button_set = set() key_mapper = xbox.KeyMapper() if not key_mapper.has_button(self.proxy_button): rospy.logerr("proxy: unknown button '%s'" % self.proxy_button) return False button_set.add(self.proxy_button) for channel_name, channel in self.channels.items(): assert isinstance(channel_name, str) assert isinstance(channel, dict) if 'button' not in channel: rospy.logerr( "proxy: channel '%s' does not has 'button' field" % channel_name) return False if 'topic' not in channel: rospy.logerr("proxy: channel '%s' does not has 'topic' field" % channel_name) return False assert isinstance(channel['button'], str) assert isinstance(channel['topic'], str) if not key_mapper.has_button(channel['button']): rospy.logerr("proxy: button '%s' is invalid for channel '%s'" % (channel['button'], channel_name)) return False if channel['button'] == self.proxy_button: rospy.logerr( "proxy: button for channel '%s' cannot be equals to the proxy button" % channel_name) return False button_set.add(channel['button']) if self.default_channel not in self.channels: rospy.logerr( "proxy: default channel '%s' is not into the available options" % self.default_channel) return False if len(button_set) != len(self.channels) + 1: rospy.logerr("proxy: all buttons must be different!") return False return True
def __init__(self): rospy.loginfo('Joystick head init ...') # connections self.head_pub = rospy.Publisher('head/cmd', Emotion, queue_size=1) # load head configuration self.b_pause = rospy.get_param('~b_pause', 'START') b_neck_actuate = rospy.get_param('~b_neck_actuate', 'RS') a_neck_sides = rospy.get_param('~a_neck_sides', 'RS_HORZ') a_neck_front = rospy.get_param('~a_neck_front', 'RS_VERT') b_increment = rospy.get_param('~b_increment', 'RB') b_decrement = rospy.get_param('~b_decrement', 'LB') b_happy = rospy.get_param('~b_happy', 'A') b_angry = rospy.get_param('~b_angry', 'B') b_sad = rospy.get_param('~b_sad', 'X') b_surprise = rospy.get_param('~b_surprise', 'Y') self.max_neck_degrees = rospy.get_param('~max_neck_degrees', 60) self.max_emotion_intensity = rospy.get_param('~max_emotion_intensity', 3) self.min_emotion_intensity = rospy.get_param('~min_emotion_intensity', 1) # convert to ids key_mapper = xbox.KeyMapper() self.b_idx_pause = key_mapper.get_button_id(self.b_pause) self.a_idx_neck_sides = key_mapper.get_axis_id(a_neck_sides) self.a_idx_neck_front = key_mapper.get_axis_id(a_neck_front) self.b_idx_neck_actuate = key_mapper.get_button_id(b_neck_actuate) self.b_idx_increment = key_mapper.get_button_id(b_increment) self.b_idx_decrement = key_mapper.get_button_id(b_decrement) self.b_idx_happy = key_mapper.get_button_id(b_happy) self.b_idx_angry = key_mapper.get_button_id(b_angry) self.b_idx_sad = key_mapper.get_button_id(b_sad) self.b_idx_surprise = key_mapper.get_button_id(b_surprise) # check self.assert_params() # control self.is_paused = False self.emotion_intensity = self.min_emotion_intensity # ready to work rospy.Subscriber('joy', Joy, self.callback, queue_size=1) rospy.loginfo('Joystick for head is ready')
def __init__(self): rospy.loginfo('Joystick proxy init ...') # control # default: active on channel 0 self.current_channel_name = 'base' # load params self.proxy_button = rospy.get_param('~b_proxy', 'BACK') self.channels = rospy.get_param( '~channels', {'base': { 'button': 'A', 'topic': 'base' }}) self.default_channel = rospy.get_param('~default_channel', 'base') # check params if not self.params_are_valid(): sys.exit(1) # map ids and map button names to button ids key_mapper = xbox.KeyMapper() self.proxy_button_id = key_mapper.get_button_id(self.proxy_button) for channel_name, channel in self.channels.items(): button = self.channels[channel_name]['button'] topic = self.channels[channel_name]['topic'] self.channels[channel_name]["id"] = key_mapper.get_button_id( button) self.channels[channel_name]["publisher"] = rospy.Publisher( topic, Joy, queue_size=10) # enable channel self.enable_channel(self.default_channel) # ready to work rospy.Subscriber('joy', Joy, self.callback) rospy.loginfo('Joystick proxy is ready')