16 from __future__
import print_function
20 from std_msgs.msg
import Bool
21 from geometry_msgs.msg
import Twist, Accel, Vector3
22 from sensor_msgs.msg
import Joy
28 self.
_axes = dict(x=4, y=3, z=1,
29 roll=2, pitch=5, yaw=0,
30 xfast=-1, yfast=-1, zfast=-1,
31 rollfast=-1, pitchfast=-1, yawfast=-1)
35 roll=0.5, pitch=0.5, yaw=0.5,
36 xfast=6, yfast=6, zfast=1,
37 rollfast=2, pitchfast=2, yawfast=2)
39 if rospy.has_param(
'~mapping'):
40 mapping = rospy.get_param(
'~mapping')
41 for tag
in self.
_axes:
42 if tag
not in mapping:
43 rospy.loginfo(
'Tag not found in axes mapping, ' 46 if 'axis' in mapping[tag]:
47 self.
_axes[tag] = mapping[tag][
'axis']
48 if 'gain' in mapping[tag]:
54 if rospy.has_param(
'~deadzone'):
55 self.
_deadzone = float(rospy.get_param(
'~deadzone'))
59 if rospy.has_param(
'~deadman_button'):
63 if rospy.has_param(
'~exclusion_buttons'):
69 if type(n)
not in [float, int]:
70 raise rospy.ROSException(
71 'Exclusion buttons must be an integer index to ' 72 'the joystick button')
78 if rospy.has_param(
'~home_button'):
82 if rospy.has_param(
'~type'):
84 if self.
_msg_type not in [
'twist',
'accel']:
85 raise rospy.ROSException(
'Teleoperation output must be either ' 89 self.
_output_pub = rospy.Publisher(
'output', Twist, queue_size=1)
91 self.
_output_pub = rospy.Publisher(
'output', Accel, queue_size=1)
94 'home_pressed', Bool, queue_size=1)
100 while not rospy.is_shutdown():
142 if self.
_axes[
'pitchfast'] > -1
and abs(joy.axes[self.
_axes[
'pitchfast']]) > self.
_deadzone:
143 a.y += self.
_axes_gain[
'pitchfast'] * joy.axes[self.
_axes[
'pitchfast']]
154 cmd.linear = Vector3(0, 0, 0)
155 cmd.angular = Vector3(0, 0, 0)
162 if joy.buttons[n] == 1:
164 self._output_pub.publish(cmd)
174 self._output_pub.publish(cmd)
175 self._home_pressed_pub.publish(
177 except Exception
as e:
178 print(
'Error occurred while parsing joystick input,' 179 ' check if the joy_id corresponds to the joystick ' 180 'being used. message={}'.format(e))
182 if __name__ ==
'__main__':
184 node_name = os.path.splitext(os.path.basename(__file__))[0]
185 rospy.init_node(node_name)
186 rospy.loginfo(
'Starting [%s] node' % node_name)
191 rospy.loginfo(
'Shutting down [%s] node' % node_name)
def _joy_callback(self, joy)
def _parse_joy(self, joy=None)