How to Write your own Flight Controller Software — Part 5

Calculating Roll, Pitch and Yaw from IMU Rates

David Such
24 min readJan 2, 2022

There are a number of libraries that make working with the LSM9DS1 IMU (Inertial Measurement Unit) easy. In Part 5 of our series on writing your own flight controller software we will focus on the IMU and in particular explain the best ways to convert the gyro rate and accelerometer force data to a roll and pitch angle. The yaw angle is then calculated using the pitch and roll and magnetometer data. This discussion, is in the context of building a drone flight controller based on the Arduino Nano 33 BLE.

Our follow up part in this series will explain how to calibrate the LSM9DS1 IMU and store the results plus use sensor fusion to improve the accuracy of the angles and overcome sensor shortfalls.

1.0 The Easy Way

If you are using an Arduino Nano 33 BLE and want a library that just works, then there are lots of those available (see Section 7.0 below). As we are writing our own flight controller code, we needed to understand what data we were being fed. It is like wine making where quality wine starts with good grapes. You can’t make a great wine from rubbish grapes and similarly a good…

--

--

David Such

Reefwing Software · Embedded Systems Engineer · iOS & AI Development · Robotics · Drones · Arduino · Raspberry Pi · Flight Control