rov_pd_grav_compensation_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 DPControllerBase
19 
20 
21 class ROV_PD_GComp_Controller(DPControllerBase):
22  """
23  PD controller with compensation of restoring forces for the dynamic
24  positioning of ROVs.
25  """
26 
27  _LABEL = 'PD controller with compensation of restoring forces'
28  def __init__(self):
29  # Start the super class
30  DPControllerBase.__init__(self, is_model_based=True)
31  self._logger.info('Initializing: ' + self._LABEL)
32  # Proportional gains
33  self._Kp = np.zeros(shape=(6, 6))
34  # Derivative gains
35  self._Kd = np.zeros(shape=(6, 6))
36  # Error for the vehicle pose
37  self._error_pose = np.zeros(6)
38 
39  self._tau = np.zeros(6)
40 
41  if rospy.has_param('~Kp'):
42  Kp_diag = rospy.get_param('~Kp')
43  if len(Kp_diag) == 6:
44  self._Kp = np.diag(Kp_diag)
45  else:
46  raise rospy.ROSException('Kp matrix error: 6 coefficients '
47  'needed')
48 
49  self._logger.info('Kp=' + str([self._Kp[i, i] for i in range(6)]))
50 
51  if rospy.has_param('~Kd'):
52  Kd_diag = rospy.get_param('~Kd')
53  if len(Kd_diag) == 6:
54  self._Kd = np.diag(Kd_diag)
55  else:
56  raise rospy.ROSException('Kd matrix error: 6 coefficients '
57  'needed')
58 
59  self._logger.info('Kd=' + str([self._Kd[i, i] for i in range(6)]))
60 
61  self._is_init = True
62  self._logger.info(self._LABEL + ' ready')
63 
64  def _reset_controller(self):
65  super(DPControllerBase, self)._reset_controller()
66  self._error_pose = np.zeros(6)
67 
68  def update_controller(self):
69  if not self._is_init:
70  return False
71 
72  self._vehicle_model._update_restoring(use_sname=True)
73 
74  self._tau = np.dot(self._Kp, self.error_pose_euler) \
75  + np.dot(self._Kd, self._errors['vel']) \
76  + self._vehicle_model.restoring_forces
77 
78  self.publish_control_wrench(self._tau)
79 
80 if __name__ == '__main__':
81  print('Starting PD controller with compensation of restoring forces')
82  rospy.init_node('rov_pd_grav_compensation_controller')
83 
84  try:
86  rospy.spin()
87  except rospy.ROSInterruptException:
88  print('caught exception')
89  print('exiting')


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