16 from __future__
import print_function
19 from uuv_control_interfaces
import DPControllerBase
24 _LABEL =
'Model-based Sliding Mode Controller' 27 DPControllerBase.__init__(self,
True)
28 self._logger.info(
'Initializing: ' + self.
_LABEL)
48 if rospy.has_param(
'~lambda'):
49 coefs = rospy.get_param(
'~lambda')
53 raise rospy.ROSException(
'lambda coefficients: 6 coefficients ' 57 if rospy.has_param(
'~rho_constant'):
58 coefs = rospy.get_param(
'~rho_constant')
62 raise rospy.ROSException(
'rho_constant coefficients: 6 coefficients ' 66 if rospy.has_param(
'~k'):
67 coefs = rospy.get_param(
'~k')
69 self.
_k = np.array(coefs)
71 raise rospy.ROSException(
'k coefficients: 6 coefficients ' 75 if rospy.has_param(
'~c'):
76 coefs = rospy.get_param(
'~c')
78 self.
_c = np.array(coefs)
80 raise rospy.ROSException(
'c coefficients: 6 coefficients ' 84 if rospy.has_param(
'~adapt_slope'):
85 coefs = rospy.get_param(
'~adapt_slope')
89 raise rospy.ROSException(
'adapt_slope coefficients: 6 coefficients ' 93 if rospy.has_param(
'~rho_0'):
94 coefs = rospy.get_param(
'~rho_0')
96 self.
_rho_0 = np.array(coefs)
98 raise rospy.ROSException(
'rho_0 coefficients: 6 coefficients ' 100 print(
'rho_0=', self.
_rho_0)
102 if rospy.has_param(
'~drift_prevent'):
103 scalar = rospy.get_param(
'~drift_prevent')
104 if not isinstance(scalar, list):
107 raise rospy.ROSException(
'drift_prevent needs to be a scalar value')
112 if rospy.has_param(
'~enable_integral_term'):
119 if rospy.has_param(
'~adaptive_bounds'):
126 if rospy.has_param(
'~constant_bound'):
132 if rospy.has_param(
'~ctrl_eq'):
138 if rospy.has_param(
'~ctrl_lin'):
144 if rospy.has_param(
'~ctrl_robust'):
175 self._services[
'set_mb_sm_controller_params'] = rospy.Service(
176 'set_mb_sm_controller_params',
177 SetMBSMControllerParams,
180 self._services[
'get_mb_sm_controller_params'] = rospy.Service(
181 'get_mb_sm_controller_params',
182 GetMBSMControllerParams,
185 self._logger.info(self.
_LABEL +
' ready')
196 self.
_int = np.zeros(6)
198 self.
_s_b = np.zeros(6)
205 self.
_f_eq = np.zeros(6)
208 self.
_tau = np.zeros(6)
211 return SetMBSMControllerParamsResponse(
True)
214 return GetMBSMControllerParamsResponse(
215 self._lambda.tolist(),
216 self._rho_constant.tolist(),
219 self._adapt_slope.tolist(),
220 self._rho_0.tolist(),
226 t = rospy.Time.now().to_sec()
233 self.
_int += 0.5 * (self.error_pose_euler - self.
_error_pose) * self._dt
238 e_p_linear_b = self._errors[
'pos']
239 e_v_linear_b = self._errors[
'vel'][0:3]
241 e_p_angular_b = self.error_orientation_rpy
242 e_v_angular_b = self._errors[
'vel'][3:6]
244 e_p_b = np.hstack((e_p_linear_b, e_p_angular_b))
245 e_v_b = np.hstack((e_v_linear_b, e_v_angular_b))
248 self.
_s_b = -e_v_b - np.multiply(self.
_lambda, e_p_b) \
254 self._vehicle_model.rotItoB, (self._reference[
'acc'][0:3] - \
255 np.dot(self.
_rotBtoI_dot, self._vehicle_model._vel[0:3]))) + \
256 np.multiply(self.
_lambda[0:3], e_v_linear_b) + \
259 np.dot(self.
_rotBtoI_dot, self._vehicle_model._vel[3:6]))) + \
260 np.multiply(self.
_lambda[3:6], e_v_angular_b) + \
267 self.
_f_eq = self._vehicle_model.compute_force(acc, use_sname=
False)
278 (self.
_adapt_slope[1] * np.abs(self.
_s_b) * np.abs(e_p_b) * np.abs(e_p_b)) +
279 (self.
_adapt_slope[2] * np.abs(self.
_s_b) * np.abs(e_v_b) * np.abs(e_v_b)) +
288 self.publish_control_wrench(self.
_tau)
292 if __name__ ==
'__main__':
293 print(
'Starting Model-based Sliding Mode Controller')
294 rospy.init_node(
'rov_mb_sm_controller')
299 except rospy.ROSInterruptException:
300 print(
'caught exception')
_accel_angular_estimate_b
def get_mb_sm_controller_params_callback(self, request)
def update_controller(self)
def _reset_controller(self)
def set_mb_sm_controller_params_callback(self, request)
def cross_product_operator(x)