Page 1 of 2
Lock coordinate while creating the model
Posted: Tue Jul 11, 2017 5:14 pm
by haolee
I am modifying the DynamicWalkingStarter to more degree of freedom. I add a FreeJoint in the model, but only want it to have 3 DOF. I try to call the "setLocked" in my matlab code but failed to execute it.
Part of code is shown as below (without setLocked since it failed, now I set the range to 0 but this isn't what I want)
Code: Select all
platformToPelvis = FreeJoint('PlatformToPelvis',platform,locationInParent,orientationInParent,pelvis,locationInChild,orientationInChild,false);
% Update the coordinates of the new joint
jointCoordinateSet1 = platformToPelvis.upd_CoordinateSet();
jointCoordinateSet1.get(0).setRange([0, 0]);
jointCoordinateSet1.get(0).setName('Pelvis_rx');
jointCoordinateSet1.get(0).setDefaultValue(0);
jointCoordinateSet1.get(0).setLocked(true);
jointCoordinateSet1.get(1).setRange([0, 0]);
jointCoordinateSet1.get(1).setName('Pelvis_ry');
jointCoordinateSet1.get(1).setDefaultValue(0);
jointCoordinateSet1.get(2).setRange([-pi, pi]);
jointCoordinateSet1.get(2).setName('Pelvis_rz');
jointCoordinateSet1.get(2).setDefaultValue(0);
jointCoordinateSet1.get(3).setRange([0, 10]);
jointCoordinateSet1.get(3).setName('Pelvis_px');
jointCoordinateSet1.get(3).setDefaultValue(0.9);
jointCoordinateSet1.get(4).setRange([0, 10]);
jointCoordinateSet1.get(4).setName('Pelvis_py');
jointCoordinateSet1.get(4).setDefaultValue(0);
jointCoordinateSet1.get(5).setRange([0, 0]);
jointCoordinateSet1.get(5).setName('Pelvis_pz');
jointCoordinateSet1.get(5).setDefaultValue(0);
The whole m file could be download in the below link
https://drive.google.com/open?id=0B4Av7 ... TlHb0pOVDA
I checked the API, it said the setLocked function is defined as
Code: Select all
setLocked (SimTK::State &s, bool aLocked) const
I wonder how could I get the State in matlab?
Re: Lock coordinate while creating the model
Posted: Tue Jul 11, 2017 5:23 pm
by jimmy
I wonder how could I get the State in matlab?
Re: Lock coordinate while creating the model
Posted: Wed Jan 29, 2020 10:26 am
by idhamari
I there a way to do this in cpp?
I tried something like
Code: Select all
myJoint->getCoordinate().setLocked(state, true);
the model is created but there is no lock. It works correctly in the visualizer but not in the gui interface as I have to lock the joint manually using the coordinates tab. Here is part of the code. The complete example can be found in this post
https://simtk.org/plugins/phpBB/viewt ... t=0&view=
Code: Select all
Model pendulumDF; // DF =Drag Force
pendulumDF.setName("pendulumDF");
pendulumDF.setGravity(SimTK::Vec3(0, gravity, 0));
Ground& ground = pendulumDF.updGround();
// body name, mass ,massCenter, inertia
Body* rodBdy = new Body("rod", rodMass, rodCoM, rodInertia );
Cylinder rodGeom (rodRd , rodHeight);
rodGeom.setColor(rodColor); //set the color of the first block so they are different
SimTK::Transform rodTrsfrm(SimTK::Vec3(0,0,0));
auto* rodCenter = new PhysicalOffsetFrame("rodCenter", *rodBdy, rodTrsfrm);
rodBdy->addComponent(rodCenter); rodCenter->attachGeometry(rodGeom.clone());
pendulumDF.addBody(rodBdy);
// Connect the bodies with pin joints. Assume each body is 1 m long.
auto* groundTrodJnt = new PinJoint("groundTrodJnt", pendulumDF.getGround(), Vec3(0), Vec3(0), *rodBdy, rodPos, rodOrient);
pendulumDF.addJoint(groundTrodJnt);
Body* sphBdy = new Body("sph", sphMass, sphCoM, sphInertia );
Sphere sphGeom (sphRd);
sphGeom.setColor(sphColor); //set the color of the first block so they are different
SimTK::Transform sphTrsfrm(SimTK::Vec3( 0, 0, 0));
auto* sphCenter = new PhysicalOffsetFrame("sphCenter", *sphBdy, sphTrsfrm);
sphBdy->addComponent(sphCenter); sphCenter->attachGeometry(sphGeom.clone());
pendulumDF.addBody(sphBdy);
auto* rodTsphJnt= new PinJoint ("rodTsphJnt", *rodBdy,Vec3(0), Vec3(0), *sphBdy, Vec3(0), Vec3(0));
rodTsphJnt = new PinJoint ("rodTsphJnt", *rodBdy, Vec3(sphX-rodHeight,sphY,0), rodOrient, *sphBdy, sphPos, sphOrient);
pendulumDF.addJoint(rodTsphJnt);
pendulumDF.finalizeConnections();
// Initialize the system and get the default state
SimTK::State& si = pendulumDF.initSystem();
rodTsphJnt->getCoordinate().setLocked(si, true); // the sphere is fixed to rod
pendulumDF.print(pendulumDF.getName()+".osim");
Re: Lock coordinate while creating the model
Posted: Wed Jan 29, 2020 10:36 am
by tkuchida
The line
Code: Select all
rodTsphJnt->getCoordinate().setLocked(si, true);
modifies the state, which is not written to the model file. I think you want to set the default value of the "locked" property, which you can do with the
setDefaultLocked() method:
https://simtk.org/api_docs/opensim/api_ ... 9fa818c53a.
Re: Lock coordinate while creating the model
Posted: Wed Jan 29, 2020 11:17 am
by idhamari
Thanks for the info, I tried :
Code: Select all
rodTsphJnt->getCoordinate().setDefaultLocked( true);
and I get
Code: Select all
BodyDragExampleComplete/pendulumDF.cpp:117: error: passing const OpenSim::Coordinate as this argument discards qualifiers -fpermissive
I also tried
Code: Select all
rodTsphJnt->getCoordinate().setDefaultLocked( true);
The code is compiled but there is no effect, the joints still unlocked when I load the model to the gui.
Re: Lock coordinate while creating the model
Posted: Wed Jan 29, 2020 11:36 am
by aymanh
Hello,
Calling
is the correct solution, however you need to use
so that you get a writable reference rather than a constant reference and the side effects are propagated.
Hope this helps,
-Ayman
Re: Lock coordinate while creating the model
Posted: Wed Jan 29, 2020 11:55 am
by idhamari
Thanks for your input. Still doesn't work
rodTsphJnt->getCoordinate() does not have setDefaultLocked function same error above
with this
Code: Select all
Coordinate jntCord = rodTsphJnt->getCoordinate();
jntCord.setDefaultLocked(true);
rodTsphJnt->updCoordinate();
still the same effect. No lock in the model file or in the gui.
Re: Lock coordinate while creating the model
Posted: Wed Jan 29, 2020 12:00 pm
by idhamari
A workaround is to add this to joint coordinate xml part
Re: Lock coordinate while creating the model
Posted: Wed Jan 29, 2020 12:32 pm
by tkuchida
I would try something like this:
Code: Select all
Coordinate& coord = rodTsphJnt->updCoordinate();
coord.setDefaultLocked(true);
Re: Lock coordinate while creating the model
Posted: Wed Jan 29, 2020 3:28 pm
by idhamari
Thanks Thomas for the reply.
I would try something like this:
Code: Select all
Coordinate& coord = rodTsphJnt->updCoordinate();
coord.setDefaultLocked(true);
I don't see a difference, or am I missing something?
Code: Select all
Coordinate jntCord = rodTsphJnt->getCoordinate();
jntCord.setDefaultLocked(true);
with or without the third line rodTsphJnt->updCoordinate(); there is no effect.