matt-weinstein / adigator

Matlab Algorithmic Differentiation Toolbox
25 stars 5 forks source link

Unable to use ADiGator for GPOPS problem with multiple phases #9

Closed WJWest closed 4 years ago

WJWest commented 4 years ago

Hi ADiGator creators,

Thank you so much for the work that you put into this tool!

I am currently busy with my Masters degree where we are solving the minimum lap time optimal control problem for a Formula 1 car. We are using GPOPS as the optimal control solver and want to use ADiGator as the derivatives supplier.

Initially we solved the minimum time problem for a single lap in GPOPS using ADiGator as the derivative supplier and it worked really well. When I extend the problem over multiple laps we get an error when ADiGator tries to calculate the derivatives for the Continuous function.

The underlying equations did not change. The only difference is that the phaseout structure used by GPOPS now consists of multiple phases (one phase for each lap). The integrand, dynamics and path structures have been assigned in exactly the same way:

Instead of

phaseout.integrand = dtds; [phaseout.dynamics, phaseout.path] = MinimumLapTimeDAE(s,x,u,dtds,curvature,data);

We now have

phaseout(iphase).integrand = dtds; [phaseout(iphase).dynamics, phaseout(iphase).path] = MinimumLapTimeDAE(s,x,u,dtds,curvature,data);

ADiGator returns the following error: Unable to use a value of type cada as an index.

Error in cada/adigatorAnalyzeForData (line 381) xOverLoc = ADIGATOR.VARINFO.OVERMAP.FOR(xCount,1);

Error in adigator (line 564) adigatorAnalyzeForData(ForCount,dummyVar);

Error in adigatorGenFiles4gpops2 (line 204) adigator(ContFunc,{cinput},ContDeriv1,ADopts);

Can you please help us to address this issue?

Kind regards

machalot commented 4 years ago

I ran into a similar issue a few years ago when I tried to vectorize my phase outputs. First, try unrolling your iphase loop and setting each phase output explicitly with a separate call to your DAE function. That might reveal some other issue that is causing this error.

Do any of your DAE function inputs need to be indexed by (iphase)? That might cause a dimension mismatch that makes adigator unhappy.

WJWest commented 4 years ago

Thank you for the feedback!

I had a for loop in the continuous function to construct the phase output. After explicitly writing out each iteration instead of using the for loop the issue was resolved :).

Really appreciate the help!

machalot commented 4 years ago

Glad it's working. I can't explain why that makes a difference. Maybe @matt-weinstein will have some insight when he's available to check this thread.