24 This is an abstract class for PID-based controllers. The base class method 25 update_controller must be overridden in other for a controller to work. 30 DPControllerBase.__init__(self, *args)
31 self._logger.info(
'Initializing: Underactuated PID controller')
33 self.
_Kp = np.zeros(shape=(4, 4))
35 self.
_Kd = np.zeros(shape=(4, 4))
37 self.
_Ki = np.zeros(shape=(4, 4))
43 if rospy.has_param(
'~Kp'):
44 Kp_diag = rospy.get_param(
'~Kp')
46 self.
_Kp = np.diag(Kp_diag)
48 raise rospy.ROSException(
'Kp matrix error: 4 coefficients ' 51 self._logger.info(
'Kp=' + str([self.
_Kp[i, i]
for i
in range(4)]))
53 if rospy.has_param(
'~Kd'):
54 Kd_diag = rospy.get_param(
'~Kd')
56 self.
_Kd = np.diag(Kd_diag)
58 raise rospy.ROSException(
'Kd matrix error: 4 coefficients ' 61 self._logger.info(
'Kd=' + str([self.
_Kd[i, i]
for i
in range(4)]))
63 if rospy.has_param(
'~Ki'):
64 Ki_diag = rospy.get_param(
'~Ki')
66 self.
_Ki = np.diag(Ki_diag)
68 raise rospy.ROSException(
'Ki matrix error: 4 coefficients ' 71 self._logger.info(
'Ki=' + str([self.
_Ki[i, i]
for i
in range(4)]))
73 self.
_services[
'set_pid_params'] = rospy.Service(
77 self.
_services[
'get_pid_params'] = rospy.Service(
83 self._logger.info(
'Underactuated PID controller ready!')
88 self.
_int = np.zeros(4)
94 if len(kp) != 4
or len(kd) != 4
or len(ki) != 4:
95 return SetPIDParamsResponse(
False)
96 self.
_Kp = np.diag(kp)
97 self.
_Ki = np.diag(ki)
98 self.
_Kd = np.diag(kd)
99 return SetPIDParamsResponse(
True)
102 return GetPIDParamsResponse(
103 [self.
_Kp[i, i]
for i
in range(4)],
104 [self.
_Kd[i, i]
for i
in range(4)],
105 [self.
_Ki[i, i]
for i
in range(4)])
120 error_vel = np.array([self.
_errors[
'vel'][0],
124 ua_tau = np.dot(self.
_Kp, cur_error_pose) \
125 + np.dot(self.
_Kd, error_vel) \
127 self.
_tau = np.array([ua_tau[0], ua_tau[1], ua_tau[2], 0, 0, ua_tau[3]])
131 if __name__ ==
'__main__':
132 print(
'Starting Underactuated PID Controller')
133 rospy.init_node(
'rov_ua_pid_controller')
138 except rospy.ROSInterruptException:
139 print(
'caught exception')
def _reset_controller(self)
def update_controller(self)
def get_pid_params_callback(self, request)
def publish_control_wrench(self, force)
def error_pose_euler(self)
def set_pid_params_callback(self, request)