Here we take all the equations of motion we have derived and numerically integrate them to generate a simulation of the vehicle motion and dynamics.

*This post is the 3rd in a series on modeling and simulation of a quadcopter’s vehicle dynamics. The previous posts can be found here:*

- Modeling Vehicle Dynamics – Euler Angles
- Modeling Vehicle Dynamics – Quadcopter Equations of Motion
**Modeling Vehicle Dynamics – 6DOF Nonlinear Simulation**

## Programming a Simulation

I have created the simulation in a Jupyter notebook which uses Python code. You can download a copy of the notebook to make changes and try running it from my GitHub here:

#### Link to iPython Notebook

### Example Control Inputs:

In order for the simulation to show something interesting without any control laws in place, I have hard coded in a small set of propeller commands:

- For time = 0.0 – 10.0 seconds: Apply positive climb acceleration
- For time = 8.0 – 9.0 seconds: Apply forward pitch rate
- For time = 9.0 – 10.0 seconds: Remove forward pitch rate
- For time = 12.0 – 13.0 seconds: Apply negative pitch rate
- For time = 13.0 – 14.0 seconds: Remove negative pitch rate
- For time = 16.0 and after: Apply slight positive climb acceleration

After the simulation runs you can see the plots at the bottom of the notebook that show the effect these control inputs produce.

## Visualization

Below is a javascript visualization of the trajectory plotted in the above Jupyter Notebook.

*Use left click to rotate, middle click to zoom, and right click to pan (when camera is not locked)*

Hi there,

I was just wondering what would be the expression that would be used to calculate Torque. I mean the the below code returns a value of zero isn’t it?

def T(F,dx,dy):

# Returns torque about cg given thrust force and dx,dy distance from cg

#### PLACEHOLDER ####

return 0

I have been going through various sources to finalize on the expression. There are sources which gives expressions such as Torque = Cq * Omega^2 , where Cq is the torque coefficient and Omega the RPM (http://www.cs.cmu.edu/afs/cs.cmu.edu/academic/class/16311/www/s15/syllabus/ppp/Lec08-Control3.pdf) . I am bit confused there as the expression doesn’t contian information regards to the distance from CoM.