Page 1 of 2

MPU-6050 Programming

Unread postPosted:Sat May 17, 2014 3:05 pm
by DeWitt
After some stumbling around in the dark until I found a USB driver .inf file that would let Windows 8.1 talk to the Arduino, I was able to get kit #3 working with the megalogger code.  I noticed that it only polls the accelerometer and gyro every 200 msec.  If I read the firmware code for the MPU-6050 correctly, you don't have the low pass filter activated so I could poll the device much faster than every 200msec.  By the way, shouldn't the LPF be set to twice the sampling frequency to reduce aliasing of higher frequencies? 

The MPU-6050 chip seems to have a lot of capability that isn't being used currently, including the ability to attach a 3 axis magnetometer for 9 axis motion detection and on board sensor fusion calculation.

Re: MPU-6050 Programming

Unread postPosted:Sat May 17, 2014 7:22 pm
by DeWitt
And speaking of the accelerometer and gyro data, on my car anyway (2011 Ford Mustang), the OBDII plug is not a good mounting place.  The plug is not attached firmly and it's not vertical.  That means lots of vibration, causing lots of noise in the output and the requirement to rotate the axis data to put it in the correct relation to the vehicle frame of reference.  It's also too close to my left leg, so it's likely to get moved when I move my foot on and off the clutch.  I'm planning on buying a low profile extension cable and mounting the adapter somewhere else more firmly.

All that being said, I'm pleased so far with the device and its capabilities.  I haven't done any serious programming in ages, and never in C++ so there's going to be a steep learning curve.

Re: MPU-6050 Programming

Unread postPosted:Mon May 19, 2014 3:09 am
by Grey.CC
Welcome DeWitt,

You could check this library first.
https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050
I think it will be helpful.

Re: MPU-6050 Programming

Unread postPosted:Mon May 19, 2014 7:43 pm
by DeWitt
[quote="Grey"]
Welcome DeWitt,

You could check this library first.
https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050
I think it will be helpful.
[/quote]

Thanks.  I found that link earlier.  Unfortunately, the programs appear to depend at least somewhat on having access to the interrupt pin on the MPU6050, which is not available with the Freematics OBDII. It's going to take some studying.

Right now, I need to work on vibration isolation.  I glued the OBDII socket on the car to the frame.  It helped a little, especially with rotation noise.  But there's still a massive increase in accelerometer noise when the car is moving.  The noise on the vertical accelerometer axis increases by a full order of magnitude when the car is moving compared to when it's stopped, standard deviation stopped = 0.0056g, moving = 0.0569g.  It looks like attaching the sensor board firmly to the OBDII plug was not the best idea.

Re: MPU-6050 Programming

Unread postPosted:Tue May 20, 2014 4:05 pm
by orpheus88
[quote="DeWitt"]
And speaking of the accelerometer and gyro data, on my car anyway (2011 Ford Mustang), the OBDII plug is not a good mounting place.  The plug is not attached firmly and it's not vertical.  That means lots of vibration, causing lots of noise in the output and the requirement to rotate the axis data to put it in the correct relation to the vehicle frame of reference.  It's also too close to my left leg, so it's likely to get moved when I move my foot on and off the clutch.  I'm planning on buying a low profile extension cable and mounting the adapter somewhere else more firmly.

All that being said, I'm pleased so far with the device and its capabilities.  I haven't done any serious programming in ages, and never in C++ so there's going to be a steep learning curve.
[/quote]
With my Freematics V2 came an OBD extension cable with a flat cord, works rather nice and since it also has GPS included, having it under the dash wasn't really a good solution anyways.
About the speed,  for me ACC-Data is the least interesting data, but 5 times a second sounds not that bad to me. If you want it to poll more often you probably have to strip some stuff that you don't need, like logging or streaming. Also from looking at the code it looks like dfrobot polling is done only, when he is waiting for OBD data, so you could remove that if-clause  (Lines 253-257 in megalogger.ino) and it should poll (maybe just a bit) more often.

Re: MPU-6050 Programming

Unread postPosted:Thu May 22, 2014 3:28 pm
by DeWitt
I changed ACC_DATA_Interval from 200 to 100 milliseconds and it does report at ~10Hz.  However, I now get OBD data from the Teir 1 PID's in blocks of four points about 400 msec apart with gaps of 8 seconds between blocks, which seems excessive.  For Tier 2 PID's I get one point every 8 seconds and for Tier 3 it's one point every 36 seconds.

The vibration noise problem seems to be much better even when the LPF isn't set to a lower frequency.  I also had a large offset appear in the X-axis accelerometer.  I used the accelerometer self test command, MPU6050_write_reg (MPU6050_ACCEL_SELFTEST, 1);, which seemed to fix the problem.

Re: MPU-6050 Programming

Unread postPosted:Thu May 22, 2014 5:35 pm
by DeWitt
Curiouser and curiouser.  I uncommented line 39 in megalogger config.h : [code]#define OBD_MIN_INTERVAL 200 /* ms */ [/code]and things got worse.  The time between Tier 1 OBD points in the cluster of four increased from ~0.3 sec to ~1.2 sec but the time between clusters remained ~8 sec.  Tier 2 interval increased to 12 sec and Tier 3 to ~48 sec.  Back to square one.

Re: MPU-6050 Programming

Unread postPosted:Thu May 22, 2014 5:59 pm
by DeWitt
I now think the reduction in accelerometer and gyro noise was related to opening and closing the OBD-II adapter box.  Either something wasn't tight or it was too tight.  I see no difference after changing the LPF setting.

Re: MPU-6050 Programming

Unread postPosted:Sat May 24, 2014 1:07 pm
by DeWitt
[quote="stanleyhuang"]
Reading from MPU6050 should really not take so much processor time. Maybe you can use simpler code to access MPU6050 alone to see how fast you can get.
[/quote]

I'm pretty sure the problem is a request for a PID that isn't available, specifically MAP.  I've deleted it from the Tier 2 list, line 68 in megalogger.ino.  I'll test it and see if that fixes the problem.

Edit:  Yep, that was it.  The 8 seconds was probably a function of the OBD long time out period of 7 seconds.

Re: MPU-6050 Programming

Unread postPosted:Fri Mar 25, 2016 5:41 pm
by ben amara ramzi
HI,
I need to know if there is a solution to get displcaement in mm from mpu6050.
I know that using kalman filter we can have accurate angular position; but I need to have displcament or position of my object not the orientation .
Thank you for your help!