16 from __future__
import print_function
20 import tf.transformations
as trans
22 from sensor_msgs.msg
import Joy
23 from uuv_gazebo_ros_plugins_msgs.msg
import FloatStamped
25 from rospy.numpy_msg
import numpy_msg
30 print(
'FinnedUUVControllerNode: initializing node')
35 param_labels = [
'n_fins',
'gain_roll',
'gain_pitch',
'gain_yaw',
36 'thruster_model',
'fin_topic_prefix',
37 'fin_topic_suffix',
'thruster_topic',
38 'axis_thruster',
'axis_roll',
'axis_pitch',
'axis_yaw']
40 for label
in param_labels:
41 if not rospy.has_param(
'~%s' % label):
42 raise rospy.ROSException(
'Parameter missing, label=%s' % label)
49 if rospy.has_param(
'~thruster_joy_gain'):
54 gain_roll = rospy.get_param(
'~gain_roll')
55 gain_pitch = rospy.get_param(
'~gain_pitch')
56 gain_yaw = rospy.get_param(
'~gain_yaw')
58 if len(gain_roll) != self.
_n_fins or len(gain_pitch) != self.
_n_fins \
59 or len(gain_yaw) != self.
_n_fins:
60 raise rospy.ROSException(
'Input gain vectors must have length ' 61 'equal to the number of fins')
64 self.
_rpy_to_fins = numpy.vstack((gain_roll, gain_pitch, gain_yaw)).T
67 self.
_joy_axis = dict(axis_thruster=rospy.get_param(
'~axis_thruster'),
68 axis_roll=rospy.get_param(
'~axis_roll'),
69 axis_pitch=rospy.get_param(
'~axis_pitch'),
70 axis_yaw=rospy.get_param(
'~axis_yaw'))
79 rospy.Publisher(topic, FloatStamped, queue_size=10))
86 raise rospy.ROSException(
'No limit to thruster output was given')
92 raise rospy.ROSException(
'Thruster model could not be initialized')
95 self.
sub_joy = rospy.Subscriber(
'joy', numpy_msg(Joy),
101 """Handle callbacks with joystick state.""" 107 thrust = max(0, msg.axes[self.
_joy_axis[
'axis_thruster']]) * \
111 cmd_roll = msg.axes[self.
_joy_axis[
'axis_roll']]
112 if abs(cmd_roll) < 0.2:
115 cmd_pitch = msg.axes[self.
_joy_axis[
'axis_pitch']]
116 if abs(cmd_pitch) < 0.2:
119 cmd_yaw = msg.axes[self.
_joy_axis[
'axis_yaw']]
120 if abs(cmd_yaw) < 0.2:
123 rpy = numpy.array([cmd_roll, cmd_pitch, cmd_yaw])
124 fins = self._rpy_to_fins.dot(rpy)
126 self._thruster_model.publish_command(thrust)
135 except Exception
as e:
136 print(
'Error occurred while parsing joystick input, check ' 137 'if the joy_id corresponds to the joystick ' 138 'being used. message={}'.format(e))
141 if __name__ ==
'__main__':
142 print(
'starting FinnedUUVControllerNode.py')
143 rospy.init_node(
'finned_uuv_teleop')
148 except rospy.ROSInterruptException:
149 print(
'caught exception')
def joy_callback(self, msg)