gkjohnson / urdf-loaders

URDF Loaders for Unity and THREE.js with example ATHLETE URDF Files open sourced from NASA JPL
https://gkjohnson.github.io/urdf-loaders/javascript/example/bundle/index.html
Apache License 2.0
469 stars 121 forks source link

Forward Kinematics #258

Closed vantony1 closed 1 year ago

vantony1 commented 1 year ago

Hello,

Thank you for making this library! It looks awesome and I am looking to use it for my project.

I can't figure out how to get forward kinematics to work here. I want to move from a joint configuration A to configuration B and then to config C. Could you please point me in the right direction?

I noticed that in the example you use a lerp function to follow a sinusoidal pattern -- but that won't work for my needs I don't think.

This is my current test implementation but it just sets position abruptly there's no movement.

  const animateRobot = async () => {
    const position1 = [ 0.5, -0.5, 0.2 ];
    const position2 = [ -0.5, 0.5, -0.2 ];
    const position3 = [ 0, 0, 0 ];

    const positions = [position1, position2, position3];
    for (const position of positions) {
      robot.joints['elbow'].setJointValue(position[0]);
      robot.joints['shoulder'].setJointValue(position[1]);
      robot.joints['wrist'].setJointValue(position[2]);
      await new Promise((resolve) => setTimeout(resolve, 1000));
    }
  };
gkjohnson commented 1 year ago

Hello! This is a fairly general question about animation in Javascript that unfortunately is more in depth than I have time to dive into. The short of it is that you should be using an animation loop, track the target state, and interpolate the angles (using something like lerp) every frame until the target is reached.

I recommend asking for help at the three.js forum if you need more in depth insight into how to animate one numeric value towards another smoothly over time: https://discourse.threejs.org/