Search in sources :

Example 6 with AxialSpring

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

the class FemBeamMech method build.

public void build(String[] args) {
    femPath = "models/mech/models/fem/";
    modPath = "models/mech/";
    int nn = 2;
    myFemMod = FemFactory.createTetGrid(null, 0.6, 0.2, 0.2, nn * 3, nn * 1, nn * 1);
    myFemMod.setName("fem");
    myFemMod.setDensity(myDensity);
    myFemMod.setBounds(new Point3d(-0.6, 0, 0), new Point3d(0.6, 0, 0));
    myFemMod.setLinearMaterial(60000, 0.33, true);
    myFemMod.setStiffnessDamping(0.002);
    myFemMod.setImplicitIterations(100);
    myFemMod.setImplicitPrecision(0.001);
    myFemMod.setSurfaceRendering(SurfaceRender.Shaded);
    Renderable elems = myFemMod.getElements();
    RenderProps.setLineWidth(elems, 2);
    RenderProps.setLineColor(elems, Color.BLUE);
    Renderable nodes = myFemMod.getNodes();
    RenderProps.setPointStyle(nodes, Renderer.PointStyle.SPHERE);
    RenderProps.setPointRadius(nodes, 0.005);
    RenderProps.setPointColor(nodes, Color.GREEN);
    // fix the leftmost nodes
    double EPS = 1e-9;
    for (FemNode3d n : myFemMod.getNodes()) {
        if (n.getPosition().x < -0.3 + EPS) {
            myLeftNodes.add(n);
        }
    }
    System.out.println("fixed nodes:");
    for (FemNode3d n : myLeftNodes) {
        n.setDynamic(false);
    }
    RenderProps.setFaceColor(myFemMod, new Color(0.4f, 0.4f, 1.0f));
    myFemMod.setProfiling(true);
    RigidBody anchorBox = new RigidBody("anchorBox");
    PolygonalMesh mesh = MeshFactory.createBox(0.1, 0.3, 0.3);
    anchorBox.setMesh(mesh, /* fileName= */
    null);
    RigidTransform3d X = new RigidTransform3d();
    X.p.set(-0.35, 0, 0);
    anchorBox.setPose(X);
    anchorBox.setDynamic(false);
    myMechMod = new MechModel("mech");
    myMechMod.addModel(myFemMod);
    myMechMod.addRigidBody(anchorBox);
    System.out.println("models: " + myMechMod.findComponent("models"));
    System.out.println("models/fem: " + myMechMod.findComponent("models/fem"));
    myMechMod.setIntegrator(Integrator.BackwardEuler);
    addModel(myMechMod);
    myMechMod.setProfiling(true);
    // add marker to lower right corner element
    Point3d corner = new Point3d(0.3, -0.1, -0.1);
    FemElement cornerElem = null;
    for (FemElement e : myFemMod.getElements()) {
        FemNode[] nodeList = e.getNodes();
        for (int i = 0; i < nodeList.length; i++) {
            if (nodeList[i].getPosition().epsilonEquals(corner, 1e-8)) {
                cornerElem = e;
                break;
            }
        }
    }
    if (cornerElem != null) {
        FemMarker mkr = new FemMarker(0.3, -0.07, -0.03);
        myFemMod.addMarker(mkr, cornerElem);
        RenderProps.setPointStyle(mkr, Renderer.PointStyle.SPHERE);
        RenderProps.setPointRadius(mkr, 0.01);
        RenderProps.setPointColor(mkr, Color.WHITE);
        Particle part = new Particle(1, 0.5, -0.07, -0.03);
        RenderProps.setPointStyle(part, Renderer.PointStyle.SPHERE);
        RenderProps.setPointRadius(part, 0.01);
        part.setDynamic(false);
        myMechMod.addParticle(part);
        AxialSpring spr = new AxialSpring(1000, 0, 0);
        myMechMod.attachAxialSpring(part, mkr, spr);
        RenderProps.setLineStyle(spr, Renderer.LineStyle.SPINDLE);
        RenderProps.setLineRadius(spr, 0.01);
        RenderProps.setLineColor(spr, Color.GREEN);
    }
    int numWays = 0;
    double res = 0.2;
    for (int i = 0; i < numWays; i++) {
        addWayPoint(new WayPoint((i + 1) * res, true));
    }
    addControlPanel(myMechMod, myFemMod);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) FemNode(artisynth.core.femmodels.FemNode) Color(java.awt.Color) PolygonalMesh(maspack.geometry.PolygonalMesh) FemMarker(artisynth.core.femmodels.FemMarker) WayPoint(artisynth.core.probes.WayPoint) AxialSpring(artisynth.core.mechmodels.AxialSpring) Particle(artisynth.core.mechmodels.Particle) MechModel(artisynth.core.mechmodels.MechModel) Renderable(maspack.render.Renderable) Point3d(maspack.matrix.Point3d) FemNode3d(artisynth.core.femmodels.FemNode3d) WayPoint(artisynth.core.probes.WayPoint) RigidBody(artisynth.core.mechmodels.RigidBody) FemElement(artisynth.core.femmodels.FemElement)

