Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have a problem #3

Open
guest-oo opened this issue Apr 16, 2024 · 3 comments
Open

I have a problem #3

guest-oo opened this issue Apr 16, 2024 · 3 comments

Comments

@guest-oo
Copy link

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
Copy link
Author

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

@elena-ecn
Copy link
Owner

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
Copy link
Author

guest-oo commented Apr 19, 2024

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants