Smoothing question (getEstimatedAttitude())

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
sakumar
Posts: 7
Joined: Wed Apr 27, 2011 6:43 pm

Smoothing question (getEstimatedAttitude())

Post by sakumar »

Hi,

I have a question about the code to smoothen the accelerometer raw data in the function getEstimatedAttitude()

The following line of code:
for (axis=0;axis<3;axis++) accSmooth[axis] =(accSmooth[axis]*7+accADC[axis]+4)/8;

It appears that we are weighting the previous data 7:1 with the current data and that is fine.

What I don't understand is the +4 thus adding .5 to the smoothened value. Is that emprical, or am I missing something?

Thanks,
Sanjaya

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Smoothing question (getEstimatedAttitude())

Post by Alexinparis »

it's a better integer math accuracy:

example:

without +4
7/8 = 0
8/8 = 1
15/8 = 1 => real middle value = (15+8)/2 = 11.5
16/8 = 2

with +4
(3+4)/8 = 0
(4+4)/8 = 1
(11+4/8) = 1 = real middle value = (4+11)/2 = 7.5
(12+4)/8 = 2

sakumar
Posts: 7
Joined: Wed Apr 27, 2011 6:43 pm

Re: Smoothing question (getEstimatedAttitude())

Post by sakumar »

Thanks! In other words, the code is rounding up in integer math.

I was looking at this code because I was trying to get better behavior out of the ADXL345. My version seems to be affected by vibration.

I built the "classic" WM+NK and really liked the results. I thought I would build a second one with the Sparkfun ITG3200/ADXL345 combo board but have been pretty disappointed by the ADXL345 so far.

On rcgroups I saw that point65 had presented some interesting data confirming that the ADXL345 is sensitive to vibration. I observed from his data that the readings were oscillating around the mean so I thought I'd try more aggressive smoothing to see if it gets any better.

Still in progress but thanks for your help.

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Smoothing question (getEstimatedAttitude())

Post by Alexinparis »

Honestly, the ADXL345 is one of the worse acc you can get.
It is very noisy, even in a quiet environment.
The BMA180 is far superior.

sakumar
Posts: 7
Joined: Wed Apr 27, 2011 6:43 pm

Re: Smoothing question (getEstimatedAttitude())

Post by sakumar »

I realize that now! I wish I had read the rcgroups thread more carefully since other people have run into the same issue with the ADXL345. The sparkfun combo board (SEN-10121) looked really attractive. I figured I could run the I2C at a faster speed and have a more compact and responsive solution as compared to WMP+NK. But this acc has been a real disappointment.

I'll look into the the BMA180.

Thanks for your help (and code!).

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Smoothing question (getEstimatedAttitude())

Post by ziss_dm »

Hi sakumar,
I don't think that ADXL ACC is so bad ;), but there are couple of issues which should be sorted:
1) It is better to install filtering capacitors as per datasheet (in case you have noise from power supply):
A 1 μF tantalum capacitor (CS) at VS and a 0.1 μF ceramic capacitor (CI/O) at VDD I/O placed close to the ADXL345 supply pins is recommended to adequately decouple the accelerometer from noise on the power supply. If additional decoupling is necessary, a resistor or ferrite bead, no larger than 100 Ω, in series with VS may be helpful. Additionally, increasing the bypass capacitance on VS to a 10 μF tantalum capacitor in parallel with a 0.1 μF ceramic capacitor may also improve noise.

2) The ADXL does not have configurable Low Pass Filter, but it's bandwidth is tied up to the sampling rate. The default 200Hz sampling rate is way too high (for ACC) and has bandwidth 100Hz, which is also too high. You can try this initialization procedure:

Code: Select all

void i2c_ACC_init () {
  delay(10);
  i2c_rep_start(0xA6+0);      // I2C write direction
  i2c_write(0x2D);            // register 2D Power CTRL
  i2c_write(1<<3);            // Set measure bit 3 on
  i2c_rep_start(0xA6+0);      // I2C write direction
  i2c_write(0x31);            // DATA_FORMAT register
  i2c_write(0x0B);            // Set bits 3(full range) and 1 0 on (+/- 16g-range)
  i2c_rep_start(0xA6+0);      // I2C write direction
  i2c_write(0x2C);            // BW_RATE
  //i2c_write(8+2+1);           // 200Hz sampling (see table 5 of the spec)
  i2c_write(8+2);             // 100Hz sampling (see table 5 of the spec)
  //i2c_write(8+1);             // 50Hz sampling (see table 5 of the spec)
  //i2c_write(8);               // 25Hz sampling (see table 5 of the spec)
  //i2c_write(4+2);             // 6.25Hz sampling (see table 5 of the spec)
  //i2c_write(4+2+1);           // 12.5Hz sampling (see table 5 of the spec)

  acc_1G = 260;
  acc_25deg = 106; // = acc_1G * sin(25 deg)
  accPresent = 1;
}


regards,
ziss_dm

sakumar
Posts: 7
Joined: Wed Apr 27, 2011 6:43 pm

Re: Smoothing question (getEstimatedAttitude())

Post by sakumar »

Ziss_dm,

Thanks for the suggestions. Since I have the breakout board (http://www.sparkfun.com/datasheets/Sens ... al-v10.pdf) I believe it shows the 0.1μF capacitor -- I am not sure how I'd add the other capacitor (software guy, not hardware :) ).

I'll try out the software initialization changes and see how it goes.

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Smoothing question (getEstimatedAttitude())

Post by ziss_dm »

Hi sakumar,
By datasheet, it shuould be like this http://www.sparkfun.com/datasheets/Sens ... rd-v10.pdf.
It is not extremelly difficult to solder it, I will post picture later, if you are interested.

regards,
ziss_dm

sakumar
Posts: 7
Joined: Wed Apr 27, 2011 6:43 pm

Re: Smoothing question (getEstimatedAttitude())

Post by sakumar »

Hi Ziss_dm,

Sure. Please post the changes I'd need to make to the sparkfun board. I'd really appreciate it.

Thanks.

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Smoothing question (getEstimatedAttitude())

Post by ziss_dm »

Hi sakumar,

I have posted pictures here SF 6 Degrees of Freedom ITG3200/ADXL345 Mods

regards,
ziss_dm

sakumar
Posts: 7
Joined: Wed Apr 27, 2011 6:43 pm

Re: Smoothing question (getEstimatedAttitude())

Post by sakumar »

Thanks ziss_dm. I'll go ahead and solder the capacitor and see if there is any improvement. I've already tried your code modifications (reduce sampling, change 1g value).

In my case, for static I don't see any noise. Only when I start up the motors (about 25%), the ACC seems to go haywire. I think the problem is real vibrations. I'm also going to try rubber dampers to isolate the controller board -- someone on rcgroups suggested using servo mount grommets. Let's see how that goes.

miniquad
Posts: 65
Joined: Wed Mar 23, 2011 8:17 pm

Re: Smoothing question (getEstimatedAttitude())

Post by miniquad »

Isolating the sensors from vibration results in improved stability of the flight. You may also consider soft foam tapes to attach the sensor/controller board to the quad body which blocks body vibration to be transmitted to the sensors by a big margin.

sakumar
Posts: 7
Joined: Wed Apr 27, 2011 6:43 pm

Re: Smoothing question (getEstimatedAttitude())

Post by sakumar »

Just a follow up to say that I tuned the ADXL345 with the suggestions here and it improved, but didn't seem as good as the nunchuck.

Based on Alex's suggestion, I got the BMA180 (sparkfun breakout board) and, while it took some fine-tuning, this sensor produces a very nice stable mode.

Post Reply