rov_nl_pid_controller.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (c) 2016-2019 The UUV Simulator Authors.
3 # All rights reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 import rospy
17 import numpy as np
18 from uuv_control_interfaces import DPPIDControllerBase
19 from geometry_msgs.msg import Wrench, Vector3
20 from tf_quaternion.transformations import quaternion_matrix
21 
22 
23 class ROV_NLPIDController(DPPIDControllerBase):
24  """MIMO Nonlinear PID controller with acceleration feedback for the dynamic
25  positioning of underwater vehicles.
26 
27  References
28  ----------
29 
30  - Fossen, Thor I. Handbook of Marine Craft Hydrodynamics and Motion
31  Control (April 8, 2011).
32  """
33 
34  _LABEL = 'MIMO Nonlinear PID Controller with Acceleration Feedback'
35 
36  def __init__(self):
37  DPPIDControllerBase.__init__(self, True)
38  self._logger.info('Initializing: ' + self._LABEL)
39  # Feedback acceleration gain
40  self._Hm = np.eye(6)
41  if rospy.has_param('Hm'):
42  hm = rospy.get_param('Hm')
43  if len(hm) == 6:
44  self._Hm = self._vehicle_model.Mtotal + np.diag(hm)
45  else:
46  raise rospy.ROSException('Invalid feedback acceleration gain coefficients')
47 
48  self._tau = np.zeros(6)
49  # Acceleration feedback term
50  self._accel_ff = np.zeros(6)
51  # PID control vector
52  self._pid_control = np.zeros(6)
53  self._is_init = True
54  self._logger.info(self._LABEL + ' ready')
55 
56  def _reset_controller(self):
57  super(ROV_NLPIDController, self)._reset_controller()
58  self._accel_ff = np.zeros(6)
59  self._pid_control = np.zeros(6)
60 
61  def update_controller(self):
62  if not self._is_init:
63  return False
64  # Calculating the feedback acceleration vector for the control forces
65  # from last iteration
66  acc = self._vehicle_model.compute_acc(
67  self._vehicle_model.to_SNAME(self._tau), use_sname=False)
68  self._accel_ff = np.dot(self._Hm, acc)
69  # Update PID control action
70  self._pid_control = self.update_pid()
71  # Publish control forces and torques
72  self._tau = self._pid_control - self._accel_ff + \
73  self._vehicle_model.restoring_forces
74  self.publish_control_wrench(self._tau)
75  return True
76 
77 
78 if __name__ == '__main__':
79  rospy.init_node('rov_nl_pid_controller')
80 
81  try:
83  rospy.spin()
84  except rospy.ROSInterruptException:
85  print('caught exception')
86  print('exiting')


uuv_trajectory_control
Author(s):
autogenerated on Thu Jun 18 2020 03:28:42