Control
The MCSimPython.control package contains a set of DP and Maneuvering controllers.
Basic Controllers
The module contains simple PD and PID controllers.
PD Controller
- class MCSimPython.control.basic.PD(kp: list, kd: list)
Proportional-Derivative controller.
- get_tau(eta, eta_d, nu, nu_d)
Calculate control loads.
- Parameters:
eta (array_like) – Vessel pose in surge, sway and yaw.
eta_d (array_like) – Desired vessel pose in surge, sway and yaw (NED-frame).
nu (array_like) – Vessel velocity in surge, sway, and yaw (body-frame).
nu_d (array_like) – Desired vessel velocity in surge, sway and yaw (body-frame).
- Returns:
tau – Controller load in surge, sway, and yaw (body-frame).
- Return type:
array_like
- set_kd(kd: list)
Set the derivative gain coefficients.
- set_kp(kp: list)
Set the proportional gain coefficients.
PID Controller
- class MCSimPython.control.basic.PID(kp: list, kd: list, ki: list, dt: float = 0.01)
Proportional-Derivative control with integral action.
- get_tau(eta, eta_d, nu, nu_d)
Calculate control loads.
- Parameters:
eta (array_like) – Vessel pose in surge, sway and yaw.
eta_d (array_like) – Desired vessel pose in surge, sway and yaw (NED-frame).
nu (array_like) – Vessel velocity in surge, sway, and yaw (body-frame).
nu_d (array_like) – Desired vessel velocity in surge, sway and yaw (body-frame).
- Returns:
tau – Controller load in surge, sway, and yaw (body-frame).
- Return type:
array_like
PI Controller
- class MCSimPython.control.basic.PI(kp: list, ki: list, dt: float = 0.01)
Proportional control with integral action.
- get_tau(eta, eta_d)
Calculate control loads.
- Parameters:
eta (array_like) – Vessel pose in surge, sway and yaw.
eta_d (array_like) – Desired vessel pose in surge, sway and yaw (NED-frame).
- Returns:
tau – Controller load in surge, sway, and yaw (body-frame).
- Return type:
array_like
Direct Bias Compensation Controller
- class MCSimPython.control.basic.DirectBiasCompensationController(kp: list, kd: list)
Bias estimate provided from the observer as direct compensation in a nominal PD control law.
- get_tau(eta, eta_d, nu, nu_d, b)
- Parameters:
eta (array_like) – Vessel pose in surge, sway and yaw.
eta_d (array_like) – Desired vessel pose in surge, sway and yaw (NED-frame).
nu (array_like) – Vessel velocity in surge, sway, and yaw (body-frame).
nu_d (array_like) – Desired vessel velocity in surge, sway and yaw (body-frame).
b (array_like) – Estimated bias in surge, sway and yaw (body-frame)
Note
The bias term b is defined in body-frame.
Adaptive Controller
- class MCSimPython.control.adaptiveFS.AdaptiveFSController(dt, M, D, N=15)
Adaptive controller using a truncated Fourier series-based internal disturbance model in a “Model Reference Adaptive Control” (MRAC). The control law is determined by using LgV-backstepping, based on calculations and procedures done in (Fossen, 2021) and (Brørby, 2022).
- To be implemented:
Improved tuning.
- get_regressor(t)
Extract a (2*N+1)-dimensional regressor defined as [1 cos(w1*t) sin(w1*t) cos(w2*t) … sin(wN*t)]. Used in get_tau() to calculate control forces.
- Parameters:
t (float) – Time
- Returns:
regressor – (2N + 1) dimensional, time-dependent vector as defined above
- Return type:
array_like
- get_tau(eta, eta_d, nu, eta_d_dot, eta_d_ddot, t, calculate_bias=False)
Calculate controller output based on the adaptive update law.
- Parameters:
eta (array_like) – [surge, sway, yaw] expressed in NED
eta_d (array_like) – Desired position expressed in NED
nu (array_like) – [u, v, r] expressed in body
eta_d_dot (array_like) – Desired velocity expressed in NED
eta_d_ddot (array_like) – Desired acceleration expressed in NED
t (float) – Time
Calculate_bias (bool) – Function will also return estimated bias if True. Set to False as default.
Output –
------------ –
tau (3DOF): Calculated control forces
b_hat (3DOF): Estimated bias in surge, sway, yaw. Only returned if “calculate_bias == True”
- set_freqs(w_min, w_max, N)
Customize the number and magnitude of wave frequencies to be included in the internal disturbance model.
UNIT IN RAD/S OR HZ?
- Parameters:
w_min (float) – Lower bound frequency
w_max (float) – Upper bound frequency
N (int) – Number of components
Backstepping Controllers
In the MCSimPython.control.backstepping module there are controllers based on backstepping
theory. Currently, only a backstepping controller for maneuvering purposes has been implemented.
- class MCSimPython.control.backstepping.BacksteppingController(M, D, K1, K2)
Backsteppipng controller for maneuvering.
The controller should be used together with a path parameterization guidance/reference model.
See also
MCSimPython.guidance.path_parm.WayPointPathParamWay-points path parameterization.
- control_law(z1, z2, alpha, alpha_dot, nu)
Complete control law.
- error_pos(eta, eta_d)
Deviation from desired pose in body-frame.
- error_vel(nu, alpha)
Deviation from virtual control law.
- lyapunov_grad_s(z1, eta, eta_d_s)
Lyapunov function gradient.
- u(eta, nu, eta_d, eta_d_s, eta_d_s2, mu, u_s, u_s_dot, ddt_u_s)
Control command.
- unit_gradient_update_law(u_s, mu, eta_d_s, lyapunov_gradient)
Unit-tangent gradient update law for path parameter (s).
- virtual_control_dot(z1, z2, alpha, eta, eta_d, eta_d_s, eta_d_s2, u_s, u_s_dot, nu, s_dot, ddt_u_s)
Time derivative of virtual control law (alpha_dot).
- virtual_control_law(z1, eta, eta_d_s, u_s)
Virtual control law (alpha).