- This project gives an example, which can be modified by users.
- Every block during option start and option end should be modified by users according to the actual situation, where contains printing options and necessary parameters.
- Need to pre install dependency
Eigen
:
sudo apt-get install libeigen3-dev
sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen
- Need to pre install dependency
OSQP-0.4.1
, which can be get from:
OSQP - Provide simple parameter type checking function.
- The discrete form of the state space equation should be given by users, this project does not provide form transformation function similar to that in project DLQR.
- In
main
function, a loop is used to simulate the normal operation of a classical 1-dim position-velocity-acceleration system, the period of sampling is set to0.5
and the number of iterations is20
.
-
Specific derivation process can be seen in Appendix A, all variables' names are the same as those in the code.
-
Prediction time domain
horizon
of MPC is set to 3, so the weight matricesH
nadg
are simply formatted as identity matrices as follows:
$$\boldsymbol{H} = \boldsymbol{1}{6\times6}$$ $$\boldsymbol{g} = \boldsymbol{1}{3\times3}$$ -
The test result is as the follow figure, as the time going, the pos in blue converge to
5
from the initial state2
and the vel in red converge to0
from the initial state0
:
- The follow figure display the change process of the input of the whole system, in this sample, the input is limited between
-2
and2
.
- Sorry, due to inconsistent identification of formula format, the formula markdown source code of the derivation process is given in file
MPCformula.txt
, here only use the figure for convinent.
- A larger
horizon
will make the control effect better after referring to more prediction information. However, the phenomenon that the scale of the problem increases must also be taken into consideration. Therefore, a suitablehorizon
is far more important than a largerhorizon
. - The elements in the weight matrix
H
are used to specify the system variables that are more concerned in the calculation process. However, due to the coupling relationship between the system variables, change the value of one element inH
will affect the control effect of the controller on other system variables. Therefore, be careful when tuningH
. - The example in this project provides a simple and rough
$\boldsymbol{X}_{ref}$ selection method. In order to achieve better control effect, a more flexible method should be selected in practical application.