Mpu6050 accelerometer values perpendicular to gravity only

Hey guys, I have an mpu6050. Is there anyway to use Jeff rowbergs code, or any code, to get the values from linear motion only? No values from tilt or rotation of any kind. I can't think of a way to do it. But I'm sure there must be. Maybe if I find the accelration on an incline when theta is less than 1 degree. Any ideas would be very helpful. Thanks. SR

Basically I need the x and y values only, no z. I think that would make it a little easier to get since I also know I always want them perpendicular to earths gravity.

This is very hard, and the sensor is not that good. You will find more questions like that on this forum, and the answer is : no, the sensor drifts too much and is noisy. But some have tried it and the results were better than expected.

I tried to find a good projects, but did not find it. Sorry. Someone should create a page for this in the section.

Here are some links, I hope you can find better information.

Thanks for the links. That really helps. I also have the adxl345 sensor. Is that one better? What would be a good one to use?

CHRobotics has a very nice orientation sensor, and their library has a great overview on coordinate systems and how accelerometers and gyros work.

They also have the clearest explanation I've yet found of why it is usually not possible to use consumer-grade sensors to do what you want to do, except in certain circumstances.

You don't have to use the ADXL345. I would even prefer the MPU-6050 over the ADXL345. The MPU-6050 is a good modern sensor, and also cheap. A breakout board with this sensor inclusive shipping is only 3 dollars on Ebay.

The MEMS technology is an amazing technological achievement. I have a mouse with a mechanical accelerometer, that is so much worse. But MEMS sensors are noisy and they drift. They are not ideal, and are almost always used with software filter.

Caltoa, you seem like you know a lot about how these things work. I have a theory on how to make it work for what I am doing. But I am not very good at writing code yet. If I email you my idea could you help me with the code?

The accelerometer can measure acceleration. That's what it is for.

If you have a robot cart or something, and you are driving it around on a mostly level surface, and you want to measure it's acceleration in the horizontal direction, then mount the device on the robot and measure the acceleration in the x and y direction. Simple. You don't have to worry much about gravity or acceleration in the vertical direction or orientation of the entire robot for something which is moving around on the ground , as distinct from aircraft.

SteveRogers, I have no experience with distance calculation, and I don't understand what I read about it. If you have code, just copy it here between code tags.

The i2cdevlib 'dmp' example has a rate of 100Hz. That 100Hz pace is independent of the Arduino interrupts, because the sensor itself generates that 100Hz internally. I think those solid 100Hz samples is a good base to do the calculations. Let me think: the Gyro is not useful ? because of the linear motion ? So it is only the acceleration. Well, if you know the acceleration, you can calculate the speed and calculate the distance.

If the sensor is on a rail, the accelerometer is very sensitive for vibrations. Those will occur at a higher rate than 100Hz, so you can not keep up with that, since the sample rate is only 100Hz. Can you encapsulate the sensor in rubber or so, to reduce the short shocks, it might improve the accuracy.

Can the MPU6050 be programmed to output linear acceleration to one set of variables and angular acceleration to another set of variables? Basically I am hoping if I separate the two values, I can use just linear acceleration to calculate change in distance on a single axis. The mpu will be free floating and turning all over the place. I am trying to just get x and y values, 2d position, without roll or pitch values. I am hoping to essentially turn off the angular velocity/acceleration that would come from rotating the mpu and only get the linear values from sliding back and forth. Is there a way to do that with this or any other accelerometer? I have read a few papers on the subject and it seems like it is being done, but I can't find any code samples.

I'm not sure if I understand you, but did you try the 'dmp' example with the i2cdevlib mpu-6050 ? There are enough numbers I think.

On line 660 of this code, I found an x value that I think is linear only but I'm now sure how to print the variable to serial.

On line 754 is ‘x’ printed to the serial port. The ‘y’ and ‘z’ after that.
That is unfiltered raw data, and that is noisy and it will drift.