Seeking Assistance with Real-Time Inverse Kinematics Implementation in MATLAB using OpenSim

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Hoon Kim
Posts: 27
Joined: Wed Aug 23, 2017 9:03 pm

Seeking Assistance with Real-Time Inverse Kinematics Implementation in MATLAB using OpenSim

Post by Hoon Kim » Thu Apr 18, 2024 7:50 pm

Hello,

I am currently working on a project where I need to obtain real-time inverse kinematics outputs using MATLAB, specifically utilizing the OpenSim API.

I have successfully managed to gather real-time marker trajectories from a motion capture system within MATLAB. However, I am now faced with the challenge of implementing real-time inverse kinematics using the OpenSim API in MATLAB.

While I am aware of existing projects that address real-time inverse kinematics and inverse dynamics (https://simtk.org/projects/rtosim), I am keen on developing a MATLAB-specific version for my project.

If anyone could provide guidance, share relevant code snippets, or offer advice on how to approach this task effectively, I would greatly appreciate it.

Thank you in advance for your assistance.

Best regards,
Hoon

Tags:

User avatar
Tom Van Wouwe
Posts: 3
Joined: Sun Sep 07, 2014 9:22 am

Re: Seeking Assistance with Real-Time Inverse Kinematics Implementation in MATLAB using OpenSim

Post by Tom Van Wouwe » Fri Apr 19, 2024 3:14 am

Hello Hoon,

If you really want to have everything contained in Matlab there are at least two options:

(1) use fmincon/fminunc in combination with the API. The coordinates are optimization variables for fmincon and you use them to set the model (with markers) in the corresponding pose through the API. Then you collect the marker positions using the API and calculate the loss (i.e. distance wrt experimental markers). You will need to use numerical gradients (finite differences), which is handled by fmincon. I do not have code for this, but I think you can take inspiration from other projects that heavily use the API and use chatGPT to get you started.

(2) because I am not sure if (1) will be fast enough. You can also code your own forward kinematics (coordinates to marker positions) in matlab and use a tool like CasADi to get gradients quickly (autodifferentiation) and solve using ipopt (everything is supported if you rely on CasADi). I have an implementation in PyTorch of forward kinematics for the Rajagopal model.

There might be projects out there that will save you work, but I am unaware of these. Especially because you want to have everything in Matlab.

Tom

POST REPLY