Lap Time Simulation with Optimal Control
Certain aspects of improving Greenpower cars is obvious – reduce drag, reduce mass. However, other aspects are more nuanced – what is the optimal way to deploy your limited battery energy around a lap/race, taking into account hills, headwinds, corners etc. To answer these questions you either need to do extensive and expensive testing, or detailed physics models representing the cars behaviour must be simulated virtually. This is known in racing as lap time simulation (LTS).
Classical LTS involves integrating the differential equations governing your system forward in time, but these require ‘loop-closure’ to decide on the control inputs driving your system (throttle/brakes/gears/steering in our case). You can either close the loop with a real driver, like F1 DiL simulators, or you can write some code to try and represent a driver. Both methods come with a caveat though, how do you know that your loop closure method is optimal?
When changing car variables like aerodynamic balance on an F1 car, does the e.g. improvement in lap time come from the car being able to extract more grip, or does the driver just prefer that setup, and if they were to change their driving style the opposite change in lap time would occur? Solving these issues is the current gold standard in LTS – optimal control methods.
Computed optimal Greenpower racing line at Goodwood's 'St. Mary's' corner.
As part of my fourth-year dissertation, I wrote an optimal control LTS for Greenpower cars in Python, making use of CasADi and opensource large-scale nonlinear optimisation solvers like IPOpt and BONMIN.
Optimised states for velocity (red) and car location relative to track centreline (blue) around Goodwood circuit
Optimal control methods for dynamic simulation involve a shift in perspective on how to simulate. Instead of integrating forward in time, each discrete increment along the track is already determined, with the car having some state variables each point. We know that in between each segment on the track the physics governing the states must be adhered to, so we can set that as a constraint between each segment. Now our dynamic simulation problem is just a very large optimisation problem, where we are looking to find the minimum lap time by selecting the optimum variables at each state around the track, but we constrain these states so that they must all obey how the physics propagates through time.
Crucially we can also set the driver’s controls as states in this optimisation problem, so that when solved we are confident that the change in lap time involved in any car variable changes is real and not a result of how much coffee the driver-in-loop has had.
These problems can be very large, non-linear and non-convex, which means finding global optimums is hard, and even harder to ‘prove’ (as much as one can with only necessary conditions). The specific approach taken in our LTS is a direct collocation approach with trapezoidal quadrature. We write the dynamics such that automatic differentiation can be used to compute gradient and hessian information for solvers. This is towards the simpler end of optimal control methods but works well for Greenpower cars where the states change smoothly, not featuring stiff dynamics like grip limited tyres.