2

I have a NMPC controller written in python using Gekko library for a nonlinear model of inverted pendulum mounted on the cart. I want to add terminal set and terminal cost using Gekko Library.

This is how I defined the objective function in code:

m.Obj(final*(x-xf)**2)
m.Obj(final*(xdot-xdotf)**2)
m.Obj(final*(q1-q1f)**2)
m.Obj(final*(q1dot-q1dotf)**2)
m.Obj(TF)

I don't know where and how to add terminal cost and terminal set?

user2002
  • 21
  • 1

1 Answers1

0

There are the Inverted Pendulum Optimal Control and the Double Inverted Pendulum Optimal Control example problems for reference. The terminal cost can be set by adding an additional weight (w1-w4) to each term to prioritize which one is met. In the example cases, all final conditions are met so the terminal cost is zero when (w1=1, w2=1, w3=1, w4=1). The solution may change when using different terminal weights.

m.Minimize(final*w1*(x-xf)**2)
m.Minimize(final*w2*(xdot-xdotf)**2)
m.Minimize(final*w3*(q1-q1f)**2)
m.Minimize(final*w4*(q1dot-q1dotf)**2)

The terminal set is the set of final conditions that can be adjusted such as xf, xdotf, q1f, and q1dotf. Hard constraints can be used instead of the soft (objective-based) constraints above.

m.Equation(final*(x-xf)==0)
m.Equation(final*(xdot-xdotf)==0)
m.Equation(final*(q1-q1f)==0)
m.Equation(final*(q1dot-q1dotf)==0)

However, this may lead to an infeasible solution if all constraints can't be met.

John Hedengren
  • 12,068
  • 1
  • 21
  • 25