use of artisynth.core.mechmodels.Muscle in project artisynth_core by artisynth.
the class HydrostatModel method createMuscles.
public void createMuscles(Axis axis, String prefix) {
Point3d p0 = new Point3d();
Point3d p1 = new Point3d();
int cnt = 0;
for (double i = 0; i < (axis == Axis.X ? nl : nl + 1); i++) for (double j = 0; j < (axis == Axis.Y ? nr : nr + 1); j++) for (double k = 0; k < (axis == Axis.Z ? nr : nr + 1); k++) {
if (periphLongP && axis == Axis.X && ((j != 0 && j != nr) && (k != 0 && k != nr)))
continue;
p0.set(l * (i / nl - 0.5), r * (j / nr - 0.5), r * (k / nr - 0.5));
p1.set(l * ((axis == Axis.X ? i + 1 : i) / (nl) - 0.5), r * ((axis == Axis.Y ? j + 1 : j) / nr - 0.5), r * ((axis == Axis.Z ? k + 1 : k) / nr - 0.5));
Muscle f = new Muscle(findPoint(p0), findPoint(p1));
f.setConstantMuscleMaterial(muscleForce, 1);
// f.getNumber());
f.setName(prefix + (cnt++));
muscleFibres.add(f);
}
}
use of artisynth.core.mechmodels.Muscle in project artisynth_core by artisynth.
the class HydrostatModel method createBundle.
public void createBundle(String name, Point3d emin, Point3d emax, String prefix) {
Point3d pmin = new Point3d();
Point3d pmax = new Point3d();
MuscleBundle newbundle = new MuscleBundle(name);
addMuscleBundle(newbundle);
RenderProps.setLineWidth(newbundle, 4);
// great than check -- use minus minimum
emin.negate();
for (Muscle f : muscleFibres) {
pmin.set(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
pmax.set(-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE);
f.updateBounds(pmin, pmax);
// great than check -- use minus minimum
pmin.negate();
if (f.getName().startsWith(prefix) && emax.greaterEquals(pmax) && emin.greaterEquals(pmin))
newbundle.addFibre(f);
}
}
use of artisynth.core.mechmodels.Muscle in project artisynth_core by artisynth.
the class HydrostatModel method createTubeLongMuscles.
public void createTubeLongMuscles() {
MuscleBundle bundle = new MuscleBundle("long");
addMuscleBundle(bundle);
RenderProps.setLineWidth(bundle, 4);
RenderProps.setLineColor(bundle, Color.RED);
Point3d p0 = new Point3d();
Point3d p1 = new Point3d();
double dl = l / (nl - 1);
double dt = 2 * Math.PI / nt;
double dr = (r - rin) / (nr - 1);
for (double i = 0; i < nt; i++) for (double j = (periphLongP ? nr - 1 : 0); j < nr; j++) {
for (double k = 0; k < nl - 1; k++) {
p0.set(-l / 2 + k * dl, -(rin + dr * j) * Math.cos(dt * i), (rin + dr * j) * Math.sin(dt * i));
p1.set(-l / 2 + (k + 1) * dl, -(rin + dr * j) * Math.cos(dt * i), (rin + dr * j) * Math.sin(dt * i));
Muscle f = new Muscle(findPoint(p0), findPoint(p1));
f.setConstantMuscleMaterial(muscleForce, 1);
bundle.addFibre(f);
}
}
}
use of artisynth.core.mechmodels.Muscle 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();
}
use of artisynth.core.mechmodels.Muscle in project artisynth_core by artisynth.
the class ForceTargetDemo method build.
public void build(String[] args) throws IOException {
// create MechModel and add to RootModel
mech = new MechModel("mech");
addModel(mech);
// create the components
p1 = new Particle("p1", /*mass=*/
2, /*x,y,z=*/
0, 0, 0.15);
p2 = new Particle("p2", 2, 10, 0, 0.15);
p3 = new Particle("p3", 2, 5, 5, 0);
p4 = new Particle("p4", 2, 5, -5, 0);
p5 = new Particle("p5", 0, 5, 0, 5);
p6 = new Particle("p6", 0, 5, 0, -5);
box = RigidBody.createBox("box", /*wx,wy,wz=*/
0.5, 0.3, 0.3, /*density=*/
1);
box.setPose(new RigidTransform3d(/*x,y,z=*/
5, 0, -0.15));
// create marker point and connect it to the box:
FrameMarker mkr = new FrameMarker(/*x,y,z=*/
0, 0, 0.15);
mkr.setFrame(box);
// create the muscle:
muscle = new Muscle("mus1", /*restLength=*/
5);
muscle.setPoints(p1, mkr);
muscle.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
1000));
muscle2 = new Muscle("mus2", /*restLength=*/
5);
muscle2.setPoints(p2, mkr);
muscle2.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
1000));
muscle3 = new Muscle("mus3", /*restLength=*/
5);
muscle3.setPoints(p3, mkr);
muscle3.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
4000));
muscle4 = new Muscle("mus4", /*restLength=*/
5);
muscle4.setPoints(p4, mkr);
muscle4.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
4000));
muscle5 = new Muscle("mus5", /*restLength=*/
5);
muscle5.setPoints(p5, mkr);
muscle5.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
4000));
muscle6 = new Muscle("mus6", /*restLength=*/
5);
muscle6.setPoints(p6, mkr);
muscle6.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
4000));
if (two_cons == true) {
RigidTransform3d XPW = new RigidTransform3d(5, 0, 0);
XPW.R.mulAxisAngle(1, 0, 0, Math.toRadians(90));
// Connection on the corner
// PlanarConnector connector =
// new PlanarConnector (box, new Vector3d (lenx/2, -2.5, 1.5), XPW);
// Connection in the center
con = new PlanarConnector(box, new Vector3d(0, 0, 0.15), XPW);
con.setUnilateral(false);
con.setPlaneSize(2);
RenderProps props = con.createRenderProps();
props.setPointColor(Color.blue);
props.setPointStyle(Renderer.PointStyle.SPHERE);
props.setPointRadius(0.06);
con.setRenderProps(props);
// con = new ParticlePlaneConstraint(p5, pl);
// RenderProps.setDrawEdges (con, true);
// RenderProps.setVisible (con, true);
RigidTransform3d XPW2 = new RigidTransform3d(5, 0, 0);
XPW2.R.mulAxisAngle(1, 0, 0, 0);
// Connection on the corner
// PlanarConnector connector =
// new PlanarConnector (box, new Vector3d (lenx/2, -2.5, 1.5), XPW);
// Connection in the center
con2 = new PlanarConnector(box, new Vector3d(0, 0, 0.15), XPW2);
con2.setUnilateral(false);
con2.setPlaneSize(2);
con2.setRenderProps(props);
} else {
RigidTransform3d XPW = new RigidTransform3d(5, 0, 0);
XPW.R.mulAxisAngle(1, 0, 0, Math.toRadians(45));
con = new PlanarConnector(box, new Vector3d(0, 0, 0.15), XPW);
con.setUnilateral(false);
con.setPlaneSize(2);
RenderProps props = con.createRenderProps();
props.setPointColor(Color.blue);
props.setPointStyle(Renderer.PointStyle.SPHERE);
props.setPointRadius(0.06);
con.setRenderProps(props);
}
// con.setRenderProps (myRenderProps);
// add components to the mech model
mech.addParticle(p1);
mech.addParticle(p2);
mech.addParticle(p3);
mech.addParticle(p4);
mech.addParticle(p5);
mech.addParticle(p6);
mech.addRigidBody(box);
mech.addFrameMarker(mkr);
// mech.addParticle (p5);
mech.addAxialSpring(muscle);
mech.addAxialSpring(muscle2);
mech.addAxialSpring(muscle3);
mech.addAxialSpring(muscle4);
mech.addAxialSpring(muscle5);
mech.addAxialSpring(muscle6);
con.setName("con1");
if (two_cons == true) {
con2.setName("con2");
}
if (cons == true) {
mech.addBodyConnector(con);
ConnectorForceRenderer rend = new ConnectorForceRenderer(con);
myRenderProps = rend.createRenderProps();
myRenderProps.setLineStyle(LineStyle.CYLINDER);
myRenderProps.setLineRadius(0.175);
myRenderProps.setLineColor(Color.BLUE);
rend.setRenderProps(myRenderProps);
rend.setArrowSize(0.1);
addMonitor(rend);
}
if (two_cons == true) {
mech.addBodyConnector(con2);
}
// first particle set to be fixed
p1.setDynamic(false);
p2.setDynamic(false);
p3.setDynamic(false);
p4.setDynamic(false);
p5.setDynamic(false);
p6.setDynamic(false);
// increase model bounding box for the viewer
mech.setBounds(/*min=*/
-1, 0, -1, /*max=*/
1, 0, 0);
// set render properties for the components
setPointRenderProps(p1);
setPointRenderProps(p2);
setPointRenderProps(p3);
setPointRenderProps(p4);
setPointRenderProps(p5);
setPointRenderProps(p6);
setPointRenderProps(mkr);
setLineRenderProps(muscle);
setLineRenderProps(muscle2);
setLineRenderProps(muscle3);
setLineRenderProps(muscle4);
setLineRenderProps(muscle5);
setLineRenderProps(muscle6);
addTrackingController(mkr);
if (cons = true) {
addConForceProbe(10, 0.1);
}
}
Aggregations