ELECINF344/381

Interactive web site of Télécom ParisTech's ELECINF344/ELECINF381 Robotics and Embedded Systems classes (a.k.a. ROSE, 2012 session).

Categories

A complementary filter for a IMU

I recently talked about getting informations from the FreeIMU board. This gives us raw data from acceleroscope and gyroscope. Both of them can give some informations about the attitude (pitch, roll) of the board, but they both have some flaws, even if they are perfect sensors (which they aren’t):

The gyroscope only gives the rotation speed, so the software has to integrates the value, which means there will most likely have integration errors, and thus a drift.
The accelerometer gives the acceleration + g, so when the device is not moving, we get g, which gives us pitch and roll. But when there is some acceleration, the values can’t be used.
The gyroscope’s drift is mostly slow, whereas there is an acceleration only on short period of times, so we can combine both of those sensors to get the actual attitude.

One usual way to merge them is to use a Kalman filter. It is a very effective way of merging, and the result can be quite incredible. But it is really complicated to understand and implement. The theory behind it assumes the knowledge of physics of the problem, which doesn’t help its complexity. It actually works without this knowledge, so it’s still a possible solution.

Anyway, as I mentioned before, the noise from the gyroscope and from the accelerometer is not a white noise, but has some specific spectrum, and gyroscope and accelerometer’s noises have quite a complementary spectrum, which leads to another possible filter to merge gyroscope and accelerometer informations (it can also filter magnetometer informations actually): It’s called a complementary filter.

The idea is to apply a low-pass filter on accelerometer, since its values are correct only at low frequencies, and add the complementary (ie the sum of the high-pass filter’s transfer function and the one of the low-pass filter is equal to one) on gyroscope’s data. That way, we filter out high frequency noise of the accelerometer, and low frequency noise of the gyroscope.

So, that’s the theory. To implement such a thing, an easy way we’ve chosen is to use an exponential filter: v_{n+1} = v_n*t + x_n*(1-t), where t is a number between 0 and 1. I’ve chosen t = 10/11 for a sensor frequency of 60Hz. The complementary filter is w_n = x_n-v_{n+1}.

Again, to have as simple code as possible, the current implementation doesn’t even use a FQA, which obviously leads to problems on some specific angles. For our bot, this is no problem, since the range of possible pitch and roll are short, we can take care of being in a safe area.

Today, we also got the Kalman filter to work, so we could compare both approaches. Even thoguh Kalman is still working better, the complementary filter is working properly, and should be enough to control the bot properly, at a way lower cpu processing cost.

Pierre-Hugues Husson

Ball-E’s new PSSCs

Through yesterday’s presentation and teachers’ comments, we have defined our new Project Specific Success Criteria.

Here they are :

Work Manager Deadline
Kalman filter working Otilia 04/24/2012
Complementary filter working Pierre-Hugues 04/24/2012
ADC to measure battery level working Scott 04/28/2012
Zigbee working Otilia 04/28/2012
Wi-fi working Matthieu 04/24/2012
H bridges Pierre-Hugues 04/23/2012
Motors’ piloting Pierre-Hugues 04/24/2012
Fixing PCB/IMU/Batteries Matthieu 04/25/2012
Cooling circuit Mattthieu 04/25/2012
Ball-E is standing Scott 04/27/2012
Ball-E moves the way we want Scott 05/02/2012
We can pilot Ball-E with an Android smartphone Matthieu 05/04/2012

Yesterday, I also managed to make the leds blink on our Ball-E board, let’s begin the Wi-fi !

Matthieu Tardivon

Talking to the FreeIMU

So we recently received the FreeIMU board we will be using for our Ball-E.

As we didn’t have our PCBs ready at that moment, I started wiring the FreeIMU board on a STM32F4-Discovery card I could get, which is using the same serie of STM32F4 processors as our final card will. As stronly recommended by Sam, we’re using ChibiOS, which helps quite a lot the development, since all drivers are already available.

The FreeIMU board is a 10-axis unit. We don’t care about pressure, so we only use the magnetometer (HMC-5883) and gyroscope/accelerometer chips(MPU-6050). The gyroscope/accelerometer chip is rather complex and has several really interesting features:

  • The chip has a built-in FIFO module. Basically you configure the device, and then you just read all infos from the FIFO register. It even supports burst reads, so you can make a single I2C read to retrieve all the informations.
  • It has both a master and a slave I2C bus. The slave is obviously the way to get sensors informations to the microcontroller. The master bus is wired to the HMC-5883, so you can set-up the MPU-6050 to read magnetometer values on its own, and then just keep reading the FIFO to get all the infos you need !

We needed the sensors working quickly, so I chose to bypass this I2C master feature, as the MPU-6050 allows us to, and so the current code speaks directly to the HMC-5883 magnetometer.

I hit mainly two problems concerning the retrieval of those datas:

  • The MPU-6050 needs to have its clock source setted before doing anything, while the register address of this choice is high. That was a problem not obvious to find, since the infos available doesn’t seem to mention this problem. What happened was that the chip wasn’t working on first power-on, but after reset it’s working.
  • The FreeIMU board doesn’t have a RESET pin, so it might happen that the chip is in an appropriate state on reboot. It’s especially true because the current code is polling informations from the board, so the I2C bus is always working. This means that a reset was most likely in a middle of a communication. A fix to that problem is to fake the end of the I2C transmission: put SDA up, and toggle SCL enough times (10 times should be enough.)

So now we have a working board to test various filters on the sensors, to get proper positioning information.

Pierre-Hugues Husson