Page 1 of 1

[Matlab-creating model] Weld joints for three bodies, fixing the foot to a platform

Posted: Thu Oct 25, 2018 7:59 am
by anacsousa
Hello,

In my model, I want to weld the foot object to a platform object that I created.

So first, I created the platform Body similar to the "DynamicWalkingStarter" from the repository:
% Platform
platform = Body();
platform.setName('Platform');
platform.setMass(1);
platform.setInertia(Inertia(1,1,1,0,0,0));

% Create Weld Joint Platform to ground
locationInParent = Vec3(0,0,0);
orientationInParent = Vec3(0,0,0);
locationInChild = Vec3(0,0,0);
orientationInChild = Vec3(0,0,0);
platformToGround = WeldJoint('PlatformToGround', ground, locationInParent, ...
orientationInParent, platform, locationInChild, orientationInChild, false);


That worked fine.
However, I also want the foot to be weld to this platform, so I got the calcn_r handle body from the model (that represents a part of the foot):
calcn_r = osimModel.updBodySet().get('calcn_r'); % get a handle to the "foot"

And then I tried to create a new weld joint (fixing the calcn-foot to the platform):
% Create Weld foot to platform
footToPlatform = WeldJoint('FootToPlatform', calcn_r, locationInParent, ...
orientationInParent, platform, locationInChild, orientationInChild, false);


However, that erases the platformToGround WeldJoint.

So I have some questions:

1) I believe it is needed to weld the platform to the ground, so it does move, correct? Is there another reason for that?
2) Is it possible to create two welds for the three bodies? If it is, how can I do that? If it is not, what should I do?
3) Should I weld all the foot objects? talus, calcn and toes?

Thanks a lot!

Re: [Matlab-creating model] Weld joints for three bodies, fixing the foot to a platform

Posted: Thu Oct 25, 2018 9:21 am
by aymanh
Hello,

Can You post the whole code snippet as the problem is likely not in the portion you posted. I assume you are using 3.3

Thanks,
Ayman

Re: [Matlab-creating model] Weld joints for three bodies, fixing the foot to a platform

Posted: Thu Oct 25, 2018 9:51 am
by anacsousa
Hello, sorry, yes, it is 3.3.

here is the code that I create the model:

% Import Java Library
clear; clc;
import org.opensim.modeling.*

%% Open the model
osimModel = Model('leg6dof9musc_hipfree_stance.osim');
osimModel.setName('leg6dof9stand_stance');

%% platform
DEG2RAD = pi/180;
RAD2DEG = 1/DEG2RAD;
PlatformLength = 10;
PlatformWidth = 0.05;
PlatformOffset = 0.5;

ground = osimModel.getGroundBody(); % Get a Handle to Ground Body
calcn_r = osimModel.updBodySet().get('calcn_r'); % get a handle to the "foot"

% Platform
platform = Body();
platform.setName('Platform');
platform.setMass(1);
platform.setInertia(Inertia(1,1,1,0,0,0));

% Create Weld Joint Platform to ground
locationInParent = Vec3(0,0,0);
orientationInParent = Vec3(0,0,0);
locationInChild = Vec3(0,0,0);
orientationInChild = Vec3(0,0,0);
platformToGround = WeldJoint('PlatformToGround', ground, locationInParent, ...
orientationInParent, platform, locationInChild, orientationInChild, false);

% Create Weld foot to platform
footToPlatform = WeldJoint('FootToPlatform', calcn_r, locationInParent, ...
orientationInParent, platform, locationInChild, orientationInChild, false);

% Add Visible Object for GUI
platform.addDisplayGeometry('box.vtp');
platform.updDisplayer().setScaleFactors([PlatformLength, PlatformWidth, 1]);
platform.updDisplayer().translate(Vec3(PlatformLength/2-PlatformOffset,0,0));

% Add Body to Model
osimModel.addBody(platform);


%% Print a new model file
osimModel.print('zz.osim');

Re: [Matlab-creating model] Weld joints for three bodies, fixing the foot to a platform

Posted: Thu Oct 25, 2018 9:53 am
by anacsousa
The navigator is only showing the "FootToPlatform"

Image

Re: [Matlab-creating model] Weld joints for three bodies, fixing the foot to a platform

Posted: Thu Oct 25, 2018 9:58 am
by aymanh
Hello,

The problem I see is that a Body refers a single Joint that connects it to the rest of the model, so if you need to do multiple welds, you'd need to use a WeldConstraint, otherwise the multi-body tree is not a tree anymore.

-Ayman

Re: [Matlab-creating model] Weld joints for three bodies, fixing the foot to a platform

Posted: Thu Oct 25, 2018 10:01 am
by anacsousa
ok, I fixed this by changing this line:
% Create Weld foot to platform
footToPlatform = WeldJoint('FootToPlatform', ground, locationInParent, ...
orientationInParent, calcn_r, locationInChild, orientationInChild, false);

