Skip to content
A racecar simulation with model predictive control and motion blur for final projects in MEAM517 and CIS519
C++ CMake GLSL
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
modules
CMakeLists.txt
GlModel.cpp
GlModel.hpp
LICENSE
OpenGlWrappers.cpp
OpenGlWrappers.hpp
Path.cpp
Path.hpp
README.md
RaceWindow.cpp
RaceWindow.hpp
RacecarMPC.pdf
RgbImage.cpp
RgbImage.hpp
Simulation.cpp
Simulation.hpp
any_color.fs
any_color.vs
cone.fs
cone.vs
main.cpp
screenshot.png
solid_color.fs
solid_color.vs
top_screenshot.png

README.md

Racecar-MPC-Simulation

Screenshot

A racecar simulation that I created for two different final projects for two classes I took in Fall of 2018. One was a control systems class (MEAM517) and the other was machine learning (CIS519) and both had final projects where we could pick anything relevant we wanted. I'm the software lead of Penn Electric Racing, a student organization that designs, builds and races custom electric racecars, and we've been thinking about competing in the driverless division at some point, so this seemed like a great opportunity to get started on the project. Even if we don't, it was a great learning experience and hopefully other teams will find it useful. I developed the physics model and used it to develop a Model Predictive Control algorithm to get the racecar to follow a path for MEAM517. The CIS519 project involved using Neural Networks to find cones in images with motion blur and I used the simulation to generate the training and test data. It was a group project and I'm not including the machine learning portion of the code.

Screenshot

Project Results Summary

The simulated racecar can successfully follow different courses, but there's still a lot of room for tuning. The code nearly runs in real time but it isn't quite fast enough and the racecar doesn't follow the path as well as I'd like. The neural network we produced for the machine learning project was able to locate cones in the test dataset within an average positional error of 1.2m. The simulation doesn't include pitch and roll yet though and I expect that to reduce the accuracy. I tried to make everything as realistic as was feasible and I'm really curious to see how will the approaches to both problems will work on a real vehicle.

Controls

  • p - Pauses the simulation
  • Space bar - Top down view
  • + - zoom in
  • - - zoom out
  • To enable keyboard control (disabling MPC), change the boolean at the beginning of Simulation.cpp
  • ↑ - Maximum acceleration (all wheels) - may want to edit the code to tune this depending on the course
  • ↓ - Maximum deceleration (all wheels)
  • Move mouse left and right to steer

Files

  • RacecarMPC.pdf - My report for MEAM517. Read this for more details on the implementation and results.
  • CMakeLists.txt - CMake build file. See below for information on building the project
  • GlModel.hpp/.cpp - Class for easily loading 3D models into a format usable with OpenGL using ASSIMP.
  • OpenGlWrappers.hpp/.cpp - RAII classes for managing OpenGL resources to simplify loading shaders and avoiding resource leaks.
  • Path.hpp/.cpp - A class hierarchy for working with paths made of several types of primitives and trajectories that determine the optimal speed for the racecar to go along the path
  • RaceWindow.hpp/.cpp - gtkmm window class that does most of the rendering and user interaction
  • RgbImage.hpp/.cpp - A class for saving and loading images and for OpenGL textures and screenshots
  • Simulation.hpp/.cpp - A set of classes that handle updating the simulation, including doing the physics calculations and MPC. The course and simulation can be changed at the end in create_simulation and a variety of parameters can be adjusted at the beginning of the file.
  • main.cpp - Starts the simulation
  • any_color.vs/.fs - Shaders for drawing with no lighting and each vertex having a specified color. Linear interpolation is used for colors in between.
  • cone.vs/.fs - Shaders for drawing cones with stripes and directional lighting
  • solid_color.vs/.fs - Shaders for drawing something with a uniform color

Building this project

  1. Clone this repository
  2. Install GCC (on Windows, install MSYS2 first and install gcc within MSYS2)
  3. Install CMake
  4. Install the required libraries (gtkmm, OpenGL, libjpeg, GLEW, GLM, ASSIMP, Eigen, and Gurobi). Note: Gurobi is paid software, but offers free Academic licenses. You can also comment out the code that uses it and still run the simulation, but without MPC.
  5. Three resource files aren't included for the cone model, car model and cone stripe image. Create any valid replacement files and update the lines at the top of RaceWindow.cpp accordingly.
  6. Build the project with CMake. If not on Windows or if your Gurobi version isn't 8.1, update line 40 in CMakeLists.txt. Note that this was developed on Windows within a larger project, so there may be minor configuration issues you have to fix depending on your platform.
You can’t perform that action at this time.