Example 7 with AxialSpring

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

the class SpringMeshDemo method build.

public void build(String[] args) {
    MechModel msmod = new MechModel("msmod");
    // PropertyInfoList list = msmod.getAllPropertyInfo();
    // for (PropertyInfo info : list)
    // { System.out.println (info.getName());
    // }
    msmod.setGravity(0, 0, -9.8);
    // msmod.setGravity (0, 0, 0);
    msmod.setPointDamping(1.0);
    // msmod.setIntegrator (new ForwardEuler());
    // // set view so tha points upwards
    // X.R.setAxisAngle (1, 0, 0, -Math.PI/2);
    // viewer.setTransform (X);
    RenderProps.setPointStyle(msmod, Renderer.PointStyle.SPHERE);
    RenderProps.setPointRadius(msmod, 2);
    RenderProps.setPointColor(msmod, Color.RED);
    RenderProps.setLineRadius(msmod, 0.5);
    RenderProps.setLineStyle(msmod, Renderer.LineStyle.CYLINDER);
    // PlaneCollider collider =
    // new PlaneCollider("plane",
    // new Plane(0, 0, 1, planeZ), 200, 50);
    // collider.setRenderPosition (new Point3d(0, 0, 0), 25);
    // collider.addMechModel (msmod);
    RenderProps props = (new Particle()).createRenderProps();
    props.setPointRadius(2);
    props.setPointStyle(Renderer.PointStyle.SPHERE);
    props.setPointColor(Color.GREEN);
    Particle p0 = new Particle(5, -10, 0, 20);
    p0.setRenderProps(props);
    p0.setDynamic(false);
    Particle p1 = new Particle(5, 0, 0, 25);
    p1.setRenderProps(props);
    Particle p2 = new Particle(5, 0, 0, 15);
    p2.setRenderProps(props);
    Particle p3 = new Particle(5, 10, 0, 20);
    p3.setRenderProps(props);
    AxialSpring[] springs = new AxialSpring[10];
    for (int i = 0; i < springs.length; i++) {
        springs[i] = new AxialSpring(50, 20, 10);
    }
    msmod.particles().addNumbered(p0, 5);
    msmod.particles().addNumbered(p1, 4);
    msmod.particles().addNumbered(p2, 0);
    msmod.particles().addNumbered(p3, 1);
    // msmod.particles().add (p0);
    // msmod.particles().add (p1);
    // msmod.particles().add (p2);
    // msmod.particles().add (p3);
    msmod.attachAxialSpring(p0, p1, springs[0]);
    msmod.attachAxialSpring(p0, p2, springs[1]);
    msmod.attachAxialSpring(p1, p2, springs[2]);
    msmod.attachAxialSpring(p1, p3, springs[3]);
    msmod.attachAxialSpring(p2, p3, springs[4]);
    Particle p10 = new Particle(5, 10, 0, 20);
    Particle p11 = new Particle(5, 5, 0, 10);
    Particle p12 = new Particle(5, 15, 0, 10);
    Particle p13 = new Particle(5, 10, 0, 0);
    msmod.addParticle(p10);
    msmod.addParticle(p11);
    msmod.addParticle(p12);
    msmod.addParticle(p13);
    // add names to some particles so they can be found for probing and
    // attachment
    p0.setName("pnt0");
    p3.setName("pntA");
    p10.setName("pntB");
    p13.setName("pnt7");
    msmod.attachAxialSpring(p10, p11, springs[5]);
    msmod.attachAxialSpring(p10, p12, springs[6]);
    msmod.attachAxialSpring(p11, p12, springs[7]);
    msmod.attachAxialSpring(p11, p13, springs[8]);
    msmod.attachAxialSpring(p12, p13, springs[9]);
    // test for bad component insertion:
    // Particle px = new Particle (5, 10, 0, 0);
    // Particle py = new Particle (5, 10, 0, 0);
    // msmod.attachAxialSpring (px, py, new AxialSpring (50, 20, 10));
    msmod.setBounds(new Point3d(0, 0, -25), new Point3d(0, 0, 25));
    addModel(msmod);
    msmod.scaleMass(4);
    setAttachment(true);
    // int numWays = 10;
    // double res = 1;
    // for (int i=0; i<numWays; i++)
    // { Main.getWorkspace().addWayPoint (
    // new WayPoint(TimeBase.secondsToTicks((i+1)*res), true));
    // }
    addControlPanel();
    addProbes(msmod);
    addWayPoint(0.5);
    // addBreakPoint (1.0);
    addWayPoint(1.0);
    addWayPoint(1.5);
    ReferenceList refs = new ReferenceList("refs");
    refs.addReference(p0);
    refs.addReference(p1);
    refs.addReference(p10);
    refs.addReference(p11);
    refs.addReference(msmod.particles());
    msmod.add(refs);
// msmod.setProfiling (true);
}
Also used : Particle(artisynth.core.mechmodels.Particle) MechModel(artisynth.core.mechmodels.MechModel) AxialSpring(artisynth.core.mechmodels.AxialSpring)

