rov_mb_fl_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 
17 import rospy
18 import numpy as np
19 from uuv_control_interfaces import DPPIDControllerBase
20 from uuv_control_msgs.srv import *
21 
22 class ROV_MBFLController(DPPIDControllerBase):
23  """
24  Modelbased Feedback Linearization Controller
25  Reference:
26  Thor I. Fossen 2011
27  Handbook of Marine Craft Hydrodynamics and Motion Control
28  """
29  _LABEL = 'Model-based Feedback Linearization Controller'
30 
31  def __init__(self):
32  DPPIDControllerBase.__init__(self, True)
33  self._logger.info('Initializing: ' + self._LABEL)
34 
35  # Control forces and torques
36  self._tau = np.zeros(6)
37  # PID control vector
38  self._pid_control = np.zeros(6)
39  self._is_init = True
40  self._last_vel = np.zeros(6)
41  self._last_t = None
42  self._logger.info(self._LABEL + ' ready')
43 
44  def _reset_controller(self):
45  super(ROV_MBFLController, self).reset_controller()
46  self._pid_control = np.zeros(6)
47  self._tau = np.zeros(6)
48 
49  def update_controller(self):
50  if not self._is_init:
51  return False
52 
53  t = rospy.get_time()
54  if self._last_t is None:
55  self._last_t = t
56  self._last_vel = self._vehicle_model.to_SNAME(self._reference['vel'])
57  return False
58 
59  dt = t - self._last_t
60  if dt <= 0:
61  self._last_t = t
62  self._last_vel = self._vehicle_model.to_SNAME(self._reference['vel'])
63  return False
64  self._pid_control = self.update_pid()
65 
66 
67  vel = self._vehicle_model.to_SNAME(self._reference['vel'])
68  acc = (vel - self._last_vel) / dt
69 
70  self._vehicle_model._update_damping(vel)
71  self._vehicle_model._update_coriolis(vel)
72  self._vehicle_model._update_restoring(q=self._reference['rot'], use_sname=True)
73 
74  self._tau = np.dot(self._vehicle_model.Mtotal, acc) + \
75  np.dot(self._vehicle_model.Ctotal, vel) + \
76  np.dot(self._vehicle_model.Dtotal, vel) + \
77  self._vehicle_model.restoring_forces
78 
79  # Publish control forces and torques
80  self.publish_control_wrench(self._pid_control + self._vehicle_model.from_SNAME(self._tau))
81  self._last_t = t
82  self._last_vel = self._vehicle_model.to_SNAME(self._reference['vel'])
83  return True
84 
85 
86 if __name__ == '__main__':
87  print('Starting Modelbased Feedback Linearization Controller')
88  rospy.init_node('rov_mb_fl_controller')
89 
90  try:
92  rospy.spin()
93  except rospy.ROSInterruptException:
94  print('caught exception')
95  print('exiting')


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