# What is required to get the roll, pitch and yaw of an aerial vehicle?

TL, DR : What is the method(in terms of sensors and algorithm) to get the roll, pitch and yaw of an aircraft at any instant.

I am planning to build a hobby aircraft. I am so confused about which kind of sensors should I use and how to use them in order to get the roll, pitch and yaw angles of the aircraft.

I think I also have some problems about understanding the concept.

What are the ways/methods/agents to get the orientation of an aircraft at any instant?

In some sources there is something going on as the importance of order of the application of roll,pitch and yaw. But I cannot understand why this is related.

I have used accelerometer values by inputting them into some formulas on the internet(which everybody uses but nobody explains well) to get the roll and pitch values. However could not understand how to manipulate them in order to meet my requirements.

I also have basic understanding about what a gyroscope is.

Thanks in advance.

• "some formulas on the internet(which everybody uses but nobody explains well) to get the roll and pitch values" I would start at trying to understand those formula's. Can you put up those formula's here with the question? – vvy Jul 26 at 19:01
• @vvy yes I know but I realy am bad at 3d geometric imagination. Do you have any suggestions that I can use to visualize such vectors/axes ? – muyustan Jul 26 at 19:03
• The question you've asked is very general. Its a good idea to start with a smaller question. Usually, gyro rate sensors are used for RPY(rate,pitch,yaw). Might be helpful to understand what is a raw output of a gyro and then the transformation to obtain the quantity of interest (here it's RPY). Those equations you're referring to would probably explain this transformation. – vvy Jul 26 at 19:12
• @vvy I am more clear about gyro calculations than accelemoter actualy, I know as follows(please revise and give me feedback about it) : gyro measures the rotation speed about an axis, so we can get the gyro readings(dps) over a short time(dt) duration and add to the p/r/y variable as dps*dt - an approximation of integartion -. So by this, with respect to an inital attitude we can have a relative p,r,y angles. But this has two disadvantages, the drift issue(errors cumulatively increases because of integration) and the problem mentioned here : youtu.be/4BoIE8YQwM8?t=596 – muyustan Jul 26 at 19:20
• @vvy so I am not a total stranger, have the basics somehow but need to relate each of them. – muyustan Jul 26 at 19:21

## 2 Answers

The only sustainable long-term acceleration (for anything terrestrial) is gravity. The Madgwick algorithm uses gravity and a magnetometer to correct gyro drift.

Watch the video, then head to the site - there are open-source implementations already written for you in Matlab, C, and C#.

• Thanks! I will have a look at the links you shared. Could you please somehow describe what you wanted to mean by "terrestrial"? I am not a native speaker and that word is hard to understand for me. – muyustan Jul 27 at 20:00
• @muyustan - Basically rockets. I think it's easiest to think of the Madgwick filter as a low-pass filter on the accelerometer: over the long-term (very low frequency), the average of your accelerometer readings should be only the gravity vector, and you know it points down. The exception is if you were able to maintain an acceleration for a long period of time, such as ballistic missiles, or in unusual applications like a centrifuge or something similar. But for quadcopters, vehicles, etc., your average acceleration is only gravity. You can see the effect when the IMU converges in the video. – Chuck Jul 27 at 20:08

Use mpu6050 gyroscope module and optional compass module to know where is the North. Mpu6050 can be calibrated by itself, but you have to write a code that calibrates readings with mpu6050's accelerometer sensor(using atan2 function)