So I want to start off by saying that this project for the time being is still very much under development and I’m not even sure how advanced I want it to get yet, or exactly how much more work I want to put in it.
I wrote some MATLAB code to calculate optimal lap times and optimize racing lines using the CasADi solver. It allows the import of RaceChrono telemetry data and comparing it directly against the simulated optimal line.
In the figure above the limits for these parameters were taken from the racechrono log, that way the optimization algorithm creates a perfect lap for similar vehicle dynamics. The logged lap is my 12.09 world record T-race lap for comparison.
After the constraints are set it generates the optimal racing line for the programmed track. Trying to keep the vehicle on one of the above mentioned limits all the time. At the moment I only have the T-race track implemented, as the reason why I even got started on this project is that I was wondering what the optimal lap of T-race actually is, and where I might be able to find more improvements.
You can find the project on github if you want to run it for yourself:
It is being developed in Matlab R2026a, don’t know whether it works in other versions.
You’ll need to download CasADi and add it to your matlab path for this to work.
It is possible to implement custom tracks, however only T-race is tested for now. Now with CasADi it can do ~500 nodes now and I also added interpolation between nodes if it’s needed for particularly large tracks.
Now you know what you gotta do lol. Virtual Coach/Race Crew. Take all this data bridge RaceBox and VESC telemetry into an app that then helps you on pace, how off the line you are, getting on brakes and acceleration, etc talking to you through BT.
Would be very cool if I get there eventually. Once I get to the fully custom electronics part of my board it would make sense developing an app for it to have all the telemetry data conveniently accessible.
What I’m working on for now requires a PC with Matlab installed on it to check the data. Matlab has very powerful tools to work with data, and relatively easy to code as well, hence why I started here. I haven’t looked into it yet, but I have serious doubts about the optimal lap generation being viable on a phone, simply because of not having access to matlab’s vast toolbox. However I can certainly imagine using the matlab code to export the pregenerated ideal lap data and build just a comparison tool into the mobile app.
All that said, I am not a great programmer, so even if I end up making that app, don’t expect that to happen very soon.
Here is the current progress and the comparison to my best lap of today’s session. I also moved all the configuration settings to the first section and (to some degree) untangled the code for readability if anyone wants to download it. PS: you need matlab.
At this point the only implemented track is still T-race, but with some of the changes I made today it’s a lot more robust under the hood so it should work for other tracks as well without too many problems hopefully
Added speed traps like in racechrono (red is gps, green is optimal).
Also implemented speed dependent lateral jerk limits. In effect, it doesn’t simulate with a jerk of 4-5G/s in the middle of the straight now when starting the turn in (at speed, this would be way too scary), but still simulates with the high limit in the low speed corners, where it is actually being achieved according to the gps data. This slowed down the optimal line a bit, so it reflects reality better now.
That’s amazing, especially the headset integration would be so good to have! We can take a look at the possibilities, I’ll DM you in a bit.
I can see two possibilities, one is to pregenerate many laps with various vehicle dynamics (probably easiest to implement) and match the closest. And then there’s the proper way which allows you to set your specific vehicle dynamics and generate laps for that - I’d prefer to take a look at the possibility of implementing it this way if it’s possible (have to check feasability), there’s a fair bit of computational requirement for this though and would most likely require a fair bit of work from both of us.