16 from __future__
import print_function
20 import tf.transformations
as trans
21 from os.path
import isdir, join
22 from copy
import deepcopy
25 from uuv_thrusters
import ThrusterManager
26 from geometry_msgs.msg
import Wrench, WrenchStamped
31 """The thruster allocator node allows a client node 32 to command the thrusters. 36 """Class constructor.""" 37 ThrusterManager.__init__(self)
42 self.
input_sub = rospy.Subscriber(
'thruster_manager/input',
49 'thruster_manager/input_stamped', WrenchStamped,
52 'thruster_manager/get_thrusters_info', ThrusterManagerInfo,
55 'thruster_manager/get_thruster_curve', GetThrusterCurve,
58 'thruster_manager/set_config', SetThrusterManagerConfig,
61 'thruster_manager/get_config', GetThrusterManagerConfig,
64 rate = rospy.Rate(self.
config[
'update_rate'])
65 while not rospy.is_shutdown():
66 if self.
config[
'timeout'] > 0:
70 print(
'Turning thrusters off - inactive for too long')
71 if self.thrust
is not None:
73 self.command_thrusters()
77 """Return service callback with thruster information.""" 78 return ThrusterManagerInfoResponse(
80 self.configuration_matrix.flatten().tolist(),
81 self.namespace + self.
config[
'base_link'])
84 """Return service callback for computation of thruster curve.""" 86 return GetThrusterCurveResponse([], [])
89 input_values, thrust_values = self.thrusters[0].get_curve(
90 request.min, request.max, request.n_points)
91 return GetThrusterCurveResponse(input_values, thrust_values)
94 old_config = deepcopy(self.
config)
96 self.
config[
'base_link'] = request.base_link
97 self.
config[
'thruster_frame_base'] = request.thruster_frame_base
98 self.
config[
'thruster_topic_prefix'] = request.thruster_topic_prefix
99 self.
config[
'thruster_topic_suffix'] = request.thruster_topic_suffix
100 self.
config[
'timeout'] = request.timeout
101 print(
'New configuration:\n')
103 print(key,
'=', self.
config[key])
104 if not self.update_tam(recalculate=
True):
105 print(
'Configuration parameters are invalid, going back to old configuration...')
107 self.update_tam(recalculate=
True)
108 return SetThrusterManagerConfigResponse(
True)
111 return GetThrusterManagerConfigResponse(
114 self.
config[
'thruster_frame_base'],
115 self.
config[
'thruster_topic_prefix'],
116 self.
config[
'thruster_topic_suffix'],
118 self.
config[
'max_thrust'],
120 self.configuration_matrix.flatten().tolist())
124 Callback to the subscriber that receiver the wrench to be applied on 126 @param msg Wrench message 131 force = numpy.array((msg.force.x, msg.force.y, msg.force.z))
132 torque = numpy.array((msg.torque.x, msg.torque.y, msg.torque.z))
136 self.publish_thrust_forces(force, torque)
142 Callback to the subscriber that receiver the stamped wrench to be 143 applied on UUV's BODY frame. 144 @param msg Stamped wrench message 150 (msg.wrench.force.x, msg.wrench.force.y, msg.wrench.force.z))
151 torque = numpy.array(
152 (msg.wrench.torque.x, msg.wrench.torque.y, msg.wrench.torque.z))
155 self.publish_thrust_forces(force, torque, msg.header.frame_id.split(
'/')[-1])
159 if __name__ ==
'__main__':
160 rospy.init_node(
'thruster_allocator')
165 except rospy.ROSInterruptException:
166 print(
'ThrusterAllocatorNode::Exception')
167 print(
'Leaving ThrusterAllocatorNode')
def set_config(self, request)
get_thruster_manager_config_service
def input_stamped_callback(self, msg)
def get_thruster_info(self, request)
def get_config(self, request)
def input_callback(self, msg)
set_thruster_manager_config_service
def get_thruster_curve(self, request)