Application of RRT for Overtaking in a Racing Car Simulation
Total Page:16
File Type:pdf, Size:1020Kb
Application of RRT for overtaking in a Racing Car Simulation Jose´ Guilherme Freitas Gomes Thesis to obtain the Master of Science Degree in Information Systems and Computer Engineering Supervisors: Prof. Joao˜ Miguel de Sousa de Assis Dias Prof. Carlos Antonio´ Roque Martinho Examination Committee Chairperson: Prof. Miguel Nuno Dias Alves Pupo Correia Supervisor: Prof. Joao˜ Miguel de Sousa de Assis Dias Member of the Committee: Prof. Manuel Fernando Cabido Peres Lopes November 2019 Acknowledgments Firstly, I would like to thank both of my supervisors, Prof. Joao˜ Dias and Prof. Carlos Martinho. They helped me a lot throughout this work, and I regret not asking some questions that sometimes stopped this work development. It was a privilege to work with them, and I would like to thank you for taking me, and helping me become a more capable person. I would also like to thank Samuel Canada Gomes, the author of the work this thesis is based on. Without any obligation or gain, he helped me with code, some doubts I had about the game and tech- nique, and even gave me some useful advice. Its fair to say he had a great contribution to this work, and I wish him the best of luck in his future endeavours. Next I would like to thank my father Silvestre and my mother Liliana for continuously supporting me. Even though they were not physically by my side (due to my residence at the time I was studying), they gave me company and constant care, and without them none of this could have been possible. I hope someday the person I become can hope to reciprocate all they did and gave to me. I would also like to thank my grandparents Maria and Jose,´ for although not understanding much of what I was doing, always showed that they were extremely proud of me. Through good and bad results, their support never wavered. Finally, I would like to thank my sister Claudia,´ for taking care of me all this years, and making me a strong enough person to adventure myself, making this masters far from my zone of confort possible. I also need to thank Anabela and Ademar Spencer and their kids Guilherme and Gabriel. They took me in their home, barely knowing me, trusting and caring for me, just like a son or a brother. They were my second family throughout these two long years, teaching and helping me overcome my flaws, making me grow in a way I was not able to do alone. They made this journey a reality and I deeply thank them for it. Finally I would like to thank all my friends especially the ones I made in IST. I came to Lisbon knowing just a long time friend that help me discover this great city, but the people I met in my master’s made it a place I could call home. They’re all extremely capable and smart, and it is an honour to say I worked with them. To Andre,´ Lourenc¸o, Jan, Gonny, Diogo, Bruno, Mariana, and again Samuel, and all the amazing people I met in these two years, I have nothing but gratitude. Without them, this project could have been finished maybe two months earlier, but they made this adventure something I would never regret. I owe and dedicate the labor of my love, countless caffeine-induced sleepless nights and stress, to all of these people. Guilherme Gomes Funchal, 31st October 2019 ii Abstract This document describes the application and development of a TORCS robot that, on a racing scenario, follows a determined trajectory (referred as racing line) calculated with the K1999 algorithm and, in case of overtaking, one that is traced by a Rapidly-exploring Random Tree based algorithm called Adapt and Overtake-RRT (ADOVER for short), working in two different modes that will later be compared. It is meant to compete against other robots and also humans, having as a requirement maintaining an acceptable performance throughout its execution. After some testing with static opponents, the robot was unable to perform the desired task. On the other hand, it showed promising results in terms of speed and efficiency. Possible improvements are discussed in the last segment. Keywords Rapidly-Exploring Random Tree (RRT), The Open Racing Car Simulator (TORCS), Overtaking, K1999, Adapt and Overtake Rapidly-Exploring Random Tree (ADOVER-RRT) iii Resumo Este documento descreve a aplicac¸ao˜ e desenvolvimento de um roboˆ do jogo TORCS que, num cenario´ de corrida, segue uma trajetoria´ determinada pelo algoritmo K1999 e, em caso de ultrapassagem, segue uma trajetoria´ determinada pelo algoritmo Rapidly-Exploring Random Tree (RRT), em dois modos de funcionamento diferentes que mais tarde irao˜ ser comparados. Este roboˆ destina-se a competir contra outros robosˆ e contra humanos, tendo como requisito manter uma performance aceitavel´ durante toda a sua execuc¸ao.˜ Apos´ alguns testes com oponentes estaticos,´ o roboˆ nao˜ conseguiu desempenhar a tarefa que lhe foi atribu´ıda. Por outro lado, mostrou resultados promissores em termos de velocidade e eficiencia.ˆ Poss´ıveis melhoramentos sao˜ discutidos no ultimo´ segmento. Palavras Chave Rapidly-Exploring Random Tree (RRT), The Open Racing Car Simulator (TORCS), Ultrapassagem, K1999, Adapt and Overtake Rapidly-Exploring Random Tree (ADOVER-RRT) v Contents 1 Introduction 1 1.1 Work’s Goal............................................3 1.2 Outline...............................................4 2 Related Work 5 2.1 Racing AI.............................................7 2.1.1 Capabilities and behaviours...............................7 A – Advanced car control........................7 B – Collision avoidance.........................7 C – Overtaking..............................8 D – Aggressiveness...........................8 2.1.2 Examples.........................................8 2.1.2.A Roborace Robocar/Devbot (2016) [1]....................8 2.1.2.B rFactor 2 Image Space Incorporated (2013) [2]...............9 A– Assetto Corsa Kunos Simulazioni (2014) [3]...........9 B– RaceRoom Racing Experience Sector3 Studios (2013) [4]...9 C– Project CARS 2 Sligthly Mad Studios (2017) [5]......... 10 D– Gran Turismo Sport Polyphony Digital (2017) [6]......... 10 E– F1 2018 Codemasters (2018) [7].................. 10 2.1.2.C Comparison table............................... 10 2.2 Racing Line............................................ 10 2.2.1 Geometric approach................................... 11 2.2.2 K1999 Path-Optimisation Algorithm [8]......................... 14 2.2.3 Race Optimal AL © [9].................................. 15 2.3 Rapidly-Exploring Random Tree (RRT)............................. 19 2.3.1 Base Algorithm [10]................................... 20 2.3.2 RRT* [11]......................................... 21 2.3.3 RRT*-Smart [12]..................................... 22 vii 2.3.4 Parallelization....................................... 24 2.3.4.A IPS-RRT applied to TORCS......................... 24 2.4 Frame rate and algorithm impact................................ 25 2.5 Discussion............................................ 26 3 Proposed solution 29 3.1 TORCS Track Representation.................................. 31 3.2 K1999............................................... 31 3.3 ADOVER-RRT.......................................... 32 3.3.1 Description........................................ 33 3.3.2 Characteristics...................................... 35 3.4 Path Adjustment......................................... 35 4 TORCS Robot Implementation 39 4.1 Bot Architecture......................................... 41 4.1.1 TORCS Back-end.................................... 41 4.1.2 Racing Line........................................ 41 4.1.3 Retracing......................................... 42 4.1.4 Control Module...................................... 43 4.2 Search State Representation.................................. 44 4.3 ADOVER-RRT applied to TORCS............................... 44 5 Testing & Evaluation 49 5.1 Proof of concept testing..................................... 51 5.2 Tests................................................ 54 5.3 Discussion............................................ 57 6 Conclusion 59 6.1 Notes for Future Work...................................... 61 viii List of Figures 2.1 Effect of road inclination on maximum possible vehicle speed................. 11 2.2 Racing line arc scheme. Optimal radius c is unknown. [13].................. 12 2.3 Comparison between trajectories and benefits of following the late apex trajectory. Both images taken from [14]...................................... 17 2.4 Algorithm 2.1 before (dotted) and after gradient descent (not dotted) [8]........... 18 2.5 Control points (red) and resulting racing line (blue) for the Porsche GT3 RS 4.0 at Shang- hai International Circuit [9].................................... 19 2.6 TT Circuit Assen - F1 Car - Race Optimal Simulated Lap segment. The higher the colour temperature, the higher the target speed. Throttle, brake and g-force information is also shown [9].............................................. 19 2.7 A Naive Random Tree vs. an RRT , each with 2000 vertices [10]............... 21 2.8 RRT vs RRT*. Note the smooth branching on RRT*. Image taken from [15]......... 22 2.9 RRT*-Smart steps. Images taken from [12]........................... 24 2.10 Attributes in each IPS-RRT state [16].............................. 26 3.1 Track segment types in TORCS................................. 31 3.2 The blue dots represent the cars corners, the dynamic path is represented in green and the static, optimal path in pink. The agent using the K1999 retraces its current path and redraws it around the opponent it finds withing