The personal wiki of ...

Detecting Movement

The Android phones we are using can measure acceleration in three dimensions.

This experiment will show you the data that is output and you should construct some graphs to see what sort of data you get.

axis device.png

What we would like you to think about is how you could use this data to determine things like which direction a person is moving and how fast.

The program

Very similar to the GPS one except it reads the accelerometer.

import android, time, os
droid = android.Android()

dt = 100 #100ms between sensings                                                                                                  \
endTime = 3000 #sample for 3000ms                                                                                                 

f = open('/sdcard/sl4a/scripts/logfile.txt','w')
f.write('x,y,z\n')
f.close()

timeSensed=0
droid.startSensingTimed(2,dt)
while timeSensed <= endTime:
    value = droid.sensorsReadAccelerometer().result
    x = value[0]
    y = value[1]
    z = value[2]

    f = open('/sdcard/sl4a/scripts/logfile.txt','a')
    f.write(str(x) + ',' + str(y) + ',' + str(z) + '\n')
    print(str(x) + ',' + str(y) + ',' + str(z) + '\n')
    f.close()
droid.stopSensing()

1. Load the Code

Here is the script:

chart-4.png

2. Run the Experiment

Try jumping up and down, the program will run until you stop it (or 3 minutes, whichever happens first).

Another experiment (afterwards) is try dropping the phone ONTO A PILLOW.

3. Copy the Data from the Phone

1. You need to copy across the data that you have collected. Connect the phone to the PC using the USB cable, on the PC open the terminal window and enter the following command to copy the data file across.

getlog

IF YOU HAVE A PROBLEM WITH THE ABOVE STEP, ASK SOMEONE, MAYBE THE COMPUTER NEEDS SOME SETTING UP!

2. Open the data file in gedit by entering the following command:

gedit logfile.txt

3. Select and copy the contents of the data file into the clipboard.

4. Graphing the Data

Try graphing the different pieces of data. Use a spreadsheet as we did with the altitude.

5. How well does the accelerometer work?

See if you can answer the following questions. Discuss them with the mentors:

  1. Why is it never zero even when the phone isn't moving?
  2. Do you think the accelerometer is very accurate?
  3. How could you work out if you are going up or down?
  4. Can you think of any ways you could use this data for a program?
I Attachment Action Size Date Who Comment
axis_device.pngpng axis_device.png manage 17 K 25 Jan 2013 - 00:19 Main.ian  
chart-4.pngpng chart-4.png manage 4 K 25 Jan 2013 - 00:17 Main.ian  
Contact Us | Section Map | Disclaimer | RSS feed RSS FeedBack to top ^

Valid XHTML and CSS | Built on Foswiki

Page Updated: 25 Jan 2013 by ian. © Victoria University of Wellington, New Zealand, unless otherwise stated