Search in sources :

Example 1 with RevoluteJoint

use of artisynth.core.mechmodels.RevoluteJoint in project artisynth_core by artisynth.

the class FrameBodyAttachment method build.

public void build(String[] args) {
    // create MechModel and add to RootModel
    mech = new MechModel("mech");
    mech.setGravity(0, 0, -98);
    mech.setFrameDamping(1.0);
    mech.setRotaryDamping(4.0);
    addModel(mech);
    // bodies will be defined using a mesh
    PolygonalMesh mesh;
    // create bodyB and set its pose
    mesh = MeshFactory.createRoundedBox(lenx1, leny1, lenz1, /*nslices=*/
    8);
    RigidTransform3d TMB = new RigidTransform3d(0, 0, 0, /*axisAng=*/
    1, 1, 1, 2 * Math.PI / 3);
    mesh.transform(TMB);
    bodyB = RigidBody.createFromMesh("bodyB", mesh, /*density=*/
    0.2, 1.0);
    bodyB.setPose(new RigidTransform3d(0, 0, 1.5 * lenx1, 1, 0, 0, Math.PI / 2));
    // create bodyA and set its pose
    mesh = MeshFactory.createRoundedCylinder(leny2 / 2, lenx2, /*nslices=*/
    16, /*nsegs=*/
    1, /*flatBottom=*/
    false);
    mesh.transform(TMB);
    bodyA = RigidBody.createFromMesh("bodyA", mesh, 0.2, 1.0);
    bodyA.setPose(new RigidTransform3d((lenx1 + leny2) / 2, 0, 1.5 * lenx1, 0, Math.PI / 2, 0));
    // create the joint
    RigidTransform3d TDW = new RigidTransform3d(-lenx1 / 2, 0, 1.5 * lenx1, 1, 0, 0, Math.PI / 2);
    RevoluteJoint joint = new RevoluteJoint(bodyB, TDW);
    // add components to the mech model
    mech.addRigidBody(bodyB);
    mech.addRigidBody(bodyA);
    mech.addBodyConnector(joint);
    // set render properties for components
    RenderProps.setLineRadius(joint, 0.2);
    joint.setAxisLength(4);
    // now connect bodyA to bodyB using a FrameAttachment
    mech.attachFrame(bodyA, bodyB);
    // create an auxiliary frame and add it to the mech model
    Frame frame = new Frame();
    mech.addFrame(frame);
    // set the frames axis length > 0 so we can see it
    frame.setAxisLength(4.0);
    // set the attached frame's pose to that of bodyA ...
    RigidTransform3d TFW = new RigidTransform3d(bodyA.getPose());
    // ... plus a translation of lenx2/2 along the x axis:
    TFW.mulXyz(lenx2 / 2, 0, 0);
    // finally, attach the frame to bodyA
    mech.attachFrame(frame, bodyA, TFW);
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) RigidTransform3d(maspack.matrix.RigidTransform3d) Frame(artisynth.core.mechmodels.Frame) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 2 with RevoluteJoint

use of artisynth.core.mechmodels.RevoluteJoint in project artisynth_core by artisynth.

the class RigidBodyConnectorList method initializePrototype.

protected void initializePrototype(ModelComponent comp, Class type) {
    if (type == RevoluteJoint.class) {
        RevoluteJoint joint = (RevoluteJoint) comp;
        joint.setAxisLength(getDefaultAxisLength());
        RenderProps.setLineRadius(joint, getDefaultLineRadius());
    } else if (type == SphericalJoint.class) {
        SphericalJoint joint = (SphericalJoint) comp;
        joint.setAxisLength(getDefaultAxisLength());
    }
}
Also used : SphericalJoint(artisynth.core.mechmodels.SphericalJoint) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint)

Example 3 with RevoluteJoint

use of artisynth.core.mechmodels.RevoluteJoint in project artisynth_core by artisynth.

the class ArticulatedFem method build.

