elena-ecn / mpc-cbf

Model Predictive Control with discrete-time Control Barrier Functions (MPC-CBF) for a wheeled mobile robot.
MIT License
111 stars 19 forks source link

I have a problem #3

Open guest-oo opened 7 months ago

guest-oo commented 7 months ago

May I ask the author, where is the matrix used to calculate the terminal error, stage cost, and input cost? May I ask why mterm = self.model.aux['cost'] # Terminal cost and lterm = self.model.aux['cost'] # Stage cost use "cost".

guest-oo commented 7 months ago

May I ask the selection basis of # State cost matrix and # Controls cost matrix and why there is no terminal error matrix?

elena-ecn commented 7 months ago

The objective function is quadratic so the stage cost is defined by the self.Q and self.R matrices. Using the same weight matrix Q for both the stage and terminal costs is a design choice. If you wanted to use a different terminal cost, you could for example set mterm=transpose(X)@Q_final@X. In applications where the system does not reach the final goal within the prediction horizon, it does not make much sense to penalize arbitrary intermediate states more heavily since they are not part of the goal set. That is why I chose to use the same weight matrix.

guest-oo commented 7 months ago

May I ask whether the author set the error weighting sum of the terminal error and the input weighting sum in the following code, and set the matrix of the error weighting sum (state variable weight) and the matrix of the terminal error (state variable terminal weight matrix) to be the same? mterm = self.model.aux['cost'] # Terminal cost lterm = self.model.aux['cost'] # Stage cost mpc.set_objective(mterm=mterm, lterm=lterm) mpc.set_rterm(u=self.R) # Input penalty (R diagonal matrix in objective fun)
And you can set the upper and lower limits of the state variable x and the input u according to the following code. max_u = np.array([self.vx_limit, self.vy_limit]) mpc.bounds['lower', '_u', 'u'] = -max_u mpc.bounds['upper', '_u', 'u'] = max_u mpc.bounds['lower', '_x', 'x'] = [2, 2]
mpc.bounds['upper', '_x', 'x'] = [22, 22]