# Setting initial conditions in a quadcopter numerical simulation

I am new to robotics, and currently trying to develop a purely numerical simulation of a quadcopter. As I understand, the problem of quadcopter control includes take-off control, hover stabilization and landing. However, I am only working with navigation control right now, foregoing take-off and landing. I am imagining a scenario wherein the quadcopter is already off the ground at a certain height (is that called hovering?) and it has to follow a trajectory in the presence of simulated noise (which I intend to introduce through random deviations in the angular orientations of the quadcopter) . The trajectory is nothing but a finely discretized curve in XYZ space (with a constant Z for now).

I am trying to build on this tutorial. It's a highly simplified model, just taking into account the thrust, external torques and frictional forces on the quadcopter. I have two questions here: 1. Is my setup even feasible just to demonstrate a proof of concept fuzzy control? 2. In this setup, and according to the initial condition mentioned above, I understand that if the quadcopter already has to be at a certain height h, then the net thrust in Z direction should balance the gravitational force. However, that would be the case at any height above the ground. But to get it to height h, how do I calculate the angular velocities in body frame that are required to keep it at that height? I am asking this because by means of affecting these velocities I'll be able to add some noise to the system and then work my way from there.

The platform for this numerical simulation is to be Matlab, if that information adds anything. I am planning to use only Matlab scripts for now, and not Simulink. As for my knowledge of dynamic systems, I understand basics of linear and rotational kinematics. I have only worked with implementing text book algorithms in a standard computer science course, and that's as far as my programming experience goes.

• Can you clarify the following questions [they will guide answer posters towards a correct approach and will eliminate unnecessary basic stuff]. 1) your knowledge on dynamic systems (Newton's laws) 2) your level of experience in programming / solving differential equations 3) will you use simulink or only matlab scripts? Oct 17 '17 at 19:01
• "to get it to height h, how do I calculate the angular velocities in body frame that are required to keep it at that height?" You need a trim state (a set of states where derivatives are zero). And so you don't need angular velocities but angles themselves (roll and pitch and yaw). Finding trim state is kind of an optimization problem with several parameters. (Which is the core of the question Actually) Oct 17 '17 at 19:20
• @GürkanÇetin made the necessary edits, thanks! Oct 18 '17 at 7:32

Here's a quick answer. We can work on it to improve.

What you are searching for is the "trim state" of the vehicle for a given height and velocity (or hover). Methodologies for finding trim state is given in textbooks as "trim theory".

There are a few very general trim search methods:

1) solving an optimization problem: iteratively trying several values for states (attitudes, linear velocities, control positions, etc) Matlab has some built in functions for non linear optimization. Namely, fminsearch, fmincon, fsolve, etc. of course, you could write your own optimization script as well. Not too difficult, and definitely worth the effort.

2) using a gentle autopilot to converge on the desired flight conditions (requires a working flight controller, at least a SAS and an attitude hold mode)