Example 8 with AxialSpring

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

the class ForceTargetDemo method addTrackingController.

public void addTrackingController(FrameMarker mkr) throws IOException {
    TrackingController myTrackingController = new TrackingController(mech, "tcon");
    for (AxialSpring s : mech.axialSprings()) {
        if (s instanceof Muscle) {
            myTrackingController.addExciter((Muscle) s);
        }
    }
    // myTrackingController.addTerm(new StiffnessTerm(model, center));
    // StiffnessTerm kTerm = TrackingController.addStiffnessTarget(center, new int[]{0,2});
    // kTerm.setStiffnessTargetType(StiffnessTargetType.DIAG);
    // ComplianceTerm2d cterm = new ComplianceTerm2d(TrackingController, center, new int[]{0,2});
    // cterm.setComplianceTargetType(StiffnessTargetType.DIAG);
    // TrackingController.addTerm(cterm);
    myTrackingController.addL2RegularizationTerm();
    // myTrackingController.addTerm(new DampingTerm(TrackingController));
    // myTrackingController.addTerm(new StaticMotionTargetTerm(TrackingController));
    myTrackingController.addMotionTarget(mkr);
    setPointRenderProps((TargetPoint) myTrackingController.getMotionTargets().get(0));
    ForceTargetTerm mft = new ForceTargetTerm(myTrackingController);
    // mft.addMotionTarget(mkr);
    // setPointRenderProps((TargetPoint) mft.getMotionTargets ().get (0));
    double[] lam = { -3.5 };
    VectorNd tarlam = new VectorNd(lam);
    if (cons == true) {
        ForceTarget ft = mft.addForceTarget(con);
        ft.setTargetLambda(tarlam);
    }
    if (two_cons == true) {
        ForceTarget ft = mft.addForceTarget(con2);
        ft.setTargetLambda(tarlam);
    }
    if (force == true) {
        myTrackingController.addForceTargetTerm(mft);
    }
    // myTrackingController.getSolver().setBounds(0.01, 0.99);
    // setWorkingDir();
    // loadForceInputProbe(mft);
    myTrackingController.setProbeDuration(10.0);
    myTrackingController.createProbesAndPanel(this);
    addController(myTrackingController);
    reloadTargetProbeData();
}
Also used : VectorNd(maspack.matrix.VectorNd) SimpleAxialMuscle(artisynth.core.materials.SimpleAxialMuscle) Muscle(artisynth.core.mechmodels.Muscle) ForceTargetTerm(artisynth.core.inverse.ForceTargetTerm) ForceTarget(artisynth.core.inverse.ForceTarget) AxialSpring(artisynth.core.mechmodels.AxialSpring) TrackingController(artisynth.core.inverse.TrackingController)

Example 9 with AxialSpring

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

the class PointModel method add1dMuscles.

public void add1dMuscles() {
    boolean[] dyn = new boolean[] { false, true, false };
    int[] x = new int[] { -1, 0, 1 };
    // boolean[] dyn = new boolean[]{false,true, true, true,false};
    // int[] x = new int[]{-2,-1,0,1,2};
    // double eps = 1e-4;
    ArrayList<Point> pts = new ArrayList<Point>(x.length);
    for (int i = 0; i < x.length; i++) {
        Point3d pnt = new Point3d(x[i], 0, 0);
        // pnt.normalize();
        pnt.scale(len);
        Particle pt = new Particle(mass, pnt);
        pt.setPointDamping(pointDamping);
        pt.setDynamic(dyn[i]);
        model.addParticle(pt);
        pts.add(pt);
        if (x[i] == 0) {
        // center = pt;
        }
    }
    for (int i = 1; i < pts.size(); i++) {
        AxialSpring m;
        Point p0 = pts.get(i - 1);
        Point p1 = pts.get(i);
        // if (p0==center || p1==center)
        // m = addAxialSpring(p0, p1);
        // else
        m = addMuscle(p0, p1);
        m.setName("m" + Integer.toString(m.getNumber()));
    }
}
Also used : Particle(artisynth.core.mechmodels.Particle) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) Point(artisynth.core.mechmodels.Point) Point(artisynth.core.mechmodels.Point) SphericalJoint(artisynth.core.mechmodels.SphericalJoint) AxialSpring(artisynth.core.mechmodels.AxialSpring)

