lanius / tinyik

A tiny inverse kinematics solver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

trouble with basic results

frueter opened this issue · comments

I am following this simple example:

import tinyik
arm = tinyik.Actuator(['z', [1., 0., 0.], 'z', [1., 0., 0.]])
arm.ee = [2 / np.sqrt(2), 2 / np.sqrt(2), 0.]
arm.angles
array([ 7.85398147e-01, 3.23715739e-08])
np.round(np.rad2deg(arm.angles))
array([ 45., 0.])

In my case I am using 3 links which look like this:
image
Red is the root (say, shoulder joint), green is parented to it (i.e. elbow) and blue is parented to green (i.e. wrist).
The yellow dot is the end effector.
So in my code I do something like:

arm = tinyik.Actuator(['z',[red.x, red.y, 0], 'z',[green.x, green.y, 0], 'z',[blue.x, blue.y, 0]])
red.angle = np.rad2deg(arm.angles[0])
green.angle = np.rad2deg(arm.angles[1])
blue.angle = np.rad2deg(arm.angles[2])

When I apply the above example and move the end effector to x=1.5, y=1.5 I get this:
image
Looks promising but doesn't seem very close to what I expected (i.e. the blue joint reaching to be as close to the end effector as possible).
When I move the end effector even closer to the left, i.e. x=1.0, y=1.5 it gets worse:
image
I'm sure I'm doing something wrong but don't know what it is.
Can you help?

Thanks,
frank

Could you show me the version of tinyik you use and all the source code? In my environment, it is version 1.2.0, and worked as follows (I assumed the size of the links to be [1, 0, 0]):

import numpy as np
import tinyik

arm = tinyik.Actuator(['z',[1, 0, 0], 'z',[1, 0, 0], 'z',[1, 0, 0]])
arm.ee = [1.5, 1.5, 0]
print('ee position', arm.ee)
# => ee position [1.50000001 1.49999999 0.        ]
print('joint angles', np.round(np.rad2deg(arm.angles)))
# => joint angles [-11.  57.  55.]

Tinyik has some tiny and naive solver which one of be used as default in older version. They are sensitive to initial angles and optimization parameters, so it may be easy to fail if you use it.

Hi, thanks for the reply.
I posted all my code and I don't know where to look up the version. I checked all the files in the package but there is no version string anywhere.
I gave it another go and now it works. I think I was one link short in my initial test.

I am glad that it worked well. You can find the version of a package with pip show command:

pip show tinyik

Ah thanks. Yes, it's 1.2.0.