Im currently working on a project that uses IMU to display on the screen: accelerometer data, gyro data.
Since I was also asked to display the displacement value of the IMU , can anyone guide me how I would start on it? Upon reading other forum, most was saying was to double integrate the accelerometer data. Does that mean I also need the time values or not?
daisygrm:
Upon reading other forum, most was saying was to double integrate the accelerometer data.
Yes, that's what you need to do. The first integral gives you speed, and the second integral gives you displacement. Note that these will become increasingly inaccurate over time.
daisygrm:
Does that mean I also need the time values or not?
Research the meaning of integration. It's straight forward once you have got the concept.
Is there any arduino code that can do the integration for me? Or do I have to come with a formula to actually integrate the acceleration? I have also read that euler's method can also be used. Is that true?
daisygrm:
Is there any arduino code that can do the integration for me?
No.
daisygrm:
Or do I have to come with a formula to actually integrate the acceleration?
Well, mainly you need to understand what integration is and then code it in your application. It can be described by a formula, but you don't need to deal with any maths equations to understand it or write the code. You just need to understand the relationship between acceleration, speed and displacement and how you can integrate acceleration to get speed, and integrate speed to get displacement.
Does that mean I also need the time values or not?
You need to know the amount of time which separates each reading of the accelerometer. Typically you would sample it at a constant rate (e.g once per second or 100 times per second), which really simplifies the calculation of the integrals to produce the velocity and displacement, but as long as you know what each interval is they don't have to be constant.
Pete
Well, you need to understand what integration is and then code it in your application
Integration I believed is the area between the curve of a function on the x and y-axis ?
Typically you would sample it at a constant rate (e.g once per second or 100 times per second)
Can you give me an example on how to sample it?
You are apparently displaying the accelerometer data on the screen. How often do you update that value?
Pete
I actually dont know how to see how long was the value updated. But is it something to do with the baud rate, if thats the case I set the rate as 115200baud. Forgive me if I was such a newbie in this field.
Your problem with integration isn't a computer or Arduino problem. As someone else said - learn what integration is and figure out how to do a simple example with pencil and paper. After that the computer programming will be simple.
...R
daisygrm:
Integration I believed is the area between the curve of a function on the x and y-axis ?
Almost - it's a method of calculating the 'area under the curve', as you put it.
Assuming that the curve shows acceleration plotted against time, do you understand what the 'area under the curve' represents?
You need to understand how acceleration, speed and displacement relate to each other - it's fundamental to this problem. Once you understand the concepts, everything that follows is easy.
Okay after reading about the basics of kinematics together with integration. This is what I learn, Im sharing to clear my doubt and to ask if there are some things I missed out on the research.
As with the diagram attached. Overall, the velocity is the rate of change of displacement and acceleration is the rate of change of velocity.
And the integration is like the undoing of differentiation which can form an equation which is v(n)=v(n-1) + a(n-1)(t(n)-t(n-1)) ?
There are 3 simple equations about acceleration, time, distance (s) and velocity (v and u). The initial velocity is u, the final velocity is v.
v2 = u2 + 2as
v = u + at
s = ut + 0.5at2
Some of these should solve your problem
...R
Some of these should solve your problem
But, as my wife often tells me, it's always 'u' that's the problem XD
daisygrm:
I'm sharing to clear my doubt and to ask if there are some things I missed out on the research.
You've got the idea right.
Although those equations can look a bit daunting, in practice the code to implement them is almost trivial.
You must start by knowing the initial displacement, speed and time. You could assume they're all zero.
long accel = 0;
long speed = 0;
long displacement = 0;
long time = millis();
At regular intervals you read the instantaneous acceleration and the elapsed time since the previous reading. Then you can integrate the acceleration to get speed. Conceptually, it works like this:
unsigned long newTime = millis();
unsigned long deltaTime = newTime - time;
...
// estimate the average acceleration since the previous sample, by averaging the two samples
long avgAccel = (accel + newAccel) / 2;
// integrate the average accel and add it to the previous speed to calculate the new speed
long newSpeed = speed + (avgAccel * deltaTime);
estimate the average speed since the previous sample, by averaging the two speeds
long avgSpeed = (speed + newSpeed) / 2;
// integrate the average speed and add it to the previous displacement to get the new displacement
long newDisplacement = displacement + (avgSpeed * deltaTime);
time = newTime;
speed = newSpeed ;
displacement = newDisplacement;
Because you're only working from discrete sample values of the acceleration and not integrating continuously, there will be some error in the calculations. These errors will accumulate over time, so the longer your integration runs for the greater these errors will get. The smaller your sample interval the smaller these integration errors will be and the more slowly they will accumulate.
The basic concepts shown above are pretty simple once you've understood what integration is. There's one more gotcha: you need to decide what units you're going to use to represent time, acceleration, speed and distance. If you use SI units for everything the code above works exactly as it is. However, unless you're using floating point for everything that's probably not practical. So, you will need to scale the calculations to suit the units that you're using.
Just to clear my doubt again, I have understood the replies you all have given and I appreciate it. However, if I am using an IMU to for the displacement tracking then I cant inititalise my acceleration to be 0 right? Or was the given methods still applicable ?
Have you done any pencil and paper calculations to see if it matters?
...R
daisygrm:
Just to clear my doubt again, I have understood the replies you all have given and I appreciate it. However, if I am using an IMU to for the displacement tracking then I cant inititalise my acceleration to be 0 right? Or was the given methods still applicable ?
I have done pencil and paper calculations and found that it doesnt matter. However I am not getting the right value.
daisygrm:
if I am using an IMU to for the displacement tracking then I cant inititalise my acceleration to be 0 right?
Why not?
Can we share the secret of what values you are getting and what your calculations tell you to expect?
...R
daisygrm:
I have done pencil and paper calculations and found that it doesnt matter. However I am not getting the right value.
Great