My problem is find a way to reduce the number of updateAccelerometer calls.
int count = 0;
int accelerometer = updateAccelerometer();
while (accelerometer <= 500) {
printf("Actual: %lf", accelerometer);
accelerometer = updateAccelerometer();
count++;
}
Which gives:
Actual: 9
Actual: 28
Actual: 47
Actual: 65
Actual: 84
Actual: 103
Actual: 122
Actual: 141
Actual: 159
Actual: 178
Actual: 197
Actual: 216
Actual: 235
Actual: 253
Actual: 272
Actual: 291
Actual: 310
Actual: 329
Actual: 347
Actual: 366
Actual: 385
Actual: 404
Actual: 423
Actual: 442
Actual: 460
Actual: 479
Actual: 498
Now my problem is that I dont want to update the accelerometer every time, but in an exponential proportional ratio, for example. If I introduce a “linear proportional ratio”
I will just do:
if (count % 2 = 0) accelerometer = updateAccelerometer();
Which means, one value will be read, one value will not be, etc etc etc, since everytime I call updateAccelerometer it might take time, I would like to take less values when I am far away and more value when I am closer.
So the idea is to have an exponential function that will return me only the ones marked with x, not because I dont print the others, but because I dont update the accelerometer
Actual: 9
Actual: 28
Actual: 47
Actual: 65
Actual: 84
Actual: 103x
Actual: 122
Actual: 141
Actual: 159
Actual: 178
Actual: 197
Actual: 216
Actual: 235x
Actual: 253
Actual: 272
Actual: 291
Actual: 310
Actual: 329x
Actual: 347
Actual: 366
Actual: 385
Actual: 404x
Actual: 423
Actual: 442
Actual: 460x
Actual: 479
Actual: 498x
This is not a very specific problem, since I had this problem of exponentially skipping updates in many other situation, any tick?
It looks like the number of counts until you next sample the accelerator should be about
sqrt(fabs(500 - accelerometer)) / 3.25.