IMU Inverse Kinematics cpp code

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Claudia Pr
Posts: 1
Joined: Fri Jul 19, 2024 2:25 am

IMU Inverse Kinematics cpp code

Post by Claudia Pr » Tue Dec 17, 2024 4:27 am

Hello everyone!
I am working on IMU data analysis in C++ and I have integrated the OpenSim API into my project. Even though there are not many examples online, I tried to figure out how the IMUPlacer and IMUInverseKinematics tools and classes work.
The fact is that what I obtain from my code is slightly different from what I can obtain from the OpenSim GUI Application, and I am not able to understand what I am doing wrong.
Here is the C++ snippet:

Code: Select all

 
        auto modelProcessor = OpenSim::ModelProcessor('Rajagopal_2015.osim');
        OpenSim::Model osimModel = modelProcessor.process();
        osimModel.setName("Rajagopal_2015");
        osimModel.finalizeFromProperties();
        auto imuPlacer = OpenSim::IMUPlacer();
        imuPlacer.set_orientation_file_for_calibration(placement_fileForOpensim);
	imuPlacer.set_base_imu_label(sensorPelvis);
	SimTK::Vec3 imuPlacerRotations(-90, 0, 0);
        imuPlacer.set_sensor_to_opensim_rotations(imuPlacerRotations);
        osimModel.initSystem();
        imuPlacer.setModel(osimModel);
        imuPlacer.run();
	OpenSim::Model outputModel = imuPlacer.getCalibratedModel();
        outputModel.finalizeFromProperties();
        auto inverseKinematics = OpenSim::IMUInverseKinematicsTool();
        inverseKinematics.setModel(outputModel);
        inverseKinematics.set_orientations_file(legmvmnt_fileForOpensim);
        inverseKinematics.set_sensor_to_opensim_rotations(imuPlacerRotations);
	inverseKinematics.set_output_motion_file(output_fileForOpensim);
        inverseKinematics.run(true);
The recorded movement is a short walk, a 180-degree turn, and another short walk in the opposite direction.
If I use the same files for the IMU Placer Tool (Orientation file at placement pose as 'placement_fileForOpensim' and Rotation X set to -90) and for the IMU Inverse Kinematics Tool (Sensor orientation file as 'imuPlacerRotations' and Rotation X set to -90), I obtain the expected movement. However, it seems that the code reconstructs the movement in a different reference frame.
Here are the GUI results: https://youtube.com/shorts/dAPu3CIu2bY?feature=share and the C++ motion result https://youtube.com/shorts/dAPu3CIu2bY. Note that they are both 'frontal view'. I am using OpenSim 4.5

Tags:

POST REPLY