## 2 Materials and Methods
### NMPC with PSO Solver  
An NMPC controller with a PSO metaheuristic algorithm as the solver of the constrained optimal control problem was developed, implemented, and tested in real-time experiments on a laboratory stand. PSO is a stochastic optimization technique that was originally developed by [PERSON] and [PERSON] [49]. There have been several variations of the PSO algorithm, including utilizing different topologies, such as the star topology, which uses the swarm's global best position, or the ring topology, in which a particle uses the local best position in its neighborhood. While the original PSO formulation used the star topology, it has been proposed to use the ring topology and limit the star topology to unimodal problems; however, according to [50], the star topology is still acceptable for multi-objective optimization problems. An empirical study by [PERSON] [51] on 60 benchmark functions showed that the two topologies perform similarly, with the star topology performing slightly better in terms of success rate and efficiency, while the ring topology performed slightly better in terms of consistency. Additionally, PSO variants with sub-swarm populations have been proposed, such as dynamic multi-swarm PSO [52] and symbiotic particle swarm optimization [53]. A review of the different PSO variants is presented in [54]. In the proposed control scheme, at each time step, \(k\), the NMPC-GP receives the current state of the plant and solves the constrained optimization problem to find a sequence of control actions \(u(k+i-1)\) defined over the control horizon \(N_{u}\) to minimize the cost function, which depends on the deviation of the process variables \(x(k+i)\) and \(\alpha(k+i)\) from the set point \(x_{r}(k+i)\) as well as the control effort required to change the system states over the prediction horizon \(N_{p}\). The PSO algorithm solves the optimization problem with the constraint \(u(k+i+1)\in\mathbb{U}\) directly as one large optimization problem, and, therefore, there is no requirement for breaking down the problem into smaller subproblems as is the case with dynamic programming. The future trajectories of the states are predicted using (3-5) based on measurements at the current time instant \(k\) and the candidate control sequence \(u(k+i+1)\) obtained iteratively using the PSO algorithm (Figure 2). The proposed cost function includes the sum of the squared prediction errors between the desired and predicted crane positions on the prediction horizon, which corresponds to shifting the equilibrium to the desired position; the sum of the weighted squares of the  
Figure 2: NMPC-GP scheme. predicted payload angle on the prediction horizon; and the weighted squares of the control increments on the control horizon, as given in  
\[J(k+i)=\sum_{i=1}^{N_{p}}\lambda_{1}(e(k+i))^{2}+\sum_{i=1}^{N_{p}}\lambda_{2}( \alpha(k+1))^{2}+\sum_{i=1}^{N_{n}}\lambda_{3}(\Delta u(k+i-1))^{2} \tag{15}\]  
where  
\(e(k+i)=x(k+i)-x_{r}(k+i)\),  
\(\Delta u(k+i-1)=u(k+i-1)-u(k+i-2)\),  
\(\lambda_{1}= \begin{cases}0&if\ |e(k+i)|\leq e_{a}\\ 1&if\ |e(k+i)|>e_{a}\\ \end{cases} \),  
\(\lambda_{2}= \begin{cases}0&if|\alpha(k+i)|\leq a_{a}\\ \lambda_{20}&if|\alpha(k+i)|>\alpha_{a}\\ \end{cases} \). The position error, \(e(k+i)\), is the difference between the predicted position \(x(k+i)\) and the reference signal \(x_{r}\) at time \(k+i\); \(\alpha(k+i)\) is the predicted sway angle of the payload; \(\Delta u(k+i-1)\) expresses the control effort, which is calculated as the predicted change in the control signal along the control horizon; and \(\lambda_{1}\), \(\lambda_{2}\), and \(\lambda_{3}\) are the weighting coefficients.