Page 1 of 1

Bodies, joints and coordinates

Posted: Wed Mar 29, 2017 7:26 am
by mgcarrilho
Hello,

I am creating a model, so I have to bodies connected through a PinJoint. When I move the lower body using coordinates it separates from the upper body like if they are independent. Any ideia how to solve this?


Regards,
Marta

Re: Bodies, joints and coordinates

Posted: Wed Mar 29, 2017 7:56 am
by didix21
I suppose that you want to move all the body not only the lower body. If it is the case, then I put the following example in C++.

Code: Select all

 // This create all the bodies
        OpenSim::Body* link1 = new OpenSim::Body("link1", linkageMass, linkageMassCenter,
                                                 linkageMass*linkageInertia);
        // Graphical representation
        link1->addDisplayGeometry("cylinder.vtp");

        // This cylinder.vtp geometry is 1 meter tall, 1 meter diameter. Sclae it
        GeometrySet& geometry = link1->updDisplayer()->updGeometrySet();
        DisplayGeometry& thinCylinder = geometry[0];
        thinCylinder.setScaleFactors(linkageDimensions);
        thinCylinder.setTransform(Transform(Vec3(0.0, linkageLength/2.0, 0.0)));
        link1->addDisplayGeometry("sphere.vtp");
        // This sphere.vtp is 1 meter in diameter. Scale it.
        geometry[1].setScaleFactors(Vec3(0.1));

        // Create a second linkage body
        OpenSim::Body* link2 = new OpenSim::Body(*link1);
        link2->setName("link2");

        OpenSim::Body* link3 = new OpenSim::Body(*link1);
        link3->setName("link3");
        
        // Now we use the pinjoint class to link them.
        
        // Create 1 degree-of-freedom pin joints between the bodies to create a kinematic chain
        Vec3 orientationInGround(0), locationInGround(0), locationInParent(0.0, linkageLength, 0.0),
                orientationInChild(0), locationInChild(0);

        PinJoint *ankle = new PinJoint("ankle", ground, locationInGround, orientationInGround, *link1,
                                       locationInChild, orientationInChild);
        PinJoint *knee = new PinJoint("knee", *link1, locationInParent, orientationInChild, *link2,
                                      locationInChild, orientationInChild);
        PinJoint *hip1 = new PinJoint("hip1", *link2, locationInParent, orientationInChild, *link3,
                                     locationInChild, orientationInChild);
                                     
        // In this case we have three joints, then if we want to move all the body,
        // we have to move the first one because it is attached to the ground
        
        ankle->setLocationInParent(Vec3(0,1,0));
        
                // Add all the bodies to the model
        osimModel.addBody(link1);
        osimModel.addBody(link2);
        osimModel.addBody(link3);

        

        

Re: Bodies, joints and coordinates

Posted: Fri Mar 31, 2017 7:54 pm
by tkuchida
The "From the Ground Up: Building a Passive Dynamic Walker Model" example may be helpful: http://simtk-confluence.stanford.edu:80 ... lker+Model.