# 2D quadcopter simulation position controller and PD controller

I'm a beginner in controls system, so if there is a nice tutorial on this, please let me know.

I have a Simulink model like the following: It takes roll and pitch commands and output velocities and positions. I want to create a PD controller so that the quadcopter in the simulation can move in a 10x10 meter shaped square(starting from bottom left corner) in a clock-wise direction.

I'm not sure how to go about this so I've been watching Vijay Kumar's Ariel Robotics lectures on Coursera and it seems like I need to create desired position, velocity, and acceleration at every time step which I think I can do (make a trapezoidal velocity profile and compute the rest).

Then Kumar talks about a nested control structure where there are two controllers: a position controller that takes in the desired position, velocity, and acceleration; and there is attitude controller which I believe is the one I have.

My question is how do I create a position controller? And is the position controller the one that converts my desired position,velocity, and acceleration into a roll/pitch command? • A similar question is asked in this thread. You send the quadrotor a desired position, and it calculates the required angles to reach to that point (at a desired speed or not) Jun 11 '17 at 19:17
• I saw that thread and kind of got it working. In coursera, Prof. Kumar seems to use all three desired values: position, velocity, and acceleration. Is this often the case? What are the benefits of using all three instead of just desired position values? Jun 12 '17 at 1:44
• It depends on the requirements of your problems. If you don't mind any boundary condition, you can simply ask the quad to reach from one position to another. But if you have any extra condition, you can implement that when reaching a particular point on the path the quad to be at a certain speed or acceleration. As you see, extra conditions harden the problem a little. Jun 12 '17 at 7:43

As you pointed out the typical control loop for a quadrotor is a nested one, with a position controller and a orientation controller (I prefer to use orientation instead of attitude to avoid confusion with altitude which happens more often than not). If you want to find some literature the set up you describe is often referred as P-VTOL , for Planar Vertical Take-Off and Landing.

In this case

is the position controller the one that converts my desired position,velocity, and acceleration into a roll/pitch command?

the answer is yes, the position controller generate the thrust magnitude and orientation to achieve good position tracking and the orientation controller is then responsible of tracking the orientation coming from the position controller.

That being said in the model you posted (first figure) you have as input pitch and roll commands, which is not possible in the planar case as in the plan there is only one angle. Usually for PVTOL system input are chosen as the total thrust ($F$) and the torque $\tau$ (as in your second figure) or as the two thrust $f_1,f_2$ produced by each propeller. The relation between the two is simple and linear

$$\begin{bmatrix} F \\ \tau \end{bmatrix} = \begin{bmatrix} 1 & 1 \\ d & -d\end{bmatrix} \begin{bmatrix}f_1 \\ f_2 \end{bmatrix}$$ Where $d$ is the distance between the propeller and the center of mass, and is assumed the same for all propellers.

Also note that from your second pictures it seems that you want to control at the same time 2 positions (y,z) and the orientation. This is impossible as the PVTOL is underactuated and only has 2 control inputs, you can either control the 2 positions but not the orientation or 1 poisiton and 1 orientation (usually z and $\phi$). The typical approach for near-hovering flight and non aggressive maneuvers is to give desired trajectory for the 2 position.

how do I create a position controller?

To create a controller you need to consider your system model, ie the mapping between your control input and your state. The trick for quadrotor is that the total thrust is exerted along a fixed direction in the body frame, so to change the orientation of the thrust you need to change the orientation.

Here I will sketch the basic rationals behind the position controller. Consider that you have an error in position along both axes $e_z$ and $e_y$ to make it disappear you need to move your platform in the direction defined by the vector $\begin{bmatrix} e_y \\ e_z \end{bmatrix}$, this gives you the desired orientation of your total thrust vector, ie z-axis of the PVTOL, that needs to be fed to the orientation controller which will compute $\tau$. The magnitude of the total thrust is usually regulated via PD on the errors, this directly defines $F$.