Hi guys, i’m trying to make a program that would analyse the input of a accelerometer and I would need some lead to follow.
First, depending of the angle of the acc, there is a default error value (ex: -0.19 instead of 0). I would like make an auto adjustment (like: if the input is steady for a period of time X, then adjust the input to 0).
Second, I would need to calculate the time between the zero value and the first max (I have joined a picture of the graphic), but this is unclear to me how to know if there had been an impact, or this is just vibration (I was thinking about a threshold, but I would need to have a buffer to go back at the beginning of the impact). And the whole graphic is one impact, so I would need the program to just calculate the time between the 0 and the first max, and not the others.
Hope I’ve been clear !
You need to define “impact” before you can measure it. This is not as simple as you might think.
First, do some experiments so that you know what an average impact will look like in the data (as in the graph you posted).
Then, search the web for “peak search algorithm” to learn how to write code to search for an appropriate peak (or peaks) in data.
In your case, a peak might be something as simple as (acceleration greater than some value, for some number of data points), but maybe not.
The impact is a punch, so it can varie a lot, but the first peak, should always be the bigger one, so if I had an array containing every read from the beginning to the of the punch I could just run a for loop to find the highest value. But I don't know what is the size of the array that I would need because I don't know how many read are done per seconds.
I don't know how many read are done per seconds
Why not? You can define that. Study the Blink and (much better) Blink Without Delay examples to learn how to time events.
But I don't know what is the size of the array that I would need because I don't know how many read are done per seconds.
Why do you need to store every value? The first reading is the largest so far. The next reading is larger than the largest reading so for and the pulse is still ramping up, and is the new largest value, or it is smaller, and the pulse has peaked.
Only one value needs to me stored between iterations of loop().
PaulS, this is a really good (and logical) idea ! I want to learn more "programming techniques" like this. But I don't really know where to look, if you guys have any idea let me know !
Do you know what I could do for the time ? If I set a threshold at example 3 (to avoid false reading) and the acc peak is at 10, I don't know what to do to calculate the time from 0.
jremington, I'm not sure to understand what I can get from studying Blink, the speed of the loop depend on the number of operation that the arduino is making, right ?
Thanks guys, I really appreciate !
I don't know what to do to calculate the time from 0.
if you guys have any idea let me know !
You haven't looked yet at the Blink Without Delay example.
I know how to use millis(), what I don't know is how to have millis start before I get the confirmation that this is really a punch, and not some wall vibration.
I've edited my previous post after you answer: "I'm not sure to understand what I can get from studying Blink, the speed of the loop depend on the number of operation that the arduino is making, right ?
what I don't know is how to have millis start before I get the confirmation that this is really a punch, and not some wall vibration.
The point is that you can't know IN ADVANCE that the accelerometer data is going to mean. You have to know what an accelerometer measures - rate of change of velocity. What might be significant is the absolute change in velocity OR what might be significant is the time over which that change in velocity happens.
Imagine sitting in your sports car, stopped. Changing speed from 0 to 60 MPH in 6 seconds would have the accelerometer showing large changes in speed, but over a relatively long time frame.
Now, imagine cruising along at 60 MPH and slamming into a bridge abutment. The speed will drop from 60 to 0 in a very short amount of time. The SAME change in speed happened, but the rate of change is considerably different.
You will HAVE to record the acceleration value at some point in time. Then, when some time interval has passed (in better be a short time interval), you read another acceleration value. If the change in acceleration is significant, you need to take some action. If not, it really doesn't matter whether the rate is increasing or decreasing.
If you only want to consider the first significant change in acceleration, you could simply ignore the accelerometer for some period of time after a significant event was detected.
I think I understand everything you're saying, but the goal of this project is to measure the force of a punch, so there is a plaque with 4 springs and I will use this equation to calculate the force of the punch: F=a(m+2k(t^2)) where t is the time of the punch (0 to the peak of acceleration)
where t is the time of the punch
A punch is NOT an instantaneous event.
You could measure the total energy of the transient?
PaulS, this is why i need the time from the beginning of the punch to the end.
MarkT, I don't understand how to mesure the total energy.
I don't understand how to mesure the total energy.
We can probably tell you that, if you can first explain the meaning and values of a, m, k and t in the following equation, and how the equation was derived.
of course ! a is the acceleration, m the masse of the plate that you punch on, k the spring constante and t the time between the beginning of the punch and the end. I’ve joined a picture of the prototype.
Your "punch" then "starts" when the accelerometer reports a value above some threshold and "ends" when the accelerometer no longer reports a value above the threshold, for some axis of the accelerometer.
You will need to integrate the values over time to get the area under the acceleration curve.
An accelerometer is almost certainly the wrong sensor for your project.
the goal of this project is to measure the force of a punch
The total force on the mass (the plate) is by definition just the acceleration you measure in m/s^2, divided by its mass in kg. That force will be a function of time and will probably look similar to the graph you already posted.
The posted equation suggests that you want to take into consideration the force applied by the spring to the mass. To do that, you need to know the displacement, which you get be integrating the acceleration twice. That simple expression can't be correct.
PaulS, why doesn't the punch end when the accelerometer reach the first peak, in other words, when the springs start to decompress ?
Which sensors would you suggest me ?
jremington, I want to mesure the maximal force.