Hello Everyone
I have an ADXL345 , and i need to use it to measure the distance i traveled.
I know that i need to integrate the data of the Accelerometer twice to get the distance.
Has anyone done this before ???
Hello Everyone
I have an ADXL345 , and i need to use it to measure the distance i traveled.
I know that i need to integrate the data of the Accelerometer twice to get the distance.
Has anyone done this before ???
Thats not really what this sensor is for. It measures angular tilt and acceleration along the axes. If it is static i.e. on a table, or moving at a constant speed it will not tell you anything about the motion.
Maybe a GPS would be the solution for distance traveled?
I know that i need to integrate the data of the Accelerometer twice to get the distance.
Experiment with your sensor for a bit, and it should become clear why this is not really possible.
Are you guys sure that i couldn't use an ADXL345 to get distance ????
I have read that its possible but the problem would be in the accumulated error that would rise.
Any help would be highly anticipated guysss
bakkar90:
@arbutus @jremingtonAre you guys sure that i couldn't use an ADXL345 to get distance ????
I have read that its possible but the problem would be in the accumulated error that would rise.
That is very true.
you do not need to integrate twice, you can do it in one step. Newton mechanics states:
S = 0.5 * a * t^2
First step is to determine the cummulative acceleration.
You must add the X Y and Z acceleration as vectors
Than multiply that with the duration of the measurement squared (be sure to use seconds)
float sum = 0;
void setup()
{
//....
lastTime = millis();
}
void loop()
{
// MEASUREMENTS
float x = getX(); // you know how to do that
float y = getY();
float z = getZ();
// MATH
float a = sqrt(x*x + y*y + z*z); // add as a vector
currentTime = millis();
sum = 0.5 * a * (currentTime - lastTime) * (currentTime - lastTime) / 1e6; // 1e6 is correction to convert millis to seconds
lastTime = currentTime; // remember time for next round
// DISPLAY
Sertial.println(sum, 4); // 4 decimals
}
That should get you up and running.
The problems you will encounter are the noise in the accelerometer readings, and the need to subtract acceleration due to gravity, which normally swamps any acceleration measurements you are likely to want to integrate to obtain the distance traveled.
Integrating twice is going to make the noise problem worse.
And the other issue, is there is nothing in the process to cause the error to be corrected.
If you are moving at a constant speed, the acceration will be zero, thats what the accelerometer will tell you, and if your speed is wrong at the start of a period of constant speed travel, it will continue to be wrong, and the distance integrated by the second integration will just get worse and worse.
It is possible to use an accelerometer AND a gps to get a solution which is going to be more correct. The accelerometer will detect rapid changes faster than the GPS will, but the GPS solution will, over time, correct the speed and displacement errors from the accelerometer.
You certainly can use an ADXL345 to measure distances, I wrote about it on my blog. I measured the vertical distance traveled by an elevator using acceleration and numerical integration.
Let me know if you have any questions!
I measured the vertical distance traveled by an elevator using acceleration and numerical integration.
For the more general 3D case, subtracting the acceleration due to gravity introduces major errors, which quickly makes the entire approach unworkable.
One of several major problems lies in determining the direction of the gravity vector with respect to the accelerometer frame of reference.