I couldn't replicate it either. However, after reading the forum again I wrote the following script.
function imu_offset_measurement()
clear ALL
clear callback_workspace %to clear its persistent variables
clear global
clc
close ALL
import com.tinkerforge.IPConnection;
import com.tinkerforge.BrickIMUV2;
global arrayElapsedTime;
global arrayRawAcceleration;
global arrayAngularVelocity;
global arrayMagneticField;
disp('START');
HOST = 'localhost';
PORT = 4223;
UID = '6467RG'; % Change XXYYZZ to the UID of your IMU Brick 2.0
ipcon = IPConnection(); % Create IP connection
imu = handle(BrickIMUV2(UID, ipcon), 'CallbackProperties'); % Create device object
ipcon.connect(HOST, PORT); % Connect to brickd
% Don't use device before ipcon is connected
bias = [0;0;0]; %[0.0055;0.0168;-0.2722]; %this constant has been previously calculated
imu.setSensorConfiguration(7,4,2,0,4);%set sensor range and filter bandwidth
%imu.setSensorFusionMode(0); %Fusion Mode OFF (uncalibrated output)
% Set period for all data callback to 0.1s (100ms)
imu.setAllDataPeriod(10);
% Register all data callback to function cb_all_data
set(imu, 'AllDataCallback', @(h, e) callback_workspace(e, bias));
%readings not reliable during first miliseconds
%all the experiment is stationary
pause(1);%recording time
imu.setSensorFusionMode(0);
pause(1);%second period
imu.setSensorFusionMode(1);
pause(1);
imu.setSensorFusionMode(2);
pause(1);
imu.setSensorFusionMode(3);
pause(1);
ipcon.disconnect(); %stop capturing data
%POST-PROCESSING
xlswrite('results_imu_offset_measurement_test_magnetometer.xls',[arrayElapsedTime,arrayRawAcceleration,arrayAngularVelocity,arrayMagneticField]);
disp('FINISH');
end
with callback function
function callback_workspace(e, bias)
persistent callbackTimer; %to remove persistent variables remember to clear the right function in the main
global arrayElapsedTime;
global arrayRawAcceleration;
global arrayAngularVelocity;
global arrayMagneticField;
%if it is the first call return inicial values.
%the persistent variables must be cleared before calling this function for the first time
if isempty(callbackTimer)
callbackTimer=tic;
return
elseif toc(callbackTimer)>0.07 %readings not reliable during first miliseconds
arrayElapsedTime = [arrayElapsedTime; toc(callbackTimer)];
arrayRawAcceleration = [arrayRawAcceleration;double(e.acceleration.')/100.0];
arrayAngularVelocity = [arrayAngularVelocity;double(e.angularVelocity.')/16.0];
arrayMagneticField = [arrayMagneticField;double(e.magneticField.')/16.0];
return
else
%left empty purposefully
end
end
This gave me the attached output file, which does not behave in the same way I described the first time, but still quite funky. It does not make much sense since the total recorded time is 10 seconds not 5 seconds as it should by adding all pauses! In this case, the "by default" period gives zeroes, and the rest behave as expected despite the additional recorded 5 seconds. However, any subsequent execution of the script gives reasonable outcome.
Is it possible that something happens just at the beginning while setting up the IP connection to the device?
results_imu_offset_measurement_test_magnetometer.xls