public void build(String[] args) {
    int nlinks = 3;
    int nelemsx = 6;
    int nelemsz = 2;
    double femLength = 0.6;
    double femHeight = 0.2;
    double boxLength = 0.1;
    double boxHeight = 0.3;
    double linkLength = femLength + 2 * boxLength;
    myMechMod = new MechModel("mech");
    RigidTransform3d X = new RigidTransform3d();
    RigidBody lastBox = null;
    double linkCenter;
    RigidBody leftAnchorBox = makeBox();
    linkCenter = linkLength * (-nlinks / 2.0 + 0.5);
    X.p.set(linkCenter - (boxLength + femLength) / 2, 0, boxHeight);
    leftAnchorBox.setPose(X);
    leftAnchorBox.setDynamic(false);
    // myMechMod.addRigidBody (leftAnchorBox);
    RigidBody rightAnchorBox = makeBox();
    linkCenter = linkLength * (-nlinks / 2.0 + (nlinks - 1) + 0.5);
    X.p.set(linkCenter + (boxLength + femLength) / 2, 0, boxHeight);
    rightAnchorBox.setPose(X);
    rightAnchorBox.setDynamic(false);
    for (int i = 0; i < nlinks; i++) {
        linkCenter = linkLength * (-nlinks / 2.0 + i + 0.5);
        LinkedList<FemNode3d> leftNodes = new LinkedList<FemNode3d>();
        LinkedList<FemNode3d> rightNodes = new LinkedList<FemNode3d>();
        FemModel3d femMod = FemFactory.createTetGrid(null, femLength, femHeight, femHeight, nelemsx, nelemsz, nelemsz);
        femMod.setDensity(myDensity);
        femMod.setLinearMaterial(200000, 0.4, true);
        femMod.setGravity(0, 0, -9.8);
        double eps = 0.000001;
        for (FemNode3d n : femMod.getNodes()) {
            double x = n.getPosition().x;
            if (x <= -femLength / 2 + eps) {
                leftNodes.add(n);
            } else if (x >= femLength / 2 - eps) {
                rightNodes.add(n);
            }
        }
        femMod.setStiffnessDamping(0.002);
        RenderProps.setLineWidth(femMod.getElements(), 2);
        RenderProps.setLineColor(femMod.getElements(), Color.BLUE);
        RenderProps.setPointStyle(femMod.getNodes(), Renderer.PointStyle.SPHERE);
        RenderProps.setPointRadius(femMod.getNodes(), 0.005);
        femMod.setSurfaceRendering(SurfaceRender.Shaded);
        RenderProps.setFaceColor(femMod, new Color(0f, 0.7f, 0.7f));
        RenderProps.setLineColor(femMod.getElements(), new Color(0f, 0.2f, 0.2f));
        RenderProps.setLineWidth(femMod.getElements(), 3);
        X.p.set(linkCenter, 0, 0);
        femMod.transformGeometry(X);
        myMechMod.addModel(femMod);
        RigidBody leftBox = makeBox();
        X.p.set(linkCenter - (boxLength + femLength) / 2, 0, 0);
        leftBox.setPose(X);
        myMechMod.addRigidBody(leftBox);
        RigidBody rightBox = makeBox();
        X.p.set(linkCenter + (boxLength + femLength) / 2, 0, 0);
        rightBox.setPose(X);
        myMechMod.addRigidBody(rightBox);
        for (FemNode3d n : leftNodes) {
            myMechMod.attachPoint(n, leftBox);
        }
        for (FemNode3d n : rightNodes) {
            myMechMod.attachPoint(n, rightBox);
        }
        RigidTransform3d TCA = new RigidTransform3d();
        RigidTransform3d TCB = new RigidTransform3d();
        RevoluteJoint joint;
        TCA.p.set(-boxLength / 2, 0, boxHeight / 2);
        TCA.R.mulAxisAngle(1, 0, 0, Math.PI / 2);
        if (lastBox == null) {
            TCB.mul(leftBox.getPose(), TCA);
            // TCB.mulInverseLeft (leftAnchorBox.getPose(), TCB);
            joint = new RevoluteJoint(leftBox, TCA, TCB);
        } else {
            TCB.p.set(boxLength / 2, 0, boxHeight / 2);
            TCB.R.mulAxisAngle(1, 0, 0, Math.PI / 2);
            joint = new RevoluteJoint(leftBox, TCA, lastBox, TCB);
        }
        RenderProps.setLineRadius(joint, 0.01);
        RenderProps.setLineColor(joint, new Color(0.15f, 0.15f, 1f));
        joint.setAxisLength(0.5);
        myMechMod.addBodyConnector(joint);
        if (addLastJoint && i == nlinks - 1) {
            TCA.p.set(boxLength / 2, 0, boxHeight / 2);
            TCB.mul(rightBox.getPose(), TCA);
            // TCB.mulInverseLeft (rightAnchorBox.getPose(), TCB);
            joint = new RevoluteJoint(rightBox, TCA, TCB);
            RenderProps.setLineRadius(joint, 0.01);
            RenderProps.setLineColor(joint, new Color(0.15f, 0.15f, 1f));
            joint.setAxisLength(0.5);
            myMechMod.addBodyConnector(joint);
        }
        lastBox = rightBox;
    }
    if (!addLastJoint) {
        lastBox.setDynamic(false);
    }
    myMechMod.setIntegrator(Integrator.BackwardEuler);
    addModel(myMechMod);
    addControlPanel(myMechMod);
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) RigidTransform3d(maspack.matrix.RigidTransform3d) FemModel3d(artisynth.core.femmodels.FemModel3d) Color(java.awt.Color) FemNode3d(artisynth.core.femmodels.FemNode3d) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) RigidBody(artisynth.core.mechmodels.RigidBody) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) LinkedList(java.util.LinkedList)

