×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    4

    sampling data from accelerometer

    Hi all,

    Working on a little project where we try to identify walking patterns in users based off the accelerometer data from a nokia n95 phone placed in the user's pocket.
    Using someone else's code right now, which is as follows:

    ######
    Code:
    offtime = getTime()
    while less than 256 samples
          # these 2 lines check if the accelerometer has data
          if not sense_conn: continue
          if not len(sense_conn.delta): continue
          if getTime() - offtime >= TIME_WINDOW
                 take a sample
    ######

    We're trying to sample data from the accelerometer at a strict interval(every TIME_WINDOW seconds).
    However, due to the nature of scheduling processes, sometimes this time window is exceeded. We'd like to enforce strict timing intervals so that the time between each sample is as uniform as possible.
    Any suggestions on how we should be doing this?

  2. #2
    Registered User
    Join Date
    Jul 2009
    Posts
    16

    Thumbs up Re: sampling data from accelerometer

    Quote Originally Posted by Damonkashu View Post
    Hi all,

    Working on a little project where we try to identify walking patterns in users based off the accelerometer data from a nokia n95 phone placed in the user's pocket.
    Using someone else's code right now, which is as follows:

    ######
    Code:
    offtime = getTime()
    while less than 256 samples
          # these 2 lines check if the accelerometer has data
          if not sense_conn: continue
          if not len(sense_conn.delta): continue
          if getTime() - offtime >= TIME_WINDOW
                 take a sample
    ######

    We're trying to sample data from the accelerometer at a strict interval(every TIME_WINDOW seconds).
    However, due to the nature of scheduling processes, sometimes this time window is exceeded. We'd like to enforce strict timing intervals so that the time between each sample is as uniform as possible.
    Any suggestions on how we should be doing this?
    I think there are few things that you can try. First of all I would recommend that you try to sample the accelerometer data as quickly as possible. In my experience I got as much as 32Hz (i.e., 32 samples per second) from my N95. This I do by choosing a small eo.ao_sleep() time. Below is a code snippet I use in my codes:

    # main loop control
    def loop(self):
    try:
    while not self.exiting:
    self.handle_redraw(None)
    e32.ao_sleep(0.009)
    finally:
    pass

    0.009 here works for me, and if you want to sample slower than 32Hz just increase the sleep time to 0.1 or something like that.

    Sampling as fast a possible as described above will make sure that have enough samples at your predefined sampling intervals (given that it is not faster than 32Hz).

    Next thing you should try is in your main code where you should take the accelerometer measurements at your predefined sampling interval. For example I use the following code to do this:

    # MAIN COMPUTATIONAL LOOP
    time_now=time.clock()
    if time_now - time_last_read >= 1/SAMPLE_RATE:
    *
    Your main computation/function code goes here
    *
    *
    time_last_read = time_now

    So my SAMPLE_TIME is like your TIME_WINDOW in your example code above.

    I hope this helps.

    Selim

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    4

    Re: sampling data from accelerometer

    Ah, I forgot to mention I set offtime = getTime() at the end of each loop iteration.
    I do not see why your "# MAIN COMPUTATIONAL LOOP" would be any different from the code I have used otherwise.

    I will try the e32 sleep method next though and check how it affects the timing intervals. Where can I find documentation on this function?

  4. #4
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,795

    Re: sampling data from accelerometer

    Quote Originally Posted by Damonkashu View Post
    Ah, I forgot to mention I set offtime = getTime() at the end of each loop iteration.
    I do not see why your "# MAIN COMPUTATIONAL LOOP" would be any different from the code I have used otherwise.

    I will try the e32 sleep method next though and check how it affects the timing intervals. Where can I find documentation on this function?
    I don't recommend using sleep function, since it would not allow other activity till the sleep time ends.

    Rather use Ao_timer instance and after() function for the callback.

    Documentation, ofcourse at https://garage.maemo.org/frs/?group_id=854 ! Download the latest exe file and install it. You would find S60 Module reference installed too.
    Pankaj Nathani
    www.croozeus.com

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    4

    Re: sampling data from accelerometer

    I'm trying to use a print function (I print the data from accelerometer after each timer.after) but it seems it will not allow me to use print as the callback, am I using it incorrectly?

    timer.after(TIME_WINDOW, print("1"))

    This is just an example, I don't actually print the number "1"

  6. #6
    Registered User
    Join Date
    Jul 2009
    Posts
    4

    Re: sampling data from accelerometer

    Code:
    running=1
    def quit():
       global running
       running=0
    
    main data collecting function
       f = open("Output.txt", "w")
    
       appuifw.note(u"Collecting Data ...")
       appuifw.app.exit_key_handler=quit
       appuifw.app.title= u"Acc Data"
       timer = e32.Ao_timer()
       e32.ao_yield()
       e32.reset_inactivity()
       while running:
          timer.cancel()
          timer.after(TIME_WINDOW, lambda:auxFunction(f))
          
       sense_conn.cleanup()
       f.close()
    
    def auxFunction(f):
        X = sense_conn.delta[0]
        Y = sense_conn.delta[1]
        Z = sense_conn.delta[2]
        f.write(str(X)+" \t"+str(Y)+" \t"+str(Z)+" \t"+str(math.sqrt(X*X + Y*Y + Z*Z))+" \t"+str(getTime())+"\n")
    I'm not sure if this is functionally correct, but once I start executing this code on the phone, I can no longer quit python or stop the program from running. I have to shutdown the phone just to be able to do anything again. I do not even know if anything is getting written to the file because the program seems to be writing to the file still.

  7. #7
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: sampling data from accelerometer

    Quote Originally Posted by Damonkashu View Post
    I'm trying to use a print function (I print the data from accelerometer after each timer.after) but it seems it will not allow me to use print as the callback, am I using it incorrectly?

    timer.after(TIME_WINDOW, print("1"))

    This is just an example, I don't actually print the number "1"
    hello Damonkanshu

    you can't write the print statement like this in the line as the time.after demand a callback function as its arguement, please make a function in which you can write the print statement and implement that.

    PS: console based statements only work with PyS60 1.9.x realeses.

    I hope you got my point.

Similar Threads

  1. Memory leak and accelerometer data
    By dunff2k in forum Symbian
    Replies: 1
    Last Post: 2009-05-13, 18:48
  2. Replies: 1
    Last Post: 2009-04-20, 17:54
  3. Replies: 3
    Last Post: 2008-09-09, 04:53
  4. Replies: 2
    Last Post: 2008-07-03, 15:29
  5. Replies: 1
    Last Post: 2007-04-17, 10:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×