Collecting and analyzing data to predict which F1 car will finish the race first.
- Platformio is a collaborative platform for embedded software development that supports a lot of boards of different vendors. It has a user-friendly interface with code completion and an integrated debugger.
- Neuton Platform enables the fast and seamless creation of optimal models, offering a high level of automation in data processing and neural network pipeline generation.
- Arduino Nano 33 BLE Sense
I've always been fascinated by Formula One and how fast cars race around the track. Since my other big interest is experimenting with machine learning, I came up with an idea to combine these two passions and create a project dedicated to vehicle speed prediction.
Of course, I don't have the opportunity to conduct such experiments on a real track and with real racing cars, so I decided to predict which F1 car is faster based on accelerometer and gyroscope sensors fixed on a miniature F1 car!
This is a simplified example of what tiny machine learning can do in motorsport. But since F1 utilizes innovative technologies, I believe the approach described in this article can be scaled to make predictions and help real teams in the world championships.
My experiment includes the following three steps:
- Collecting the data for a dataset
- Training a TinyML model
- Deploying the model on a microcontroller
Next, I will describe all three stages of the experiment in more detail so that you have the opportunity to repeat them.
To create a good dataset, I perform measurements by placing an MCU on a car and moving it at a different speed. The firmware makes readings on the accelerometer and gyroscope sensors to collect the data. It reads 2 seconds of data and calculates the statistics of those readings values. After that, it prints the statistics in CSV format to upload to the Neuton platform.
As the first step, you need to upload the firmware to Arduino Nano 33 BLE Sense. It comes with a series of embedded sensors:
- 9 axis inertial sensor (I used it to detect the car movement behavior)
- humidity and temperature sensor
- barometric sensor
- gesture, proximity, light color, and light intensity sensor
Find the repository with the complete code here: https://github.com/leoribg/neuton-f1-data-collect.
Secondly, you need to make the movements for each target you want to identify.
0: Car Idle (Car is stopped)
1: Ferrari F1 Car (Speedy)
2: HAAS F1 Car (Kinda fast)
3: Williams F1 Car (Slow)
Now, you have to copy the output and save it as a CSV file for all targets.
Upon the dataset collection, you are ready to train your model. For that purpose, I used the Neuton platform, as it’s free.
Upload your dataset in a CSV format and click OK.
Select the target variable and click "Next".
This project detects one of four possible targets, so it is a multiclassification problem. Neuton can automatically detect a task type based on the target variable values. You need to select the best metric to represent the model quality, for this type of problem, I selected “Accuracy” and also enabled the TinyML mode.
Click “Start Training” and relax until the model training is complete.
One more cool thing about Neuton is that the platform makes it possible to evaluate the quality of the trained models. You can check the meaning of each metric here: https://lab.neuton.ai/#/support_library/metrics/.
Here is the model that I got:
I got 100% model accuracy, but I was curious about whether I got the smallest size of the model. To check this, I decided to build the model on TensorFlow Light. Actually, I asked a friend to help me, as it requires special coding skills and time, but after a day of work, I realized that my first model, which was automatically created with Neuton, was 4 times smaller. I decided not to embed the TFL model, but I am sharing with you the comparison of metrics.
Deploying on a microcontroller
Neuton automatically generates the C library after clicking on the “Download” button.
Once the library is downloaded, It’s time to run the inference on a microcontroller.
You need to set the input for your model with the same format you have trained it.
And run the inference based on the input data.
All the code necessary to run this model is available here: https://github.com/leoribg/neuton-f1-model.
Connect your board to a PC with a USB cable and connect it to serial monitor software, like Putty, Docklight, or TeraTerm, to check the inference results.
Formula One is a competition among the best drivers in the world, but also is a battle between the engineers. During a Grand Prix, every car is equipped with hundreds of sensors generating massive quantities of real-time data. This data can be combined with historical data to train machine learning models to help the teams make the best decisions and predictions.
As this sport embraces new technologies, I’m convinced that machine learning has great potential for use by F1 engineering teams, giving them new insights into racing and car development. Plus, implementing such solutions is really quick and easy (I proved it in my project!). I hope my tutorial will inspire you to repeat this experiment or create your own TinyML projects!