OpenOCL icon indicating copy to clipboard operation
OpenOCL copied to clipboard

interpolation

Open radiodawn5 opened this issue 6 years ago • 3 comments

I presume the CasADi interpolant can already be used in OpenOCL? If yes, would it be possible to introduce an example where lookup tables are used in the definition of the dynamic system (dae or ode) and path constraints?

radiodawn5 avatar Oct 02 '19 09:10 radiodawn5

I think interpolant should work although i haven't tested it yet. You need to set the option nlp_casadi_mx to true for ocl.Solver (which will be ocl.Problem in the next release) because interpolant only works with MX symbolics as far as i know.

Generally you can use all CasADi functions with OpenOCL. Sometimes it can happen that the OpenOCL type (ocl.Variable) and CasADi types do not work well with each other, then you can always use the .value() function on the ocl.Variable to get the underlying CasADi value and work with that.

I assume your lookup table is state dependent? What are you interpolating in your case? I will try to come up with a simple example.

If polynomial interpolation is sufficient for your problem, you could avoid using interpolant by using polyfit to fit your data, and then polyval in your OpenOCL models. Would that work for you or do you need to use splines?

jkoendev avatar Oct 02 '19 12:10 jkoendev

Yes the lookup table I would like to use is either state or control dependent. Taking your race car example, you could have a lookup table for the road center line e.g. y_center = f(x_road).

radiodawn5 avatar Oct 02 '19 14:10 radiodawn5

hi, i added an example racecar_interpolant here: https://github.com/OpenOCL/OpenOCL/blob/dev_interpolant_example/%2Bocl/%2Bexamples/racecar_interpolant.m

It should show the basic usage of casadi.interpolant in OpenOCL. Note that in line 163 i use the .value to get the casadi type. In line 164 and 165 i add the centerline (casadi expression) from the right side so that it works with the ocl.Variable type. Otherwise you could also use the .value function on the other part of the expression like:

y_max = y_center + 0.5*p.road_bound.value;
y_min = y_center - 0.5*p.road_bound.value;

The center_line_lut is passed to the gridconstraints function in line 24.

It is in a seperate branch as i haven't written any test for it yet..

jkoendev avatar Oct 04 '19 14:10 jkoendev