Discussion about 'if-else statement vs if-then statement' and Accelerometer

I am reposting your blocks here, for all to bask in its glory.

It will take me a few moments to recover my composure.

4 Likes

Still working on it. Hope, il complete it by tomorrow.

This all looks like it would collapse like a telescope to something a tenth its size using

  • procedures
  • lists
  • tables
  • math

http://www.appinventor.org/bookChapters/chapter19.pdf

http://www.appinventor.org/bookChapters/chapter20.pdf

http://www.appinventor.org/bookChapters/chapter21.pdf

2 Likes

Okay, il check it. I am closer to the finishing line, so il try the other way after that. Yes, reducing the block size is my next step/goal.

Can you create blocks?

Purpose: To give an audio message to driver ((as quickly as possible) when he starts his car 'AUDIO MESSAGE: You Started Driving, Have a Safe Journey'. - I have chosen accelerometer sensor for that after experimenting with other sensors.

I don't have a good physics model for sensing that situation.

1 Like

okay :slight_smile:

@ABG , In one of your reply once you show me the blocks about setting deadline to clock. I need to know more about it.

  1. I wish to play music only if I get accelerometer x value = 0 after 15 seconds of app start time.

  2. and I wish to play another music if I get accelerometer x value = 1 after another upcoming 15 seconds.

  3. If the x value didn't reaches 1 before 60 seconds (deadline), then label text = 'Not Reached Expected Value'.

How can I set this deadline for any accelerometer value for a given time? I shall share the screeshots once you shared to me below (regarding alert message).

I know to create 1) and 2) using clock but I don't know to create 3), ie, deadline.

08e6525fd0bb9c10a0a0b85b5ce64c108c8f6dae_2_690x296 (1)

d6305a193076b1c5403d30651eab4616c3de93e9_2_690x308 (1)

Here is a sample using deadline variables.

On the subject of the analysis of movement, ancient astronomers would accumulate lists of measurements, that could be used discover patterns of movement among heavenly bodies.

AI2 has some easy graph components that could be used to display measurements across time, if you feed them the appropriate lists of readings. Maybe you could spot patterns in the graphs that would give you clues?

Your problem reminds me of the problem of how to deduce your present location while locked into the trunk of a moving car.

1 Like

Yes, I am trying to create an app that can know when a person starts driving within in few seconds. I am working to accomplish this using only accelerometer. Let me check the graph components that you mentioned.

How can I reduce blocks?

  1. In this Accelerometer app, I have to work with each accelerometer values. ie, -10 to 10 for all the three axis (x, y, z).

  2. According to the phone position that is maintained (spontaneously or randomly) by user, always the current value of x, y and z will be between -10 to +10.

  3. So, I planned to code (arrange blocks) in such way that

a) If the current value of x or y or z is increased/decreased by 3 (in any of both direction + or -), then user may started to drive, so check again if the increased value is maintained for few seconds (eg. 3 seconds).

b) To check if the increased value is maintained, I put different clocks to check for each upcoming 250 milli seconds repetitively for four times. And, these four times checking must be completed within 3 seconds (dead line (So, how can i reduce no. of clocks? )). Deadline is because, the value of accelerometer will vary always in high speed. So, the blocks will check if the increased value is reccurently appearing for 4 times within the deadline time. If, so then the app will conclude that the increased speed of the vehichle is maintained, so the app will conclude that the driver started driving.

c) Then all the above steps will be looped/repeated only if the increased value comeback to its past value (without the presence of increased value again for few seconds).

The main reason I feel that the blocks cannot be reduced much is because, for each value from -10 to +10, the if conditions are different. ie, the if condition will check for if the current value is increased/decreased by 3. This mathematics cannot be done in a single block.

I think, if this mathematics can be done in a single block, then the no. of blocks can be reduced.

What if you used a single Clock at 250 ms, accumulating the three axis values in separate lists over the last 5 seconds?

For each list compare the mean and mode of those lists.

1 Like

Can you give some idea to compare mean and mode?

Are these two blocks I have to use for that?

Capture
Capture

I got this from a website;

image

How can I get the list of x, y z values for a specific period of time?

Guide me.

Don't know how to arrange the blocks. Guide me.

See:

1 Like

@NishyanthKumar , I have few newbie questions.

  1. Will it work when the user hold the phone in any position?

  2. And, in this app what will be the approximate value change if a car started moving (so we can conclude that the driver started the car)?

Guide me.

It should.

Unfortunately, that it something I do not know about. You'll have to figure that out by trying it yourself.

1 Like

@NishyanthKumar , this is the app that I am trying to make. So, by modifying your app can I achieve the same result?

Aim of the app:

App has to Say an audio message to driver 'You started Diving, Have a happy Journey'.

Guide me.

@NishyanthKumar , May I know why this block is multiplied by 0.1. What is the use of it?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.