← Back to Projects

Matt Haywood

3D Drone Simulator

Using my 3D renderer, I programmed a 3D drone simulator, for simulating flight and navigation of a drone.

Physics and Gravity

I implemented an acceleration due to gravity by adding the following code:


    if self.drone.pos[1] <= 0:
			pass
		else:
			self.drone.vertical_velocity -= 1
			self.drone.decrease_altitude(-self.drone.vertical_velocity)

This code checks if the drone is above the ground and then decreases the vertical velocity by g - gravity. The drone is then decreased in altitude by that amount. It is also important to note that when the drone flies up, the function for flying up, resets the vertical velocity back to zero.

PID Controllers

PID controllers are an essential part of how a Drone flies. They are used to stabilise the flight, navigate the drone and used for autonomous waypoint following.

The following shows a PID controller used for the roll of the drone.



self.current_roll_error = self.roll

self.proportional = self.current_roll_error
self.integral += self.current_roll_error
self.differential = self.current_roll_error - self.prev_roll_error
		
ROLL_PID_OUTPUT = (self.proportional*self.p1_parameter) + (self.integral*self.i1_parameter)+(self.differential*self.d1_parameter)

print(ROLL_PID_OUTPUT)

self.tilt_drone_in_relation(ROLL_PID_OUTPUT, camera)

The video below shows the PID controller reacting to a perturbation in the roll axis.