Example 10 with AxialSpring

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

the class DoubleArmDemo method addMuscles.

public void addMuscles() {
    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;
    }
    Point3d markerBodyPos = new Point3d(-size.x / 2, 0, (size.z / 2.0) / 1.2);
    FrameMarker u = new FrameMarker();
    model.addFrameMarker(u, upperArm, markerBodyPos);
    u.setName("upperAttachment");
    markerBodyPos = new Point3d(size.x / 2, 0, (size.z / 2.0) / 1.2);
    FrameMarker tu = new FrameMarker();
    model.addFrameMarker(tu, thirdArm, markerBodyPos);
    tu.setName("thirdUpperAttachment");
    markerBodyPos = new Point3d(size.x / 2, 0, -(size.z / 2.0) / 2);
    FrameMarker l = new FrameMarker();
    model.addFrameMarker(l, lowerArm, markerBodyPos);
    l.setName("lowerAttachment");
    markerBodyPos = new Point3d(size.x / 2, 0, (size.z / 2.0) / 2);
    FrameMarker tl = new FrameMarker();
    model.addFrameMarker(tl, lowerArm, markerBodyPos);
    tl.setName("thirdLowerAttachment");
    Muscle muscle = new Muscle("muscle");
    muscle.setPeckMuscleMaterial(20.0, 22.0, 30, 0.2, 0.5, 0.1);
    Muscle muscle2 = new Muscle("muscle2");
    muscle2.setPeckMuscleMaterial(8, 20, 30, 0.2, 0.5, 0.1);
    muscle.setFirstPoint(u);
    muscle2.setFirstPoint(tu);
    muscle.setSecondPoint(l);
    muscle2.setSecondPoint(tl);
    RenderProps rp = new RenderProps(model.getRenderProps());
    rp.setLineStyle(Renderer.LineStyle.SPINDLE);
    rp.setLineRadius(len / 20);
    // rp.setLineSlices(10);
    rp.setShading(Renderer.Shading.SMOOTH);
    rp.setLineColor(Color.RED);
    muscle.setRenderProps(rp);
    muscle2.setRenderProps(rp);
    model.addAxialSpring(muscle);
    model.addAxialSpring(muscle2);
    if (addCompression) {
        markerBodyPos = new Point3d(size.x / 2, 0, +size.z / 2.0);
        FrameMarker l2 = new FrameMarker();
        model.addFrameMarker(l2, lowerArm, markerBodyPos);
        l2.setName("lowerAttachmentCompressor");
        double len = u.getPosition().distance(l2.getPosition());
        AxialSpring s = new AxialSpring(10, 0, 50);
        s.setFirstPoint(u);
        s.setSecondPoint(l2);
        model.addAxialSpring(s);
        RenderProps props = new RenderProps();
        props.setLineStyle(Renderer.LineStyle.CYLINDER);
        props.setLineRadius(0.0);
        s.setRenderProps(props);
        // restoring spring
        len = tu.getPosition().distance(tl.getPosition());
        s = new AxialSpring(10, 0, 2 * len);
        s.setFirstPoint(tu);
        s.setSecondPoint(tl);
        model.addAxialSpring(s);
        s.setRenderProps(props);
    }
}
Also used : FrameMarker(artisynth.core.mechmodels.FrameMarker) Point3d(maspack.matrix.Point3d) RenderProps(maspack.render.RenderProps) Muscle(artisynth.core.mechmodels.Muscle) RigidBody(artisynth.core.mechmodels.RigidBody) AxialSpring(artisynth.core.mechmodels.AxialSpring)

Aggregations

AxialSpring (artisynth.core.mechmodels.AxialSpring)20 Particle (artisynth.core.mechmodels.Particle)10 Muscle (artisynth.core.mechmodels.Muscle)8 Point3d (maspack.matrix.Point3d)8 RigidBody (artisynth.core.mechmodels.RigidBody)5 FrameMarker (artisynth.core.mechmodels.FrameMarker)4 MechModel (artisynth.core.mechmodels.MechModel)4 LinearAxialMuscle (artisynth.core.materials.LinearAxialMuscle)3 SphericalJoint (artisynth.core.mechmodels.SphericalJoint)3 Color (java.awt.Color)3 RenderProps (maspack.render.RenderProps)3 ForceTarget (artisynth.core.inverse.ForceTarget)2 ForceTargetTerm (artisynth.core.inverse.ForceTargetTerm)2 TrackingController (artisynth.core.inverse.TrackingController)2 Point (artisynth.core.mechmodels.Point)2 WayPoint (artisynth.core.probes.WayPoint)2 RigidTransform3d (maspack.matrix.RigidTransform3d)2 FemElement (artisynth.core.femmodels.FemElement)1 FemMarker (artisynth.core.femmodels.FemMarker)1 FemNode (artisynth.core.femmodels.FemNode)1