I’m developing an MPC for an autonomous car. This is part of the student organization fuel fighter at NTNU. The goal is to make the most energy efficient autonomous car. We will compete in Shell Eco-Marathon this summer.
I’m using the python interface to define the MPC and then use the generated c-code together with my C++ code for ROS to run the MPC.
I want to use splines to describe the track. Since the track is not know before we start this spline needs to be updated as the system is running. I have not found a good way of doing this. I tried implementing the solution from this topic. I got it working by modifying race_cars example. I modfied line 58 in this file.
# old spline, can't update after compile kapparef_s = interpolant("kapparef_s_old", "bspline", [s0], kapparef) # new spline, can update after compile by setting parameters p. model.p = MX.sym("spilne_p", len(s0), 1) interp_path = interpolant("kapparef_s_new", "bspline", [s0]) kapparef_s = Function("interp_func", [s], [interp_path(s, p)]) # specifying the parameters later for new solution: ocp.parameter_values = np.array(kapparef)
Here s0 is the distance along the trajectory, for example [0, 0.5, 1, … , 0.5*n]. Kapparef is the curvature of the trajectory at each point. It works, however it is painfully slow. ~4000 times slower in my case… I think the issue is that instead of calculating the parameters for the spline once and the using them for the rest of the calculations, it’s calculating the parameters every time the function is called.
What I want is that if the track is updated then the I want to update the spline. Otherwise I want to use the spline from the previous calculation. I think that if it would be possible to send the spline parameters (the internal coefficients) to acados it would work. Then I would generate the interpolant function myself and pass this to acados. I could either pass the internal parameters or what would be very nice is that if I could pass a function pointer or something like that . Is this possible?
Thanks for your time!