Logging Timestamp from board using data_fuser

Hi,
I'm trying to adapt the data_fuser example to output the timestamp, along with the accelerometer and gyro readings. Is there a way to directly access the timestamp when the data was sent from the sensor? I have tried to work around this by saving the os time each time the callback is called, but this leads to repeated timestamps but different sensor readings.
Change I made to the callback:

def data_handler(self, ctx, data):
        time_stamp = time.time()
        values = parse_value(data, n_elem=2)
        sensor_data.append("%f,%f,%f,%f,%f,%f,%f" % (time_stamp,  values[0].x, values[0].y, values[0].z, values[1].x, values[1].y, values[1].z))

Sample output:

timestamp, accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z
1548343125.325549,0.956055,-0.013367,-0.041382,0.365854,-0.792683,0.182927
1548343125.325549,0.960754,-0.014160,-0.041199,0.304878,-0.975610,0.182927
1548343125.341187,0.961243,-0.013184,-0.039917,0.243902,-1.036585,0.243902
1548343125.356795,0.958130,-0.013062,-0.041626,0.304878,-0.914634,0.182927
1548343125.356795,0.962585,-0.013916,-0.044556,0.243902,-0.853659,0.182927
1548343125.378925,0.964966,-0.014771,-0.041260,0.304878,-0.914634,0.182927
1548343125.378925,0.961914,-0.016541,-0.040894,0.365854,-0.975610,0.182927
1548343125.394557,0.961487,-0.016235,-0.043091,0.304878,-0.914634,0.121951
1548343125.410185,0.964661,-0.014221,-0.041931,0.304878,-1.036585,0.121951
1548343125.410185,0.963684,-0.014526,-0.041199,0.304878,-0.731707,0.18292

I'm having difficulty understanding how to obtain the timestamps directly so any help is appreciated.
Thanks!

Comments

Sign In or Register to comment.