Deriving optimal trajectories on a manifold in GEKKO

Viewed 76

I've finally gotten back to working on my project and have found my next hurdle.

I have an enclosed manifold: Field as manifold

Also here's an example trajectory in the game im modelling enter image description here

that I can have my system drive on like a normal car. I'm curious what the best way to incorporate this type of constraint would be in gekko. The manifold looks like a cube with rounded edges and corners. My current thought is to create a MLP (multii layer perceptron) to approximate the normal vector on the manifold at each point in on the surface. I tried using the GEKKO brain model to do this but it ended up being very slow so I moved to a keras model. I now have a keras model that is about 89% percent accurate connecting positions to normal vectors (which might be enough).

So my first thing is, how can I incorporate the keras model into my gekko equations? If I'm able to calculate the derivative of the neural network output at each point as well would it be possible to black box the model such that gekko puts in a position and then the black box function spits out a normal vector and this normal vectors derivative to ultimately calculate optimal trajectories?

If this is not possible, do you think I could easily model this manifold as a bspline? And what would be the way I should approach making the manifold surface a constraint for the system while it's in the driving state? My thoughts were I would take the system's current velocity vector and dot it with the normal vector of the manifold at the system's position to get how much along the manifold the velocity vector rotates. I already see some problems like for example large time steps missing curvature of the manifold and causing the system to drive off the surface of the manifold. I think the typical way of doing this math is to project the system's velocity into the "tanget space" of the manifold, derive the future state in the tanget space then map back to the manifold using a retraction. I'm still fairly new to this topic of topology and manifolds so correct me if I've made a mistake on the theory.

I don't have much code yet doing this as I'm stuck figuring out how to use the keras model in an equation. I do have a simpler problem available which is instead of driving on this complex manifold I just drive on a circle in R2. I've modelled this circle in R2 using a keras model as well. I plan to start with the simpler version if I'm able to use keras in equations before I jump into driving on the manifold in R3.

Are there any examples doing something similar to this that I could learn form?

Thank You! Excited to get back into this project.

1 Answers

This path planning optimization application may be better with a shooting approach where the model is a "black box" that the optimizer repeatedly calls the simulator. Some of the challenges are the changing equations when the vehicle is interacting with the ground versus in the air. If you do want to try to model both ground and air, an if3 statement would allow the switching or else use slack variables.

For the boundary constraint, maybe there is a simpler way to start modeling it such as simple inequality constraints that would form a box. You could add additional inequality constraints for the edges to model the curvature.

Below is a related application with a rocket launch that is applicable to the air dynamics. You would need to extend this to 3D.

Rocket launch

import numpy as np
import matplotlib.pyplot as plt
from gekko import GEKKO

# create GEKKO model
m = GEKKO()

# scale 0-1 time with tf
m.time = np.linspace(0,1,101)

# options
m.options.NODES = 6
m.options.SOLVER = 3
m.options.IMODE = 6
m.options.MAX_ITER = 500
m.options.MV_TYPE = 0
m.options.DIAGLEVEL = 0

# final time
tf = m.FV(value=1.0,lb=0.1,ub=100)
tf.STATUS = 1

# force
u = m.MV(value=0,lb=-1.1,ub=1.1)
u.STATUS = 1
u.DCOST = 1e-5

# variables
s = m.Var(value=0)
v = m.Var(value=0,lb=0,ub=1.7)
mass = m.Var(value=1,lb=0.2)

# differential equations scaled by tf
m.Equation(s.dt()==tf*v)
m.Equation(mass*v.dt()==tf*(u-0.2*v**2))
m.Equation(mass.dt()==tf*(-0.01*u**2))

# specify endpoint conditions
m.fix(s, pos=len(m.time)-1,val=10.0)
m.fix(v, pos=len(m.time)-1,val=0.0)

# minimize final time
m.Obj(tf)

# Optimize launch
m.solve()

print('Optimal Solution (final time): ' + str(tf.value[0]))

# scaled time
ts = m.time * tf.value[0]

# plot results
plt.figure(1)
plt.subplot(4,1,1)
plt.plot(ts,s.value,'r-',linewidth=2)
plt.ylabel('Position')
plt.legend(['s (Position)'])

plt.subplot(4,1,2)
plt.plot(ts,v.value,'b-',linewidth=2)
plt.ylabel('Velocity')
plt.legend(['v (Velocity)'])

plt.subplot(4,1,3)
plt.plot(ts,mass.value,'k-',linewidth=2)
plt.ylabel('Mass')
plt.legend(['m (Mass)'])

plt.subplot(4,1,4)
plt.plot(ts,u.value,'g-',linewidth=2)
plt.ylabel('Force')
plt.legend(['u (Force)'])

plt.xlabel('Time')
plt.show()

Here is one more application with the landing of a reusable rocket with source files. They developed a surrogate model of the rocket dynamics to apply the model in predictive control.

surrogate model

This is an example of a 3D rocket application but they didn't have the complication of ground interaction with changing dynamic equations.

Related