Reading Acc on a Fenix 3 HR with more than 20Hz?

Hi!

I am reading the acc of my Fenix 3 HR with a timer where I access Sensor.Info.accel. Sadly the maximum frequency to have a timer executed is 20Hz which is not too much.
Can I somehow up the frequency I am polling the value?
Furthermore I am logging the acc data to a TXT file via the System.println() call which I suppose is very slow and a bad way to do.
Is there a better way to story the acc data? I need to store it so I can analyze it on the PC. Later on I will real time process the data on the watch.
Using .FIT files doesn't work since the format is VERY crpytic (even when converted to CSV and I am unable to optain a format explanation) AND the .FIT files are always corrupted ... (bad checksum ...)

The code I am using is:

using Toybox.Graphics as Gfx;
using Toybox.WatchUi as Ui;
using Toybox.Sensor as Sensor;
using Toybox.FitContributor as Fit;
using Toybox.ActivityRecording as Record;

class CounterView extends Ui.View {

var counter = 0;
var started = false;
var ui_update_timer = null;
var fit_update_timer = null;
var session = null;
var fit_data = null;
var acc = [0, 0, 0];

function initialize() {
View.initialize();
}

function onLayout(dc) {
ui_update_timer = new Timer.Timer();
ui_update_timer.start(method(:ui_update_callback), 100, true);
}

function onUpdate( dc ) {
var flags = Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER;
var center_x = dc.getWidth() / 2;
var center_y = dc.getHeight() / 2;

dc.setColor( Gfx.COLOR_BLACK, Gfx.COLOR_BLACK );
dc.clear();
dc.setColor( Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT );

dc.drawText(center_x, center_y - 20, Gfx.FONT_SMALL, acc[0], flags );
dc.drawText(center_x, center_y, Gfx.FONT_SMALL, acc[1], flags );
dc.drawText(center_x, center_y + 20, Gfx.FONT_SMALL, acc[2], flags );
}

function start() {
if((session == null) || (session.isRecording() == false)) {
session = Record.createSession({:name=>"Counter", :sport=>Record.SPORT_GENERIC});
// fit_data = session.createField("acc", 0, Fit.DATA_TYPE_SINT16, {:mesgType=>Fit.MESG_TYPE_RECORD, :units=>"bars"});
fit_update_timer = new Timer.Timer();
fit_update_timer.start(method(:fit_update_callback), 50, true);
session.start();
Ui.requestUpdate();
}
}

function stop() {
if((session != null) && session.isRecording()) {
fit_update_timer.stop();
session.stop();
session.save();
session = null;
Ui.requestUpdate();
}
}

function ui_update_callback() {
Ui.requestUpdate();
}

function fit_update_callback() {
var info = Sensor.getInfo();
if(info has :accel and info.accel != null){
acc = info.accel;
// fit_data.setData(acc[0]);
System.println(acc);
}
}

}



Could anybody give me a hint.

Best regards
Noah
  • I noticed that you are trying to update the FIT data at 20Hz. The documentation for MESG_TYPE_RECORD indicates that data is only written as frequently as once a second. If you need to capture more data, you could probably use an array. You might be able to use an array of 15 elements, with each triple representing the x, y, and z acceleration values at 20Hz, written only once a second. Of course you could also normalize and pack the values if you wanted to go that far.

    I'm actually not sure how frequently the sensor data is updated, so you may not get any useful data by polling that frequently. This would be something that you'd have to test on a device to be sure.

    Travis
  • Oh, thanks for the pointer! Didn't see that one.

    Still, the fit data is only for logging. And as long as the FIT files come out corrupt, it is of no use :)

    Also, that doesn't change the fact I can oly poll with 20 Hz because of the timers.

    Best wishes
    Noah
  • Also, that doesn't change the fact I can oly poll with 20 Hz because of the timers.


    You might try something like the code below to get a faster update rate. I ran this on the simulator for an Edge 1000. If I just do 1 println per onUpdate cycle the time increment is something like 62 msec with a timer set at 20 Hz. But when I add this while loop it's something like 16 msec. It seems like getTimer() is being updated 4X faster than a timer can run.

    Now this is on the Simulator and it's getTimer(), but maybe you could get a faster update rate on the accelerometers like this. Just a thought.

    function onUpdate(dc) {
    View.onUpdate(dc);
    var time = Sys.getTimer();
    var fcount = 0;
    while (fcount < 4) {
    if (Sys.getTimer() > time){
    time = Sys.getTimer();
    fcount = fcount+1;
    Sys.println("Time: " + Sys.getTimer());
    }
    }
    }