% Press "F5" to run the script and then answer the questions.
% You should get a single sample from the XsensCMT DLL with both inertial and
% magnetic data as well as Euler-angles 3D orientation data.

% To view all the methods of the XsensCMT software component;
% methodsview(h) % h = handle to the object

% Xsens Technologies B.V., 2002-2008
% v.3.0.0 (SDK 3.0.0)

% set up instance of CMT in MATLAB
h=actxserver('MotionTracker.CMT');

% Create a CMT instance
% serial = 'demo1';
serial = '43206-40120-9E20D-B4A57';
if (strcmpi(serial,'demo1'))
    disp('Using "demo1" as a serial number will limit CMT usage to 1000 calls. Please use your own serial number ie. "12345-12345-12345-12345" for unlimited CMT use.');
end
h.cmtCreateInstance(serial);

St=input(['What COM-port is your MTi or MTx connected to? <1>'],'s');
COMport = str2num(St);
% assume default value for baud rate, but this can also be set
baudrate = 115200;

% call MT_SetCOMPort is required, unless using COM 1
h.cmtOpenPort(COMport,baudrate);

% Query for number of connected MTx's
[num_MTs]= h.cmtGetMtCount();
if num_MTs==0,
    error('No sensors found...exiting.')
end

% request device information from MotionTracker
[deviceId] = h.cmtGetMtDeviceId(0);
dec2hex(deviceId)

h.cmtGotoConfig();                             % Put MotionTracker in config mode

% ask if the user want to change some optional settings
[heading] = h.cmtGetHeading(deviceId)
St=input(['What heading would you like to use? <',num2str(heading),'>'],'s');
if ~isempty(St), heading=str2num(St); 
    h.cmtSetHeading(heading); end
[location] = h.cmtGetLocationId(deviceId)
St=input(['What location would you like to use? <',num2str(location),'>'],'s');
if ~isempty(St), location=str2num(St); 
    h.cmtSetLocationId(location); end
[samplefreq] = h.cmtGetSampleFrequency()
St=input(['What samplefreq would you like to use? <',num2str(samplefreq),'>'],'s');
if ~isempty(St), 
    samplefreq=str2num(St);end

% request calibrated inertial and magnetic data along with orientation data
h.cmtSetDeviceMode(6, 5, samplefreq, deviceId)     % Orientation outputmode, sample counter+euler, 100 Hz

% That's it!
% CMT is ready to start processing the data stream from the MotionTracker
h.cmtGotoMeasurement(); % start processing data

% wait short moment for object to read data from COM-port
pause(0.1);

% let CMT get next data bundle
h.cmtGetNextDataBundle()

% retrieve the data
[inertialData] = h.cmtDataGetCalData(deviceId); % get latest calibrated data from buffer
[eulerAngle] = h.cmtDataGetOriEuler(deviceId); % get latest orientation data from buffer

inertialData = double(inertialData) % data values (can be converted to double for easy use in Matlab)
eulerAngle = double(eulerAngle) % data values (can be converted to double for easy use in Matlab)

% stop processing before removing object
h.cmtClose();

% when finished with CMT, release it from the MATLAB workspace
delete(h); % release MotionTracker.CMT COM-object
clear h;
clear all;
Hide details
Change log
r70 by Abouza on Dec 11, 2009   Diff
Updates to add custom algorithm to combine
raw data from various sensors to produce
an updated postion and angle
Go to: 	
Older revisions
All revisions of this file
File info
Size: 2985 bytes, 82 lines
View raw file
File properties
svn:eol-style
native
