Hi. It would be really helpful to have a minimalistic working example in the readme or the repo. I have tried to create a minimal example of the solver based on the "goals" sample with a basic procedurally moving goal and i cannot get the solver to converge even in the simplest of cases. Copying the "goals" samples line for line without the mouse interaction also seems to lead to "DIVERGED" or "STALLED" in every case. Is there something i am missing?
Here is the code I am trying to get working. Any help appreciated, thanks
const solverOptions = {
maxIterations: 3,
divergeThreshold: 0.005,
stallThreshold: 1e-3,
translationErrorClamp: 0.25,
rotationErrorClamp: 0.25,
translationConvergeThreshold: 1e-3,
rotationConvergeThreshold: 1e-3,
restPoseFactor: 0.001,
};
let ikRoot = null;
let currRoot = null;
for ( let i = 0; i < 6; i ++ ) {
const link = new Link();
const joint = new Joint();
joint.setPosition( 0.0, 1.0, 0 );
joint.setDoF( i % 2 ? DOF.EX : DOF.EZ );
joint.setDoFValues( Math.PI / 4 );
joint.setRestPoseValues( Math.PI / 4 );
joint.restPoseSet = true;
joint.setMinLimits( - 0.9 * Math.PI );
joint.setMaxLimits( 0.9 * Math.PI );
link.addChild( joint );
if ( currRoot ) {
currRoot.addChild( link );
}
if ( ikRoot === null ) {
ikRoot = link;
}
currRoot = joint;
}
const finalLink = new Link();
finalLink.setPosition( 0, 0.5, 0 );
currRoot.addChild( finalLink );
// TODO: rotation seems not to work here
let goal = new Goal();
goal.makeClosure( finalLink );
goal.setGoalDoF(DOF.X, DOF.Y, DOF.Z);
// create solver
const solver = new Solver( [ ikRoot, goal ] );
Object.assign( solver, solverOptions );
..animationLoop()
{
goal.setPosition(Math.cos(elapsedTime) * 3.0, 3.0, 1.0);
let statuses = solver.solve();
let statusString = "";
statuses.forEach((s, i) => {
statusString+= SOLVE_STATUS_NAMES[statuses[i]] + ", ";
})
console.log(statusString);
}