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

About the system model and non-quadratic objective function #3

Open
BlueeHole opened this issue Mar 26, 2024 · 2 comments
Open

About the system model and non-quadratic objective function #3

BlueeHole opened this issue Mar 26, 2024 · 2 comments

Comments

@BlueeHole
Copy link

BlueeHole commented Mar 26, 2024

First of all thank you for sharing this code! But I have a question for this.
The vehicle model you use in car.py is non-linear.

def update_state(self, dt):
		A = np.array([
				[1, 0, 0],
				[0, 1, 0],
				[0, 0, 1]
					])
		B = np.array([
				[np.sin(self.x[2, 0] + np.pi/2)*dt,  0],
				[np.cos(self.x[2, 0] + np.pi/2)*dt,  0],
				[0			 , dt]
					])

		vel = np.array([
					[self.x_dot[0, 0]],
					[self.x_dot[2, 0]]
				])
		self.x = A@self.x + B@vel

In the MPC objective function, you directly use this model to derive all future states within the control hoziron, and use QP to solve it.

x, _ = controller_car.get_state()
z_k[:,i] = [x[0, 0], x[1, 0]]
cost += np.sum(self.Q@((desired_state-z_k[:,i])**2))

But in this case, the objective function is not quadratic, right? (it contains sin(x) ).
Is there any theoretical basis for doing this? Or did I misunderstand something? Hope for your responding, thank you!

@zainkhan-afk
Copy link
Owner

zainkhan-afk commented Mar 27, 2024 via email

@BlueeHole
Copy link
Author

Thank you for your detailed response! But I still have one question. quadratic should be polynomial, right? But here, at every step, you update x using x\dot=Ax+Bu, here A is non-linear of x. ( because sin(\theta) ). So from the second step of update, u has been coupled with x, and the whole cost function has been non-linear of u. Therefore, the sum of these items would be non-linear of u.
That is, the objective function is non-linear. Here is a misunderstanding. I firstly thought SLSQP is for quadratic(polynomial) objective function, but it actually can solve non-linear functions.( from the documentation of scipy)
image
So if I had discovered that SLSQP could be used to solve nonlinear problems from the beginning, I would not have raised this issue. But I happened to have not discovered it before, that's 'lucky', to some degree.
To sum up, my question is , whether your cost function is a polynomial of u? I think it's not, so it's not quadratic.
I searched other materials and found many people do linearization like this: (sorry it's Chinese, but please check the formula)
image
that is to use Taylor expension on the reference point. Here the θr is a constant (the reference theta )As I think, through this the objective function would be linear and really 'quadratic'. But by this method, we need to provide θ_r and v_r on every point, since A contains θ_r and v_r.

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