tmf-code / inverse-kinematics

A typescript/javascript library for calculating inverse kinematics. Supports 2D and 3D applications.
MIT License
18 stars 4 forks source link

How to resolve joint angles? #1

Open zikaari opened 1 year ago

zikaari commented 1 year ago

I'm trying to run a 6 axis robot using this library (Node on Raspberry PI), it successfully solves the target position however I'm having hard time figuring out how I can take the link transforms (position, rotation) and convert them into joint angles that I can feed into the stepper driver to move each joint by a specific amount.

The transforms express the link position/rotation in the 3D world, but what this case requires is rotation of the individual joints.

I'd really appreciate any help!

zikaari commented 1 year ago

I should note that calculating the joint angle is quite simple for say L axis or the U axis. It's the S, R, and T axis that need resolution. image

Honga1 commented 1 year ago

Hi :) What a nice first issue, thanks for posting - surprising to hear that this is being taken into the real world with a robotic arm. I used it in a VR project to solve for elbow angles.

Do you want to find the delta angle for each time-step so the joint can rotate that amount? Or you want to know the relative (to the preceding link) rotation you need for to navigate to?

The delta angle seems straight forward. Run the simulation once at t, and once at t+1, get both rotations and subtract them.

rot_t = solve(t)
rot_t1 = solve(t+1)
delta_rot_t1 = rot_t1 - rot_t

If you want to resolve global angles to local, you'd do something like:

let rot = Global joint rotation
for each previous joint before it
    rot = rot - previous joint global rotation
relative rotation = rot

You'd use Quaternion math to do the subtractions here. I think it's Q * S^-1 (Rotation times the inverse of the subtrahend).

This is all off the top of my head, and likely fraught with errors! I don't have so much time to help you directly with your application I'm afraid.

DISCLAIMER: I take no responsibility for the use of this information w.r.t your application - since you're working with a physical system please be careful and use proper safety lockouts/procedures. See an expert if the application is a risk to life. I did not design this library with your application in mind, so it has no safety guarantees, nor do I give any with my involvement with it!