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.
How to use construct a custom joint in Matlab
- Brody Hicks
- Posts: 32
- Joined: Wed Jun 19, 2019 11:55 am
Re: How to use construct a custom joint in Matlab
Hi Yu,
Did you ever have any success with creating a custom joint in Matlab? I am encountering the same problem now. Thanks!
William
Did you ever have any success with creating a custom joint in Matlab? I am encountering the same problem now. Thanks!
William
- Jordan Sturdy
- Posts: 9
- Joined: Fri Sep 22, 2017 8:56 am
Re: How to use construct a custom joint in Matlab
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.
I hope this helps! Please add whatever other details you have to this thread as I'm sure it will be appreciated.
Jordan
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();
Jordan