TheComet / ik

Minimal Inverse Kinematics library
MIT License
496 stars 71 forks source link

Target has an offset when setting chain_length #4

Open Flrefly opened 4 years ago

Flrefly commented 4 years ago

When I set the effector->chain_length to something smaller than number of nodes-2, the solution has a constant offset to my specified effector->target_position. And this offset gets bigger with smaller chain_lengths.

Am I doing something wrong or is this a bug? I am using the latest master branch.

TheComet commented 4 years ago

This does sound like a bug. Can you explain your setup a bit more in detail so I can try and reproduce it? Maybe even share relevant code?

Flrefly commented 4 years ago

project.zip

I uploaded the whole project in case the error is somewhere on my side. It's just a small project, where I tried to get familiar with your library. It creates a simple kinematic chain and the end-effector should follow the cursor position.

The relevant file is the KChain.cpp. I set up the solver in line 25-48 (the ik.init already happended in the Application constructor). The method solveIK (line 75-82) is called once per frame.

The effector->chain_length is set in line 42. If I delete this line or set it to number of joints or number of joints -1, everything works fine. The error occures when I set it to number of joints -2 or smaller (in the current example 4 or smaller).