I connected the foot to the ground, and not to the platform. Now both welds appear.
Capturar.PNG
Capturar.PNG (4.97 KiB) Viewed 1821 times
What's is this mtp_r?

Re: [Matlab-creating model] Weld joints for three bodies, fixing the foot to a platform

Posted: Thu Oct 25, 2018 10:27 am
by nbianco
Hi Ana,

The mtp_r is the joint for the toes. It is shorthand for the metatarsophalangeal joint. It is set as a WeldJoint in this model, but if desired, you could replace the WeldJoint with a PinJoint if you had reason to actuate the toes.

-Nick

Re: [Matlab-creating model] Weld joints for three bodies, fixing the foot to a platform

Posted: Thu Oct 25, 2018 11:10 am
by anacsousa
Thanks for the responses.
I am still struggling a little bit with these constraints.

With the weldjoint, it was too difficult to attach to the right position.
Capturar.PNG
Capturar.PNG (41.51 KiB) Viewed 1776 times
So, I tried the weld constraint. I tried two different ways, but I got two different problems.

1) I tried to add this to the XML file (my changes are in bold):

<!--Constraints in the model.-->
<ConstraintSet>
<objects>
<CoordinateCouplerConstraint name="pat_angle_r">
<!--Flag indicating whether the constraint is disabled or not. Disabled means that the constraint is not active in subsequent dynamics realization-->
<isDisabled>false</isDisabled>
<!--Constraint function of generalized coordinates (to be specified) used to evaluate the constraint errors and their derivatives, and must valid to at least 2nd order. Constraint function must evaluate to zero when coordinates satisfy constraint-->
<coupled_coordinates_function>
<LinearFunction>
<coefficients> 1 0</coefficients>
</LinearFunction>
</coupled_coordinates_function>
<!--List of names of the independent coordinates (restricted to 1 for now).-->
<independent_coordinate_names>knee_angle_r</independent_coordinate_names>
<!--Name of the dependent coordinate.-->
<dependent_coordinate_name>knee_angle_pat_r</dependent_coordinate_name>
<!--Scale factor for the function.-->
<scale_factor>1</scale_factor>
</CoordinateCouplerConstraint>
<WeldConstraint>
<isDisabled>false</isDisabled>
<body_1> calcn_r </body_1>
<body_2> ground </body_2>
<location_body_1> 0 0 0 </location_body_1>
<orientation_body_1> 0 0 0 </orientation_body_1>
<location_body_2> 0 0 0.0835 </location_body_2>
<orientation_body_2> 0 0 0 </orientation_body_2>
</WeldConstraint>

</objects>
<groups />
</ConstraintSet>


The weld constraint appears in the navigator, however I am not able to perform any forward dynamics. Nothing happens. If I disable the constraint that I created, the forward dynamics works. I am probably doing something wrong in the XML file, can you help me find what it is?


2) I found another place saying just to add this in the XML file:
<ConstraintSet>
<objects>
<CoordinateCouplerConstraint name="pat_angle_r">
<!--Flag indicating whether the constraint is disabled or not. Disabled means that the constraint is not active in subsequent dynamics realization-->
<isDisabled>false</isDisabled>
<!--Constraint function of generalized coordinates (to be specified) used to evaluate the constraint errors and their derivatives, and must valid to at least 2nd order. Constraint function must evaluate to zero when coordinates satisfy constraint-->
<coupled_coordinates_function>
<LinearFunction>
<coefficients> 1 0</coefficients>
</LinearFunction>
</coupled_coordinates_function>
<!--List of names of the independent coordinates (restricted to 1 for now).-->
<independent_coordinate_names>knee_angle_r</independent_coordinate_names>
<!--Name of the dependent coordinate.-->
<dependent_coordinate_name>knee_angle_pat_r</dependent_coordinate_name>
<!--Scale factor for the function.-->
<scale_factor>1</scale_factor>
</CoordinateCouplerConstraint>

<!-- Constrain a foot to the floor with a weld. A weld specifies a location and orientation of two frames
on separate bodies that must remain spatially coincident and aligned. -->
<WeldConstraint name="weld">
<isEnforced>true</isEnforced>
<socket_frame1> /calcn_r </socket_frame1>
<socket_frame2> /ground </socket_frame2>
</WeldConstraint>


</objects>
<groups />
</ConstraintSet>


That is not even opening in OpenSim...
Any method to make the foot fixed would work for me.

Re: [Matlab-creating model] Weld joints for three bodies, fixing the foot to a platform

Posted: Thu Oct 25, 2018 11:55 am
by aymanh
Hello,

The sockets were introduced n 4.0, so adding them to a 3.3 model and trying to open is not supported, will not work.

Your constraint appears to be working but the location of the weld is not specified correctly. You can introduce markers in the two bodies/segments you're welding to see what locations to use.

Hope this helps,
-Ayman