README.md
1 # Machine learning to improve sim racing driving styles 2 3 Sim racing is about improving lap times. There are tools that capture telemetry 4 and let you compare your telemetry to other drivers. 5 6 https://www.youtube.com/watch?v=sGCuP1VCkTU 7 8 But how about automtically detecting the best way to improve your driving style 9 and giving recommendations *while* you are driving? 10 11 ## Driving style changes 12 13 Implementation of a change should result in an improvement of lap time. 14 Changes can be compared by the amount of lap time, or sector time, improvement. 15 16 Time improvement should be measured over the course of one or multiple corners. 17 18 If there is one corner between two straights, the time measurement would start 19 at the braking zone and end at the acceleration zone. Or the corner entry and exit. 20 One might factor entry speed and exit speed into the measurement, since it's not 21 only the time spend driving through a corner, but the overall lap time what matters. 22 23 A more complex scenario might be the combination of successive corners, such as a chicane, 24 which is usually a left followed by a right, or vice versa. 25 26 ## Braking point 27 You brake too early or too late 28 Input: track position percent, brake input 29 30 ## Trail braking 31 Instead of releasing the brake apprubtly, you ease off the brakes while turning the car into a corner. 32 Input: rate of change of brake input 33 34 ## Acceleration 35 Instead of going full on the throttle, you ease into the throttle. 36 Input: rate of change of throttle input 37 38 ## Overlapping brake and throttle 39 40 ## Grip 41 Having the tires not at full grip, i.e. either you are too slow or turning to slow and the tires still have grip available or you are braking too hard or accelerating too much and the tires either block or lose grip. 42 43 ## Racing line 44 Not following the racing line 45 Input: track position x,y 46 47 48 ## Geometric approach 49 50 See [analysis](analysis/) folder for a geometric approach to the problem. 51 This also contains some analysis EDA and visualization for lap data. 52 53 ## Reinforcement learning 54 We have human driver telemetry data as input and car telemetry data and world positions as output. 55 The function to be maximised is corner time, sector time and lap time. 56 The agent inputs are the car telemetry data and the world positions. 57 The agent outputs are human driver inputs to the car, such as throttle, brake and steering. 58 The world reaction are the car telemetry data, such as tire grip and speed and the world positions, such as percent of track completed. 59 60 61 Q: would the agent learn the best combination of all laps used to train the agent? I.e. would we get a better lap than a human selected coach lap? 62 63 Q: would we get an agent model that would respond with the best next car input given a current world and car telemetry? 64 65 66 67 ## AI Coaching 68 69 The coach should provide the driver with actionable advice on how to improve the lap time. 70 Therefore the coach needs to evaluate what changes have the biggest impact on the lap time. 71 This could be posed as a ranking problem. 72 73 Given a corner inputs, find a recorded corner that is different in only one feature and compare the time improvement. 74 Do this for all available features and select the one with the biggest improvement. 75 https://towardsdatascience.com/time-series-clustering-deriving-trends-and-archetypes-from-sequential-data-bb87783312b4 76 77 1. identify which cluster you belong to 78 2. find adjacent clusters 79 80 81 It also needs to evaluate past behaviour and incorporate changes the driver has made. 82 E.g. if you usually brake too early in your previous laps, but now you fixed that behaviour, the coach should not notify you about that anymore. 83 So the coach needs to have some memory of some sorts. 84 85 86 ## Braking coach 87 88 Given a position on the track, the coach should notify the driver to brake in 100m, 50m and now. 89 90 The model is trained to emit a braking point signal 100m, 50m and now for the given position. 91 The model should have some memory for the previous inferences, since we dont know about the frequency of inference, we can only assume that the previous inference is position wise before the current inference. 92 93 94 ## Resources 95 96 https://arxiv.org/abs/2005.05178 97 https://github.com/linklab-uva/deepracing 98 https://paperswithcode.com/dataset/torcs 99 100 101 https://jmotif.github.io/sax-vsm_site/morea/algorithm/SAX.html 102 https://en.wikipedia.org/wiki/Q-learning 103 104 https://theoehrly.github.io/Fast-F1/ 105 ## Offline reinforcement learning 106 * https://arxiv.org/abs/2005.01643 107 * https://arxiv.org/pdf/2203.01387.pdf 108 109 110 ## Explaining a race track 111 112 https://www.formula1-dictionary.net/corners.html 113 114 ## Extracing features 115 116 [Information about iRacing tracks](https://github.com/SIMRacingApps/SIMRacingApps/issues/242) 117 118 ## track processing 119 120 * https://github.com/TUMFTM/racetrack-database 121 * https://github.com/TUMFTM/global_racetrajectory_optimization 122 123 # plotly rendering 124 * https://github.com/plotly/plotly.py/issues/931#issuecomment-819502866