Phylliade / ikpy

An Inverse Kinematics library aiming performance and modularity
http://phylliade.github.io/ikpy
Apache License 2.0
695 stars 152 forks source link

Ways to deal with self-collisions? #66

Closed beduffy closed 4 years ago

beduffy commented 4 years ago

Hello, great library, thanks for your work!

Is there any way to ensure that the joint angles returned from inverse kinematics won't result in a self-collision? I have my own functions for detecting these but how could I influence or change the optimisation to avoid them?

Should I change link bounds as the arm moves and is this possible/advisable?

Phylliade commented 4 years ago

Hey @beduffy,

Currently there is no support for avoiding self-collisions.

However it would be interesting to add this feature!

In order to see where we can start, could you past/explain a bit your self-collision avoidance functions?

beduffy commented 4 years ago

image

Hopefully this image makes it clearer, the blue line is going through the other blue line. If I told the real robot arm to do this there would be damage.

Generally it's quite easy to detect collisions between line segments e.g. don't include the exact endpoints since two lines share joint locations, loop through each line segment against every other line segment and return True if there is a collision.

Phylliade commented 4 years ago

Got it!

Yep, that would be indeed possible to add a collision detection function, as described.

Additionally, there is also the topic of collision avoidance, aka, proposing an IK solution that avoids collisions (e.g. not only detecting collisions, but also avoid them). Would you have any ideas on how to implement this?

beduffy commented 4 years ago

I know you use res = scipy.optimize.minimize(optimize_total, chain.active_from_full(starting_nodes_angles), method='L-BFGS-B', bounds=real_bounds, options=options) underneath so this is akin to a Jacobian/Least Squares method but in the past I've been confused over exactly how ikpy is "symbolic" or maybe it uses sympy for something else while clearly being an optimisation-based method for IK itself. For jacobian methods it's much harder to avoid collisions because we have to constrain the optimisation away from these regions and nothing is guaranteed.

Even just avoiding joint limits is a pain, this master's thesis goes deeper into that: https://pdfs.semanticscholar.org/673d/1b06d968216933d298e0eecff9fa20a2514b.pdf (Notice how common it is for methods to be much lower than 100% success rate)

I prefer analytical/geometric methods since they are faster, almost guarantee success and it's possible to directly get multiple solutions out of them but of course they are arm-specific. But I did try my own version of optimisation-based FABRIK algorithm and will try adapting that to collisions soon by rerunning the algorithm with random starting angles until one of them doesn't collide with any objects or itself but success isn't assured by doing it this way.

But if I was to make a jacobian method work with collisions it quickly turns into a motion planning problem (and not just IK) and you would have to look into OMPL, MoveIt and other libraries. Some methods generally try thousands of configurations close to the target and slowly prune out the configurations which are in collision with objects. Trac-ik and similar (https://arxiv.org/pdf/1811.00600.pdf) and relaxedIK (http://www.roboticsproceedings.org/rss14/p43.pdf) are also other resources. Self-collisions and general collision avoidance could be treated as separate cases if you wanted. Sorry I can't be of more help.

Phylliade commented 4 years ago

Thanks for the resources, will dig into that!