How can I set Time Limit for certain tasks to be completed?

But you have only clock again. Now do you want to check if target is achieved only after 60s?
Are checks every 250ms no longer required?

Where do you set global Counter to 0?

Is there any mistakes in these blocks?

Purpose is to check if the vehicle started moving, if the phone position at rest is 'x accel = 0 to1'.

Update: I added one more block at the bottom of the blocks.

Well...a lot of mistakes...now, what is the function of the timer? It is triggered three times to do what?

Some errors:

  • In the first "if" you have an OR condition...so this statement will be always true. If you want a true only for values between 0 and 1, it should be an AND.
  • You are enabling the trigger in several points but...what happens if it is already triggered? Maybe you need to check if it is already running before to enable it.
  • The second and third "if" have the same condition "Counter1 >= 100.
  • The fourth "if" has a condition that cannot matched if the first "if" is fulfilled.
    ....

Maybe it's better to stop, think in what you want, how to achieve it in the easiest way, write pseudocode again, and try to implement it.

1 Like

Capture

I enabled timer to create counter3 (ie, counter3- count for every 1 second interval). Another counter is to count the number of times xAccel value reaches the defined value.

Now, if counter1 >= 100 and if counter 3= 3 (ie, 3 seconds), then we can understand that in 3 seconds the xAccel value reached the defined value for 100 times. If so, do some task eg, play music 'You Started Driving'. This is my plan for timer.

3 Steps of these blocks:

  1. Check if the phone (ie, vehichle) is at rest for few seconds. ie, if x Accel value is between 0 and 1.

  2. Check if the speed of the vehicle is increased for few seconds. ie, if x Accel value is greater than 3 or lesser than -3.

  3. Check is the vehicle came back to rest for few seconds. ie, if x Accel value is between 0 and 1.

Yes, because of errors, app is not working.

THE PRECISE AIM OF THE APP IS TO KNOW WHEN THE VEHICLE STARTED TO MOVE USING ACCELEROMETER - AND THE PROCESS HAS TO REPEAT.

Relative to the timer, now when the condition for the timer is matched, you enable the timer and when it expires, you increment the counter3 and stop the timer... you can avoid this step and when the condition is matched increment directly the counter3...

If you want to check a condition (a counter, for example) after a time, then set the timer to that time and, in the timer block, check that condition.

1 Like

A very simple idea...to check that during an interval (3s) there is not a change from "rest" status to "moving" status or vice versa:

  • when xAceel between 0 and1 check if it was already resting.
    If it was already resting, nothing to do.
    If it wasn't already resting (the first time or accelerating) then reset the timer to start a new period of "resting" status.

  • when xAceel between 3 and -3 check if it was already moving.
    If it was already moving, nothing to do.
    If it wasn't already moving (the first time or resting) then reset the timer to start a new period of "moving" status.

  • If the timer expires, that means that during the interval there isn't a change of status (always resting/moving during the whole interval) so, you can stop the timer and you have achieved the target for moving/resting status.

1 Like

This is partially working. Always, Rest is displayed. Moving is not displayed even when x value is more than 3.

Change that for an OR:

1 Like

Okay, now it is working. Now, I need to do one more thing in the app. ie, now in this blocks we set 0 to 1 as rest and 3 or -3 as moving. I want to do this for all values of x, y and z as follows.

a) When 0 to 1 = Rest; 3 or -3 = Moving
b) When 1 to 2 = Rest; 4 or -2 = Moving
c) When 2 to 3 = Rest; 5 or -1 = Moving
....... etc.

ie, I added/substracted +3 or -3 with the Value that is set as Rest. How can we do this with less blocks?

The purpose is users may keep their phone in any position, so the rest value of the accelerometer can be unpredictable. So, we have to detect the rest and movement from the unpredictable position of the phone that is maintained for 3 seconds. ie, if a driver is planning to drive, he must keep the phone somewhere in some fixed position. So, if the position is maintained for 3 seconds, then that is Rest value & moving value will be adding/subtracting +3 or -3 with it.

Can we count/increment the rest value and moving value? For 3 seconds if a phone position is maintained, then that is what the rest value.

So, when the app/blocks increment the rest value from 0 -1 to 1-2 to 2-3 etc... , and if any incremented value matches with the phone position maintained for 3 seconds, then that can be confirmed as rest value and the app will wait for the raise of +3 or -3 with that value, if the vehicle moves then the app will detect the raise of +3 or -3.

Or is there any other better idea?

I tried something like this, but not working ...

Store the xAccel read into a variable and do the same, launch a trigger for 3s, if the same xAccel received then nothing, if a new xAccel received, reset the variable, reset the timer.

If trigger expires then it means that during 3s, there wasn't a change in xAccel so, that is your rest value.

Then, you have the same case but with a new value for rest, instead of 0-1.

Anyway, if you are using an accelerometer, it only measures the acceleration so, in an inertial system (constant speed) the car can be moving but no change in acceleration is detected.

1 Like