mindThomas/Kugle-MATLAB

Errors occur when I run the script "TestGeneratedMPC.m"

Opened this issue · 4 comments

Firstly I ran the "GeneratedMPC.m" to genetate the script "kugle_mpc_obstacles_codegen.cpp", "kugle_mpc_obstacles.mexw64" and so on, then I ran "TestGeneratedMPC.m" to test the generated MPC solver "kugle_mpc_obstacles" ,but errors occured when I did this. It displayed "Field od must be of size: 21 x 44 acado_output = kugle_mpc_obstacles(acado_input);"

by the way, the author defines the MPC model which can be seen in "EvaluateLinearMPCmodel.m" and "EvaluateNonlinearMPCmodel.m". However, when using ACADO to construct the MPC solver "kugle_mpc_obstacles", the MPC model seems not to be used, while the model is defined in the way of "f = acado.DifferentialEquation()" in script "GenerateMPC.m", so I'm curious about the meaning of defining the scripts "EvaluateLinearMPCmodel.m" and "EvaluateNonlinearMPCmodel.m"

The "Evaluate*.m" scripts are called when running the closed-loop simulation of the generated MPC controller, see this line: https://github.com/mindThomas/Kugle-MATLAB/blob/master/Controllers/MPC/SimulateMPC.m#L383
While a simplified model is used within the MPC design itself, the more accurate model is used when simulating the dynamics, applying the control inputs computed by the MPC.

I am not sure why you are seeing the ACADO error that you do. Did you install the November 2018 version as mentioned in the README: https://github.com/mindThomas/Kugle-MATLAB/blob/master/README.md#code-generation-and-requirements ?

I am honored to receive your response and I sincerely appreciate it. Currently, I am studying how to use ACADO to solve my own MPC problem. By chance, I came across your project on GitHub, which has been very helpful to me. During my learning process, I have a few questions that I hope you can provide answers to.

From my understanding, the "GenerateMPC.m" file generates the solver for your own MPC problem using a simplified model. However, when running the "SimulateMPC.m" file, a more accurate model is used. I am curious to know if the use of the simplified model in "GenerateMPC.m" would affect the precision of the solver.

My MPC problem involves controlling the end effector of a manipulator to reach a specified position. The MPC model is defined as dot(x) = J * dot(q), where x represents the pose of the end effector, q represents the joint angles, and J is the Jacobian matrix. The state variable is the end effector pose, while the control variables are the joint velocities. However, I am unsure how to construct the MPC solver using my model, as calculating the Jacobian matrix involves a complex process that requires the use of forward kinematics for the robotic arm (a series of matrix operations), which seems to make the model unsuitable for simplification.

I would greatly appreciate your response and guidance on this matter. Thank you very much.

The choice of using a simplified model in the solver is all about improving the convergence rate, I.e. the time it takes the solver to find a solution.
If your optimization problem, defined by the model, cost function and constraints is highly non-linear it will make it harder for the solver to convergence and you will need some very good initial guesses to ensure that the solver will converge at the desired minima.
In my case I simplify the problem since I know which operational domain (close to upright, small accelerations and low speed) the controller will be used within, in which case I can guarantee that the simplified model will be sufficient. But you are right, it will be less accurate especially if used outside of this limited operational domains.

It is not required that you simplify the model and you can always try to generate a solver with your full model and test its convergence. Honestly, I would urge you to do so, at least initially.