Example 4 with RevoluteJoint

use of artisynth.core.mechmodels.RevoluteJoint in project artisynth_core by artisynth.

the class SkinDemo method addJoint.

public void addJoint() {
    RigidBody upperArm = model.rigidBodies().get("upper");
    RigidBody lowerArm = model.rigidBodies().get("lower");
    if (upperArm == null || lowerArm == null) {
        return;
    }
    RevoluteJoint j = new RevoluteJoint();
    j.setName("elbow");
    RigidTransform3d TCA = new RigidTransform3d();
    TCA.p.z = -len / 2;
    TCA.R.setAxisAngle(1, 0, 0, Math.PI / 2);
    RigidTransform3d TCW = new RigidTransform3d();
    TCW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
    j.setBodies(lowerArm, TCA, null, TCW);
    j.setAxisLength(len / 3);
    model.addBodyConnector(j);
    upperArm.setDynamic(false);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 5 with RevoluteJoint

use of artisynth.core.mechmodels.RevoluteJoint in project artisynth_core by artisynth.

the class DoubleArmDemo method addJoint.

public void addJoint() {
    RigidBody upperArm = model.rigidBodies().get("upper");
    RigidBody lowerArm = model.rigidBodies().get("lower");
    RigidBody thirdArm = model.rigidBodies().get("third");
    if (upperArm == null || lowerArm == null || thirdArm == null) {
        return;
    }
    RevoluteJoint j = new RevoluteJoint();
    j.setName("elbow");
    RigidTransform3d TCA = new RigidTransform3d();
    TCA.p.z = -len / 2;
    TCA.R.setAxisAngle(1, 0, 0, Math.PI / 2);
    RigidTransform3d TCW = new RigidTransform3d();
    TCW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
    j.setBodies(lowerArm, TCA, null, TCW);
    j.setAxisLength(len / 3);
    model.addBodyConnector(j);
    upperArm.setDynamic(false);
    // add joint between lower and third
    j = new RevoluteJoint();
    j.setName("wrist");
    TCA = new RigidTransform3d();
    TCA.p.z = -len / 2;
    TCA.R.setAxisAngle(1, 0, 0, Math.PI / 2);
    TCW = new RigidTransform3d();
    TCW.p.z = len / 2;
    TCW.R.setAxisAngle(1, 0, 0, Math.PI / 2);
    j.setBodies(thirdArm, TCA, lowerArm, TCW);
    j.setAxisLength(len / 3);
    model.addBodyConnector(j);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) RevoluteJoint(artisynth.core.mechmodels.RevoluteJoint) RigidBody(artisynth.core.mechmodels.RigidBody)

Aggregations

RevoluteJoint (artisynth.core.mechmodels.RevoluteJoint)10 RigidBody (artisynth.core.mechmodels.RigidBody)7 MechModel (artisynth.core.mechmodels.MechModel)6 SphericalJoint (artisynth.core.mechmodels.SphericalJoint)5 RigidTransform3d (maspack.matrix.RigidTransform3d)5 BodyConnector (artisynth.core.mechmodels.BodyConnector)4 WayPoint (artisynth.core.probes.WayPoint)3 FemModel3d (artisynth.core.femmodels.FemModel3d)2 FemNode3d (artisynth.core.femmodels.FemNode3d)2 Color (java.awt.Color)2 AxialSpring (artisynth.core.mechmodels.AxialSpring)1 CollisionManager (artisynth.core.mechmodels.CollisionManager)1 Frame (artisynth.core.mechmodels.Frame)1 FrameMarker (artisynth.core.mechmodels.FrameMarker)1 PlanarConnector (artisynth.core.mechmodels.PlanarConnector)1 MutableCompositeComponent (artisynth.core.modelbase.MutableCompositeComponent)1 LinkedList (java.util.LinkedList)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 InternalErrorException (maspack.util.InternalErrorException)1