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?
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.The terminal set is the set of final conditions that can be adjusted such as
xf,xdotf,q1f, andq1dotf. Hard constraints can be used instead of the soft (objective-based) constraints above.However, this may lead to an infeasible solution if all constraints can't be met.