DIY Quadcopter – Vibrations & gyroscope

I’m still working on my quadcopter with a DIY flight controller based on an arduino chip. After a lot of tests and mainly (to not say only) crashes I realised that my gyroscope datas were unstable, here is how i try to sort it out !

In a previous article, I explained why we need a gyroscope and an accelerometer on a quadcopter to determine its attitude (pitch, roll and maybe yaw). In this article, I will explain how to filter the raw datas coming from the gyroscope in order to use in a fusing algorithm.

yet an other crash !

yet an other crash !

Find and cancel the offset

In order to understand what is happening I wrote a code that sends raw gyro datas to my computer here is the result :

gyro_noise

The drone was not moving so what you see is only noise. The value is supposed to be 0 on each axis. When you see this graph, you quickly realize that each axis is staying around a specific value, this is the offset. Sensors are not perfect and their zero is not the real zero.

Here is my simple solution :

    //remove offset
    gyro[0] = gyro[0] + 236;
    gyro[1] = gyro[1] - 117;
    gyro[2] = gyro[2] - 296;

The values are simply the result of an average of 500 values on each axis.

offset removed

offset removed

The result is better but we still have noise. This is a simple solution that can only apply to my sensor at this specific time. The offset can move and is different from one sensor to an other. A more complex way would be to calibrate it at the beginning of each flight.

Reducing the noise

There is noise in the reading, not only because of the sensor itself but also because there are a lot of vibrations on board ! With my tests I realized that the motors tend to change the reading from my gyroscope. This is what you can see on the next graph, when the motors are not turning there is almost no noise, however when the motors are spinning there is way more noise that needs to be filtered.

Reading from the gyroscope (blue) and power on the motor (yellow)

Reading from the gyroscope (blue) and power on the motor (yellow)

Continue reading

DIY quadcopter : get the attitude

In my previous article about my quadcopter, I described my project. Now comes the first step where I explain how to get pitch, roll and yaw information from my inertial measurement unit (IMU) on my Arduino card.

For this part, I will be only using the accelerometer and the gyroscope of my MPU9150 (so it’s the same as a MPU6150).

Zoom on the MPU9150 which is the IMU used in my project

Zoom on the MPU9150, the IMU used on my quadcopter

We’ll first see why we need both an accelerometer and a gyroscope, then I’ll give you my wiring and finally I will talk quickly about the fusion algorithm.

Why do we need accelerometer AND gyroscope ?

To answer to this question, you need to understand what kind of information is given by the accelerometer and the gyroscope.

The accelerometer will measure acceleration, and in our case we are interested by the acceleration caused by gravity. If your sensor is not moving it will give you a 3D vector pointing at the ground, so you can know your attitude (pitch, roll and yaw). This is what is used in your smartphone to rotate what is displayed on your screen when you tilt your phone. Unfortunately, an accelerometer is sensible to movement and vibrations which are two elements that you have on a drone so you can’t use it alone.

The gyroscope will measure an angle velocity on every axis. By integrating this, you will be able to know what is your attitude. But you have to know your first attitude at the beginning (either by starting on a known position or by using data from another system like an accelerometer of course !). The gyroscope comes with another problem : it tends to drift over time so you need to reset its position from time to time.

This graph shows you calculated roll of my sensor if you only use an accelerometer or a gyroscope :

Gyroscope versus accelerometer

Gyroscope versus accelerometer

You can see that the accelerometer is noisy and that the gyroscope drift at the end. The point of a fusion algorithm is to get the advantages of both sensors in order to have a nice attitude indication.

Continue reading

DIY Drone with Arduino

While I am still waiting for the pieces for my alarm clock to arrive, I’m continuing to develop my long-term project that I am going to present on this article.

Last summer I decided to build myself a drone : a quadcopter to be precise. My main goal is to create my own flight controller with an arduino card. Here is what it looks like now :

General view of the drone

General view of the drone

I didn’t want to spent much time choosing the motors or propellers so I bought a kit on Hobbyking with the frame, the motors and ESC (motor controllers) so I knew that there would be no dimension problem.

As long as electronics components are concerned, I chose to have a cheap alternate of the Arduino Uno (I know shame on me), and the MPU9150 as “attitude sensor”. I already had a Remote Controller (RX/TX).

The MPU9150 is 9 degrees of liberty sensor that is in fact composed of 3 sensors :

  • a 3-axis accelerometer
  • a 3-axis gyroscope
  • a 3-axis magnetometer, which is the equivalent of a compass
Zoom on the MPU9150 which is the IMU used in my project

Zoom on the MPU9150 which is the IMU used in my project

My goal with this project is to program and understand the process of flight stabilisation. The first step will be to change the data from IMU into a pitch, roll and yaw indication.