How to use construct a custom joint in Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Yu Zhou
Posts: 4
Joined: Thu Jan 26, 2017 7:36 am

How to use construct a custom joint in Matlab

Post by Yu Zhou » Sun Nov 29, 2020 3:15 pm

Dear all,

I am trying to use MATLAB to build a custom joint with both 3 translations and 3 rotations. But I am having trouble adding the spatial transform part. Is there any example that I can learn how to build a custom joint? And also how to use SimmSpline function? Right now I only see examples of building either pin joint or other simple joint.

Tags:

User avatar
Brody Hicks
Posts: 32
Joined: Wed Jun 19, 2019 11:55 am

Re: How to use construct a custom joint in Matlab

Post by Brody Hicks » Mon Jan 11, 2021 8:42 am

Hi Yu,

Did you ever have any success with creating a custom joint in Matlab? I am encountering the same problem now. Thanks!

William

User avatar
Jordan Sturdy
Posts: 9
Joined: Fri Sep 22, 2017 8:56 am

Re: How to use construct a custom joint in Matlab

Post by Jordan Sturdy » Wed Jan 13, 2021 1:53 pm

Hi Yu and William,

I was just struggling with the same issue in trying to adapt some materials to the 4.1 API, and I think I got everything to work for me. I have a few items left on the todo for this as the default coordinate function in the TransformAxis is apparently a constant "0". This just means you will need to define a linear (or whatever you need) function for each axis.
One note to add: I haven't dug into the reason why yet, but you need to call "initSystem()" after adding the new joint to the model in order for the spatial transform to actually show up in the resulting model file.

Also, you hopefully don't need the "org.opensim.modeling." in front of Vec3() or SpatialTransform(), but for some reason my system wasn't recognizing these two functions without the explicit call.

Code: Select all

%% Define joint spatial transform
jntTransform = org.opensim.modeling.SpatialTransform()
rot1 = jntTransform.get_rotation1()
rot1.append_coordinates("hip_abduction")
rot2 = jntTransform.get_rotation2()
rot2.append_coordinates("hip_rotation")
rot3 = jntTransform.get_rotation3()
rot3.append_coordinates("hip_flexion")
%% Get body set
bodies = myModel.getBodySet;
%% Set up joint definitions
locationInParent    = org.opensim.modeling.Vec3(-0.0522,-0.0744,-0.0934);
orientationInParent = org.opensim.modeling.Vec3(0,0,0);
locationInChild     = org.opensim.modeling.Vec3(0,0,0);
orientationInChild  = org.opensim.modeling.Vec3(0,0,0);
%% Create Custom Joint using the constructor command
hipJNT    = org.opensim.modeling.CustomJoint('hipJNT',...  % Joint Name
                                bodies.get("pelvis"),...             % Parent Frame
                                locationInParent,...   % Translation in Parent Frame
                                orientationInParent,...% Orientation in Parent Frame
                                bodies.get("femur"),...           % Child Frame
                                locationInChild,...    % Translation in Child Frame
                                orientationInChild,... % Orientation in Child Frame
                                jntTransform);    % SpatialTransform

%% Add the new joint to the model
myModel.addJoint(hipJNT)
% Important! call initSystem before printing out the new model.
state = myModel.initSystem();
I hope this helps! Please add whatever other details you have to this thread as I'm sure it will be appreciated.

Jordan

POST REPLY