Opti Race Car with SUNDIALS

152 views
Skip to first unread message

Abe Martin

unread,
Mar 13, 2018, 4:47:11 PM3/13/18
to CasADi
I really like the new Opti interface, and the race car example is great!  I've been trying to modify the car example to use sundials for the integration instead of RK4 by merging in some of the code from the multiple shooting examples.  However, I'm running into a problem when I try to pass T into the integrator as:
 
opts = {'tf':T/N}

I get the error:

NotImplementedError: Wrong number or type of arguments for overloaded function 'integrator'.
 
Possible prototypes are:
    integrator
(str,str,dict:SX,dict)
    integrator
(str,str,dict:MX,dict)
 
You have: '(str,str,str:MX,str:MX)'

Specifically, I'm trying to replace this section of the car example:

dt = T/N # length of a control interval
for k in range(N): # loop over control intervals
   
# Runge-Kutta 4 integration
   k1
= xdot(X[:,k],         U[:,k])
   k2
= xdot(X[:,k]+dt/2*k1, U[:,k])
   k3
= xdot(X[:,k]+dt/2*k2, U[:,k])
   k4
= xdot(X[:,k]+dt*k3,   U[:,k])
   x_next
= X[:,k] + dt/6*(k1+2*k2+2*k3+k4)
   opti
.subject_to(X[:,k+1]==x_next) # close the gaps

With this version from the multiple shooting example:
# CVODES from the SUNDIALS suite
   dae
= {'x':x, 'p':u, 'ode':xdot, 'quad':L}
   opts
= {'tf':T/N}
   F
= integrator('F', 'cvodes', dae, opts)
# Integrate till the end of the interval
    Fk = F(x0=Xk, p=Uk)
    Xk_end = Fk['xf']

Is this possible with the Opti interface?

Joris Gillis

unread,
Mar 13, 2018, 4:56:40 PM3/13/18
to CasADi
Dear Abe,

The divide here is not between Opti style or the more traditional CasADi building blocks.
It's between the shooting example featuring a fixed-time problem, and the race car example featuring a variable time problem.

The trick is to do a time transformation.
Let Cvodes integrate up to time 1, but scale the right-hand side by T.
Make T part of the parameters of the ode..

Best regards,
  Joris Gillis
Reply all
Reply to author
Forward
0 new messages