Opensim for use with XSENS
Posted: Tue Jan 23, 2024 5:14 am
I am writing on behalf of an ergonomics group in Cardiff university, working on a project involving analysis of ACL strain, using data from an XSENS suit (with no force plates).
At the moment we are trying to scale the generic model. We have been using a .trc file that we created using a c3d toolkit, that convert c3d data to .trc. The c3d file was derived from XSENS analyse, where the participant stayed still in a T-pose for 5 seconds.
We have also tried to convert the c3d file to an xml file to get the marker set, which we have done using a btk toolkit in matlab to read the c3d file and extract the marker set, and the xml_writeOSIM.m file to write the xml file. When we load those files for scaling, it seems to be working, however when we try the inverse kinematics step, it comes up with a no marker error.
Below is our matlab code to convert the .c3d file to a .xml. % Add BTK to MATLAB path
addpath('C:\Users\User\Downloads\BTKCore-master\Build\Bin\Debug');
% Specify the path to your C3D file
c3dFilePath = 'C:\Users\User\Downloads\LangXi-2\Subject1.c3d'
% Read the C3D file using BTK
acq = btkReadAcquisition(c3dFilePath);
% Extract marker data from the acquisition
markers = btkGetMarkers(acq);
% Convert marker data into a structure format expected by OpenSim
OpenSimMarkers = struct();
OpenSimMarkers.OpenSimDocument.Version = '40000';
OpenSimMarkers.OpenSimDocument.MarkerSet.objects = struct();
markerNames = fieldnames(markers);
for i = 1:length(markerNames)
markerName = markerNames{i};
markerData = markers.(markerName);
OpenSimMarkers.OpenSimDocument.MarkerSet.objects.(markerName) = struct();
OpenSimMarkers.OpenSimDocument.MarkerSet.objects.(markerName).Marker = struct();
OpenSimMarkers.OpenSimDocument.MarkerSet.objects.(markerName).Marker.location = markerData(1, ;
end
% Specify the path for the output XML file
xmlOutputPath = 'C:\Users\User\Downloads\Subject1\Subject1.xml';
% Save the OpenSim marker structure as an XML file
xml_writeOSIM(xmlOutputPath, OpenSimMarkers);
% Display completion message
disp('C3D file has been converted to XML format.');
At the moment we are trying to scale the generic model. We have been using a .trc file that we created using a c3d toolkit, that convert c3d data to .trc. The c3d file was derived from XSENS analyse, where the participant stayed still in a T-pose for 5 seconds.
We have also tried to convert the c3d file to an xml file to get the marker set, which we have done using a btk toolkit in matlab to read the c3d file and extract the marker set, and the xml_writeOSIM.m file to write the xml file. When we load those files for scaling, it seems to be working, however when we try the inverse kinematics step, it comes up with a no marker error.
Below is our matlab code to convert the .c3d file to a .xml. % Add BTK to MATLAB path
addpath('C:\Users\User\Downloads\BTKCore-master\Build\Bin\Debug');
% Specify the path to your C3D file
c3dFilePath = 'C:\Users\User\Downloads\LangXi-2\Subject1.c3d'
% Read the C3D file using BTK
acq = btkReadAcquisition(c3dFilePath);
% Extract marker data from the acquisition
markers = btkGetMarkers(acq);
% Convert marker data into a structure format expected by OpenSim
OpenSimMarkers = struct();
OpenSimMarkers.OpenSimDocument.Version = '40000';
OpenSimMarkers.OpenSimDocument.MarkerSet.objects = struct();
markerNames = fieldnames(markers);
for i = 1:length(markerNames)
markerName = markerNames{i};
markerData = markers.(markerName);
OpenSimMarkers.OpenSimDocument.MarkerSet.objects.(markerName) = struct();
OpenSimMarkers.OpenSimDocument.MarkerSet.objects.(markerName).Marker = struct();
OpenSimMarkers.OpenSimDocument.MarkerSet.objects.(markerName).Marker.location = markerData(1, ;
end
% Specify the path for the output XML file
xmlOutputPath = 'C:\Users\User\Downloads\Subject1\Subject1.xml';
% Save the OpenSim marker structure as an XML file
xml_writeOSIM(xmlOutputPath, OpenSimMarkers);
% Display completion message
disp('C3D file has been converted to XML format.');