I wanted to see if I could get a neural network to learn to fly a drone. To save money, I decided to test this in a simulation first. I had always wanted to implement a physics engine. Implementing Newtonian motion and collisions was quite straight forward; however, when implementing the torque and rotation calculations for the physics engine I discovered “quaternions” - which are far less straight forward…

diagram

I implemented a physics engine in python, in an object oriented style. The drone was an object with properties like position, velocity, orientation, spin. The drone object could receive inputs to drive each of the motors - this is what the neural network would use to control the drone.

I used the “PyOpenGL” library to display the 3D environment and the drone within it.