📜 ⬆️ ⬇️

Inverse kinematics: simple and fast algorithm

What is Inverse Kinematics?

The task of inverse kinematics is the search for such a set of articulation configurations that would ensure the most gentle, fast and accurate movement to the specified points. However, many methods currently existing suffer from such disadvantages as high computational complexity and unnaturalness of the resulting postures. This article describes a new ( probably, at the time of writing the article - 2010 ) heuristic method called Forward and Backward Reverse Method ( Forward and Backward Reaching Inverse Kinematics , hereinafter simply FABRIK),
FABRIK avoids the use of rotations and matrices in favor of directly obtaining a point on a straight line. Due to this, the matter costs only a few iterations, has a low computation cost and a visually natural posture as a result. FABRIK also cope with the imposition of restrictions as well as the use of multiple chains and / or end points. It is about this method of this post.


I ask you to treat this squeeze with understanding, because the original is quite large, has a lot of water, relevant and inappropriate repetitions and separations from the topic, as well as comparisons with other algorithms. I decided to nevertheless neglect this, therefore, here there is only a small part of the text, which, however, reflects the essence - approx. trans.
')

1. Artificial body model

A system of many solids consists of a set of solids, called nodes, connected together by edges. All edges are components associated with motion: they restrict movement within a certain angle relative to adjacent edges. Virtual body modeling is important for calculating a person’s posture. A model with properly placed restrictions will allow you to get a set of correct poses, which will give you the opportunity to get a more realistic movement. Most models imply the hardness of body parts, although this is just an approximate approximation to reality.
The skeleton is usually modeled as a hierarchy of solid segments connected by edges, each of which is given by such properties as length, shape, volume and mass. The manipulator, in the manner of a robo-arm or an animated character, is modeled as a chain, assembled from solid knots, conjugated with each other by edges. Each movement and / or rotation of the bone with the index i affects all subsequent elements of the chain. A chain can be formalized as follows: every node without children should be the end point; for each end point, the chain can be formed backward in the skeleton, from parent to parent, until the root node of the chain (the beginning of the chain) is encountered. By definition, the IK problem assumes that the root node is static. However, methods usually cope with the movement of the root.

The algorithm of the full cycle algorithm FABRIK (pseudocode, the first element of the array under the index 1)
 :    p[i]  i = 1...n,   t      . d[i] = | p[i+1] - p[i] | for i = 1, ... , n-1  :   p[i], i = 1...n //     dist = | p[1] - t | //   if dist > d[1] + d[2] + ... + d[n-1] { //  for i = 1, ..., n-1 do { //  r[i]   t   p[i] r[i] = | t - p[i] | lambda[i] = d[i] / r[i] //    p[i] p[i+1] = (1 - lambda[i]) * p[i] + lambda[i] * t } } else { // ; .. b     p[1] b = p[1] //,        p[n]  //  t   (tolerance) DIFa = | p[n] - t | while DIFa > tol do { // 1 :   //   p[n]    (,   "   " - . .) p[n] = t for i=n -1 , ..., 1 do { //  r[i]   p[i]    p[i+1] r[i] = | p[i+1] - p[i] | lambda[i] = d[i] / r[i] //    p[i] p[i] = ( 1 - lambda[i]) * p[i+1] + lambda[i] * p[i] } // 2:   //   p[1]   p[i] = b for i=1 ,..., n - 1 do { //  r[i]   p[i+1]   p[i] r[i] = | p[i+1] - p[i] | lambda[i] = d[i] / r[i] //   p[i] p[i+1] = (1-lambda[i]) * p[i] + lambda[i] * p[i+1] } DIFa = | p[n] - t | } } 



2.FABRIK - a new heuristic solution of the IK problem

