×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    24

    Smile Finding accelerometer update frequency

    I tried to find the accelerometer update frequency on my N95 using the following code:

    Code:
    import appuifw, sys, e32
    import time, math
    import axyz    # accelerometer
    
    class Accelerometer:
    
        p_text_colour = (200, 20, 20)
        p_buffer_time = 3.0    # [s]
        p_acc_frequency = 10.0 # [Hz]
      
        def __init__(self):
            self.acc_x = int(self.p_buffer_time * self.p_acc_frequency) * [0.0]
            self.acc_y = int(self.p_buffer_time * self.p_acc_frequency) * [0.0]
            self.acc_z = int(self.p_buffer_time * self.p_acc_frequency) * [0.0]
            self.acc_time = int(self.p_buffer_time * self.p_acc_frequency) * [0.0]
            self.acc_time2 = int(self.p_buffer_time * self.p_acc_frequency) * [0.0]
            
            self.exitflag = 0
            self.canvas = appuifw.Canvas(event_callback=self.event)
            appuifw.app.body = self.canvas
       
        def frame_rate(self, timestamps):
            try:
                frequency = len(timestamps) / (timestamps[-1] - timestamps[0])
            except:
                frequency = -1
            return frequency
             
        def update(self):
            appuifw.app.body.clear()
            appuifw.app.body.text((10, 10), u"ACC: %3.1f Hz (%4.1f, %4.1f, %4.1f)" % (self.frame_rate(self.acc_time), self.acc_x[-1], self.acc_y[-1], self.acc_z[-1]), self.p_text_colour)
            appuifw.app.body.text((10, 20), u"ACC: %3.1f Hz" % self.frame_rate(self.acc_time2), self.p_text_colour)
            
        def event(self, ev):
            pass
      
        def set_exit(self):
            self.exitflag = True
        
        def start_data(self):
            axyz.connect(self.accelerometer_data)
                    
        def stop_data(self):
            axyz.disconnect()
            
        def run(self):
            appuifw.app.exit_key_handler = self.set_exit
            self.start_data()
            while not self.exitflag:
                self.update()
                e32.ao_sleep(0.00000001)
            self.stop_data()
            
        def accelerometer_data(self, x, y, z):
            timestamp = time.time() + math.modf(time.clock())[0]
            self.acc_time2 = self.acc_time2[1:]
            self.acc_time2.append(timestamp)        
            if (timestamp - self.acc_time[-1]) >= 1 / self.p_acc_frequency:
                self.acc_time = self.acc_time[1:]
                self.acc_time.append(timestamp)
                self.acc_x = self.acc_x[1:]
                self.acc_x.append(x)
                self.acc_y = self.acc_y[1:]
                self.acc_y.append(y) 
                self.acc_z = self.acc_y[1:]
                self.acc_z.append(y)                 
        
    app = Accelerometer()
    app.run()

    I would also like to be able to set the update frequency using p_acc_frequency.

    Some questions:
    1) Why are the frequency measurements so unstable and why does (timestamp - self.acc_time[-1]) sometimes return negative values?
    2) How can I improve the frequency measurements, so that I can get the accelerometer data in the buffer at a specified rate, e.g., 10 Hz?
    3) Why is the e32.ao_sleep command necessary?
    4) Any other comments/improvements on my very first accelerometer code are welcome.

  2. #2
    Registered User
    Join Date
    Jan 2007
    Posts
    24

    Re: Finding accelerometer update frequency

    To get the timestamp I used:
    Code:
    time.time() + math.modf(time.clock())[0]
    Is there a better way?

Similar Threads

  1. N95 Accelerometer & JSR-256
    By AnthonyAndrews in forum Mobile Java General
    Replies: 9
    Last Post: 2009-04-21, 22:12
  2. Update SQL statement doesn't work
    By asheeshv in forum Symbian
    Replies: 4
    Last Post: 2008-12-11, 05:41
  3. nokia 32 frequency selection
    By EinZigeuner in forum General Development Questions
    Replies: 0
    Last Post: 2006-02-10, 06:29
  4. Tips on using NDS 1.1
    By mitts in forum Symbian Tools & SDKs
    Replies: 7
    Last Post: 2006-01-18, 16:07
  5. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31

Posting Permissions

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