Page 1 of 1

Matlab - PhidgetSpatial 3/3/3

Posted: Fri Oct 09, 2020 4:23 am
by balinte94
Hi guys,

I am facing problem with the 1044 PhidgetSpatial. I kindof figured out the code to get some data. But this is a 1x30000 or more array for X Y Z acceleration and its too much if it samples every 5ms. Also, its repeating data for 5-6 times.
I did a lot of research, google burned up by phidgetspatial and Matlab searches but I am stuck. The user guide of phidget 1044 is also helpless.
What I want is to have the data read into Matlab and each with a corresponding timestamp in the IMU (DataRate).
E.g.: time(s) X acc Y acc Z acc
0.05 0.037 0.015 -0.998
0.1 0.036 0.013 -1.002
0.15 ...
0.2 ...

Can someone link something which can guide me through? OR if someone has a working code with anything similar is also helpfull.

Thanks:)


clc, clear all

tic;

loadphidget21;

handle = libpointer('int32Ptr');
calllib('phidget21', 'CPhidgetSpatial_create', handle);
calllib('phidget21', 'CPhidget_open', handle, -1);
calllib('phidget21', 'CPhidgetSpatial_getDataRate', handle, -1)

if calllib('phidget21', 'CPhidget_waitForAttachment', handle, 2500) == 0
disp('IMU Opened')

% Start code

rt = 3; % run time for 3 seconds to see sampling

i = 0;
while rt >= toc
i = i+1;

Acc_Xdata = libpointer('doublePtr',1);
% Acc_Ydata = libpointer('doublePtr',1);
% Acc_Zdata = libpointer('doublePtr',1);

calllib('phidget21', 'CPhidgetSpatial_getAcceleration', handle, 0, Acc_Xdata);
% calllib('phidget21', 'CPhidgetSpatial_getAcceleration', handle, 1, Acc_Ydata);
% calllib('phidget21', 'CPhidgetSpatial_getAcceleration', handle, 2, Acc_Zdata);

Acc_X(i) = Acc_Xdata.Value;
% Acc_Y(i) = Acc_Xdata.Value;
% Acc_Z(i) = Acc_Xdata.Value;


end

else
disp('Could not open IMU')
end

plot(Acc_X)
% clean up
calllib('phidget21', 'CPhidget_close', handle);
calllib('phidget21', 'CPhidget_delete', handle);

%unloading the library too quickly causes issues.
pause(0.5)
unloadlibrary phidget21;

Re: Matlab - PhidgetSpatial 3/3/3

Posted: Fri Oct 09, 2020 10:38 am
by mparadis
You can use CPhidgetSpatial_setDataRate to set the data rate to be slower.

Re: Matlab - PhidgetSpatial 3/3/3

Posted: Mon Oct 12, 2020 8:41 am
by balinte94
It throws me the same answer as _getDataRate. If this work what should I write?
.
calllib('phidget21', 'CPhidgetSpatial_setDataRate', handle, 4)

Re: Matlab - PhidgetSpatial 3/3/3

Posted: Tue Oct 13, 2020 2:48 pm
by Patrick
Data Rate isn't going to help you in Matlab because it affects the event rate and Matlab doesn't support events - the best you can do is poll the data yourself. The data will be updated every 8ms. If you want to get every piece of data, you need to read it out faster than every 8ms, and you will end up with duplicate data and need to deal with that.

-Patrick