This section provides the essence of the FABRIK method. It uses positions already calculated in forward and reverse modes. FABRIK minimizes the error by adjusting the angle of each node once. Those. the whole chain is traversed, starting from the last node, with adjustment of the angle of each bypass node, after which the chain is already traversed in the opposite direction. This method, in contrast to the transformation of rotations, turns the problem of finding the position of a node into the problem of finding a point on a line; therefore, you can save time and reduce the number of calculations. Suppose that the set p [1], ..., p [n] is the set of positions of the nodes of the manipulator. Also, suppose that p [1] is a root node and p [n] is an end node, so for simplicity, leave one end node. The target is represented by the position t and the initial base position b . The FABRIK method is shown in the listing above and in the graphical interpretation of the complete cycle in the figure to the left, with one target point and four nodes in the circuit. Consider the full cycle of the algorithm in the figure:


In details:
First, the positions between the nodes are considered (array d ), after which it is checked whether the target point is reachable; the distance between the root node and the target ( dist ) is considered, and if this distance is less than the total sum of the distances between the nodes, then the goal is achievable, otherwise there is no. If the goal is attainable, the full cycle is limited to two stages. At the first stage, the algorithm estimates the initial position of each node, starting from the final element p [n] moving to the base of the manipulator p [1] . Thus, let the target position be the position of the end node, p '[n] = t . We obtain the line l [n-1] lying on the points p [n-1] and p '[n] . The new position of the node with the index n-1 , p '[n-1] , lies on this line at a distance d [n-1] from p' [n] . Similarly, the new position of the node with the index n-2 , p '[n-2] , can be calculated using the straight line l [n-2] lying on the points p [n-2] and p' [n-1] at a distance d [n-2] from p '[n-1] . The algorithm is repeated until all new positions are calculated for all nodes, including the final one. In cases where the root element moves to the desired position, FABRIK operates as described, with the only difference that the new position p '' [1] of the root node will be the desired position, not the initial one.
After one complete iteration, in almost all cases (as observed), the end node will approach the target. The procedure will be repeated as many times as necessary, until the end node lies on the target position or approaches it at the allowable distance. Implementation of the FABRIK method without introducing limiters will converge at any target point / chain if the goal is attainable. However, if the target is further than the reach to which the chain can stretch, an interrupting condition is needed that compares the past and current position of the end node, and which terminates the algorithm if the end node offset is less than a certain value (epsilon). Also, in special cases, the algorithm is interrupted after a certain number of iterations (however, such a situation has not yet been encountered).
For faster results and solutions in several iterations, optimization with the use of Conformal Geometric Algebra (hereinafter CGA) is possible; CGA has an advantage on basic shapes, such as spheres, straight lines, planes and circles, which are fairly simply displayed by algebraic objects. Therefore, the search for the position of a node located between two known nodes can be expressed by the intersection of two spheres with the centers at the corresponding positions of these nodes, and a radius equal to the distance between the positions of the desired node and the existing ones; The new position of the node will lie on the nearest point of the circle formed by the intersection of the two spheres. Another simple optimization is the direct construction of a straight line in the direction of the goal, when the latter is not available.

3. Model with multiple end nodes

As in the case of a single end node, the algorithm is divided into two stages:


4. Limiters

And finally, the most tasty part of this article is calculations using limiters. They are needed, as it was worth guessing, for greater similarity with real organisms. The node itself is usually characterized by three degrees of freedom. Rotation of a node can be characterized as “simple rotation” (2 degrees of freedom), which reflects its final position, and rotation around its own axis (1 degree of freedom). Thus, by dividing the movement of a node into two such phases, and applying constraints to them, you can control the position of the node. The restrictions themselves can be imposed in a similar way: the algorithm is iterative, it is possible to apply rotation restrictions at each iteration of the algorithm. Limiters, however, will not affect the convergence of the algorithm. The main idea of ​​using limiters is to reposition and reorient nodes within limits.

This procedure is repeated for all nodes, in the direct and reverse order, in the same way as in the unrestricted version of the movement. At the same time, the “ellipse” constraint is probably a characteristic of an edge, not a node, that is, in the second phase, the p [3] node should move into an ellipse - approx. trans.

Source: https://habr.com/ru/post/222689/


All Articles