Hi!
I'm new to programming in Monkey C. I wanna write a programm, which gets all the reading of the accelerometer and the magnetometer and saves it in a FIT-File.
Getting the data over Sensor.Info and saving it in an array is no problem. I was printing out the arrays in the console in Eclipse and they make perfekt sense. But when I save those arrays in a FIT-Field using the setData()-function, suddenly there are different, wrong values in the FIT-Field. (I use the Fit SDK to convert the FIT-Files to a CSV-File and import the File in Excel). I really don't know where my mistake is. I hope you can help me.
This is how I create the FIT-Fields:
session = ActivityRecording.createSession({
:name => "AccelMagSession"
});
xAccelField = session.createField("X_Accel_Values", XACCEL_FIELD_ID, FitContributor.DATA_TYPE_SINT32, {:count => numbersPerField, :units => "mg"});
yAccelField = session.createField("Y_Accel_Values", YACCEL_FIELD_ID, FitContributor.DATA_TYPE_SINT32, {:count => numbersPerField, :units => "mg"});
zAccelField = session.createField("Z_Accel_Values", ZACCEL_FIELD_ID, FitContributor.DATA_TYPE_SINT32, {:count => numbersPerField, :units => "mg"});
pitchField = session.createField("Pitch_Values", PITCH_FIELD_ID, FitContributor.DATA_TYPE_FLOAT, {:count => numbersPerField, :units => "dg"});
rollField = session.createField("Roll_Values", ROLL_FIELD_ID, FitContributor.DATA_TYPE_FLOAT, {:count => numbersPerField, :units => "dg"});
xMagField = session.createField("X_Mag_Values", XMAG_FIELD_ID, FitContributor.DATA_TYPE_SINT32, {:count => numbersPerField, :units => "mgauss"});
yMagField = session.createField("Y_Mag_Values", YMAG_FIELD_ID, FitContributor.DATA_TYPE_SINT32, {:count => numbersPerField, :units => "mgauss"});
zMagField = session.createField("Z_Mag_Values", ZMAG_FIELD_ID, FitContributor.DATA_TYPE_SINT32, {:count => numbersPerField, :units => "mgauss"});
When the user presses a button I start a timer which calls this function every 125ms:
function timerCallback() {
timerCalls =+ 1;
var info = Sensor.getInfo();
accel = info.accel;
mag = info.mag;
//Add the Sensor reading to the arrays. (Works, I System.println'ed the arrays afterwards to check(see below))
xAccel.add(accel[0]);
yAccel.add(accel[1]);
zAccel.add(accel[2]);
mPitch.add((Math.atan2(accel[1], Math.sqrt(Math.pow(accel[0], 2) + Math.pow(accel[2], 2)))));
mRoll.add((Math.atan2(-accel[0], accel[2])));
xMag.add(mag[0]);
yMag.add(mag[1]);
zMag.add(mag[2]);
//System.println block is here, which prints out all the arrays
//Save Data in FIT Field every numbersPerField-Time
if (timerCalls % numbersPerField == 0) {
xAccelField.setData(xAccel.slice(-numbersPerField, null));
yAccelField.setData(yAccel.slice(-numbersPerField, null));
zAccelField.setData(zAccel.slice(-numbersPerField, null));
pitchField.setData(mPitch.slice(-numbersPerField, null));
rollField.setData(mRoll.slice(-numbersPerField, null));
xMagField.setData(xMag.slice(-numbersPerField, null));
yMagField.setData(yMag.slice(-numbersPerField, null));
zMagField.setData(zMag.slice(-numbersPerField, null));
}
}
Those are the printed values from the console:
XAccel: [654, 654, 654, 654, 654, 654, 654, 475]
YAccel: [476, 476, 476, 476, 476, 476, 476, 655]
ZAccel: [-586, -586, -586, -586, -586, -586, -586, -586]
Pitch: [0.496728, 0.496728, 0.496728, 0.496728, 0.496728, 0.496728, 0.496728, 0.715031]
Roll: [-2.301411, -2.301411, -2.301411, -2.301411, -2.301411, -2.301411, -2.301411, -2.460433]
XMag: [-118, -118, -118, -118, -118, -118, -118, -86]
YMag: [-86, -86, -86, -86, -86, -86, -86, -118]
ZMag: [202, 202, 202, 202, 202, 202, 202, 202]
Those arrays in a FIT-Field look like that:
X_Accel_Values: -1|-1|-1|-8388737|-8388737|-8388737|-8388737|-129
Y_Accel_Values: -1|-1|-1|-1|-1|-1|-1|68095
Z_Accel_Values: -256|16777215|2147483647|65407|-1|402653439|250657|0 //Interesting here: Third number is max. Integer
Pitch_Values: 4.2351647E-22|0.0|1.17549435E-38|0.0|0.0|0.0|0.0|0.0
Roll_Values: 0.0|0.0|0.0|0.0|0.0|0.0|0.0|0.0
X_Mag_Values: 0|0|0|0|0|0|0|0
Y_Mag_Values:0|0|0|0|0|0|0|0
Z_Mag_Values: -872415232|-1015597533|41205445|268435456|17195260|0|-553648128|91537093
Any Help is appreciated
Thanks!
Tim