This example shows how to use the `multirotor`

guidance model to simulate the change in state of a UAV due to a command input.

Create the multirotor guidance model.

Create a state structure. Specify the location in world coordinates.

Specify a control command, `u`

, that specified the roll and thrust of the multirotor.

Create a default environment without wind.

Compute the time derivative of the state given the current state, control command, and environment.

Simulate the UAV state using `ode45`

integration. The `y`

field outputs the multirotor UAV states as a 13-by-*n *matrix.

Plot the change in roll angle based on the simulation output. The roll angle (the X Euler angle) is the 9th row of the `simOut.y`

output.

Plot the change in the Y and Z positions. With the specified thrust and roll angle, the multirotor should fly over and lose some altitude. A positive value for Z is expected as positive Z is down.

You can also plot the multirotor trajectory using `plotTransforms`

. Create the translation and rotation vectors from the simulated state. Downsample (every 300th element) and transpose the `simOut`

elements, and convert the Euler angles to quaternions. Specify the mesh as the `multirotor.stl`

file and the positive Z-direction as `"down"`

. The displayed view shows the UAV translating in the Y-direction and losing altitude.