thruster.py
Go to the documentation of this file.
1 # Copyright (c) 2016 The UUV Simulator Authors.
2 # All rights reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import rospy
17 import numpy
18 import tf.transformations as trans
19 from uuv_gazebo_ros_plugins_msgs.msg import FloatStamped
20 from std_msgs.msg import Header
21 
22 
23 class Thruster(object):
24  """Abstract function to all the thruster models avaialble. The instance
25  of a thruster model must use the factory method."""
26 
27  LABEL = ''
28  DEFAULT_AXIS=numpy.array([1, 0, 0, 0])
29 
30  def __init__(self, index, topic, pos, orientation, axis=DEFAULT_AXIS):
31  """Thruster class constructor.
32 
33  Parameters
34  ----------
35  index: int
36  Thruster's index.
37  topic: str
38  Name of the thruster's command topic.
39  pos: numpy.array
40  3D position of the thruster with relation to the reference frame.
41  orientation: numpy.array
42  Quaternion with the orientation of the thruster with relation to
43  the reference frame.
44  """
45  self._index = index
46  self._topic = topic
47  self._pos = None
48  self._orientation = None
49  self._force_dist = None
50  if pos is not None and orientation is not None:
51  self._pos = pos
52  self._orientation = orientation
53  # compute contribution to configuration matrix of this thruster
54  thrust_body = trans.quaternion_matrix(orientation).dot(
55  axis.transpose())[0:3]
56  torque_body = numpy.cross(pos, thrust_body)
57  self._force_dist = numpy.hstack((
58  thrust_body, torque_body)).transpose()
59  self._command = 0
60  self._thrust = 0
61  self._command_pub = rospy.Publisher(self._topic, FloatStamped,
62  queue_size=10)
63 
64  print 'Thruster #%d - %s - %s' % (self._index, self.LABEL, self._topic)
65 
66  @property
67  def tam_column(self):
68  return self._force_dist
69 
70  @staticmethod
71  def create_thruster(model_name, *args, **kwargs):
72  for thruster in Thruster.__subclasses__():
73  if model_name == thruster.LABEL:
74  return thruster(*args, **kwargs)
75  rospy.ROSException('Invalid thruster model')
76 
77  def get_command_value(self, thrust):
78  """Convert desired thrust force to input command according to this
79  function. Overwrite this method to implement custom models."""
80  return 0
81 
82  def get_thrust_value(self, command):
83  """Computes the thrust force for the given command."""
84  return 0
85 
86  def get_curve(self, min_value, max_value, n_points):
87  """Sample the conversion curve and return the values."""
88  if min_value >= max_value or n_points <= 0:
89  return [], []
90  input_values = numpy.linspace(min_value, max_value, n_points)
91  output_values = []
92  for value in input_values:
93  output_values.append(self.get_thrust_value(value))
94  return input_values.tolist(), output_values
95 
96  def _calc_command(self):
97  """Convert the desired thrust force into angular velocity command
98  according using a gain."""
99  self._command = self.get_command_value(self._thrust)
100 
101  def _update(self, thrust):
102  self._thrust = thrust
103  self._calc_command()
104 
105  def publish_command(self, thrust):
106  self._update(thrust)
107  output = FloatStamped()
108  output.header.stamp = rospy.Time.now()
109  output.data = self._command
110  self._command_pub.publish(output)
def get_curve(self, min_value, max_value, n_points)
Definition: thruster.py:86
def create_thruster(model_name, args, kwargs)
Definition: thruster.py:71
def get_thrust_value(self, command)
Definition: thruster.py:82
def __init__(self, index, topic, pos, orientation, axis=DEFAULT_AXIS)
Definition: thruster.py:30
def get_command_value(self, thrust)
Definition: thruster.py:77


uuv_thruster_manager
Author(s): Musa Morena Marcusso Manhaes , Sebastian Scherer , Luiz Ricardo Douat
autogenerated on Mon Jul 1 2019 19:39:26