## Inverse kinematics

Suppose you have an equation (describing for example a robot arm) that gives you a position of the end-effector (for example fingers of a robotic arm) when input like joint angles is provided. This would be Forward kinematics (FK). Opposite problem when position of the end-effector (goal) serves as input and joint angles are on output is called Inverse kinematics (IK).

While FK is relatively easy to compute (you may use coordinate systems described here) the IK is more challenging. There are often several solutions available but some problems do not have any one (for example when the goal is out of the arm's reach).

There are several algorithms to solve the IK problem. The Jacobian matrix will be used here.

The Jacobian matrix is the matrix of all first-order partial derivatives of a vector-valued function. Or sometimes referred to as matrix of partial derivatives of entire system.

\begin{aligned} J & = \begin{bmatrix} \frac{\partial f1}{\partial x1} & \frac{\partial f1}{\partial x2} \\ \frac{\partial f2}{\partial x1} & \frac{\partial f2}{\partial x2}\end{bmatrix} \qquad (1) \end{aligned}

Note 1: The Jacobian has also been used in the article "LTI systems 2".
Note 2: Sometimes the Jacobian matrix is called "Functional matrix".

To get some intuition of the Jacobian matrix, view on it as a linear approximation of a (usually non-linear) function $f()$ at a point $\bar{p}$.

In our case,

- the function $f()$ is the function that returns position of the end-effector and takes robot arm join angles (or maybe it takes as input number of ticks in case there are servo motors, or current, or ... it does not matter what).
- the point $\bar{p}$ is an actual position of the end-effector (probably out of the goal, but may also be right at the goal).
- the Jacobian defines how the position of end-effector changes relative to tiny change (limit to zero) of the input (of the system).

It is sometimes possible to compute Jacobian analytically (it is difficult though) but numerical computation servers good as well.

Some math

Let's define:

- end-effector position as vector $\bar{e}$

- goal position as vector $\bar{g}$

- joint angles as vector $\bar{\theta}$

Then FK gives us:

\begin{aligned} \bar{e} = f(\bar{\theta})\qquad (2) \end{aligned}

In other words we give joint angles on input and get end-effector position on output.

Let's do it from the opposite site and get joint angles on output and end-effector position on input. In order to do this simply move f() to the other site by inverting it:

\begin{aligned} \bar{\theta} = f^{-1}(\bar{e}) \qquad (3) \end{aligned}

Usually function $f()$ representing position of end-effector is non-linear and can not be inverted (not due to non-linearity). But what can be done is this. We can compute Jacobian matrix of the $f()$ (that is of the system) and afterward we can invert the matrix. This gives us something very close to $f^{-1}(\bar{e})$.

Jacobian (1) can be also written like this (I leave out 'bars' because we already know $e$ and $\theta$ are vectors):

\begin{aligned} J = \frac{de}{d{\theta}}\qquad (4) \end{aligned}

After small mathematical manipulation we get:

\begin{aligned} de = J*d{\theta}\qquad (5) \end{aligned}

which is related (at least look similar to :)) to the (2).

Since point (5) is all about matrix and vector manipulation we can also move J to the other side by inverting it:

\begin{aligned} d{\theta} = J^{-1}*de\qquad (6) \end{aligned}

and that is actually end of this math road because now we have derivated form of (3).

Pseudocode

Below you can see a pseudocode of the IK which basically has 4 repeating steps.

while (distance(e, g) > threshold){  // e - end-effector position, g - goal position

(1) compute the Jacobian matrix $J$

(2) compute the inverse of the $J$: $J^{-1}$

(3) compute change in joint angles $\theta$: $\Delta{\theta}$ = $J^{-1}$ * $\Delta e$ // $\Delta e$ is distance between end-effector and the goal position

(4) apply = move by a small step $\alpha\Delta{\theta}$: $\theta$ = $\theta$ + $\alpha$ * $\Delta{\theta}$

}

(1) compute the Jacobian matrix J

As written above, it is sometimes possible to compute Jacobian matrix analytically (it is difficult though) but numerical computation servers good as well. As far as I know numerically can be computed always. Big advantage of numerical way is its robustness. During computation you look at $f()$ as on a black box. For example when you implement $f()$ that returns position of an end-effector (taking joint angles on input) you can use coordinate systems that use matrix manipulation or simply add angles, compute sin/cos of it and multiply it by arm length. Both implementations basically return the same - a vector of end-effector position and that is the reason why one can numerically compute the Jacobian from both of them without any change in code.

There are a lot of resources out there on this topic:

However the main idea is as follows.

Let's rewrite definition of Jacobian matrix (1) with therms $\theta$ and $e$ - recall they are vectors.

\begin{aligned} J & = \begin{bmatrix} \frac{\partial ex}{\partial \theta 1} & \frac{\partial ex}{\partial \theta 2} \\ \frac{\partial ey}{\partial \theta 1} & \frac{\partial ey}{\partial \theta 2} \end{bmatrix} \qquad (7) \end{aligned}

Use $f(\theta)$ and compute $e$,

Now add small $\Delta \theta$ to every $\theta i$ and compute $\hat{e}i$ (here subscript 'i' means separately = if I had arm with 2 joints I would use as input $(\theta1+\Delta\theta,\theta2)$ and afterwards $(\theta1,\theta2+\Delta\theta)$).

We get:

\begin{aligned} \Delta e = \hat{e} - e \qquad (8) \end{aligned}

which basically tells us how the end-effector moves when an joint angle slightly changes.

Note: I left out subscripts 'i' here because we need to move in our thinking from single elements to vectors and matrices.

Since this approximation is valid:

\begin{aligned} \frac{\partial e}{\partial \theta} \approx  \frac{\Delta e}{\Delta\theta} \qquad (9) \end{aligned}

we can now fill in the Jacobian matrix by numerical way.

My Java code of numerical computation of Jacobian matrix:

Matrix computeJacobian(Matrix mTheta){
Matrix mTheta_;
Matrix mOut1  = computeArmPosition(mTheta);
Matrix mOut2  = mOut1.copy();
Matrix mJ     = new Matrix(2, 3);
float fValue  = 0.0;
float d       = 0.01;

for (int i = 0; i < 2; i++){
for (int j = 0; j < 3; j++){
mTheta_ = mTheta.copy();      //create copy of mTheta
mTheta_.set(0, j, mTheta_.get(0, j) + d);
mOut2 = computeArmPosition( mTheta_ );
fValue = ( (float)mOut2.get(i, 0) - (float)mOut1.get(i, 0) )/ d;
mJ.set(i, j, fValue);
}
}
return mJ;
}


(2) compute the inverse of the J: $J^{-1}$

How to inverse Jacobian?

1. Use pseudoinverse $J^+$. It is nearly impossible to inverse matrix in a standard way:

- often not a square matrix,
- changes over time hence its properties change as well.

\begin{aligned} J^+ = (J^T J)^{-1}J^T \qquad (10) \end{aligned}

2. Simply transpose the Jacobian matrix.

(3) compute change in joints $\Delta{\theta}$

In my java code I have:

//Compute delta(theta)
mDeltaTheta = mJacobian.times(mDeltaE);


where variable mJacobian contains inverted (pseudoinverted or transposed) Jacobian matrix.

Look at the $\Delta{\theta}$ as on a direction to the goal given by a map (inverted Jacobian) and your distance to the goal (error).

(4) apply = move by a small step $\alpha\Delta{\theta}$

To get to the goal the algorithm must run in a loop and repeat steps of computing a Jacobian and then taking a small step towards the goal until the end-effector is not close enough.

In my java code I have:

//Add delta(theta) to theta
mDeltaTheta = mDeltaTheta.times(fAlpha);
mTheta.plusEquals(mDeltaTheta.transpose());


Note: bigger value of Alpha means faster convergence = the arm reaches the goal faster, but also may cause oscillations (arm jitters).

Sample applet - IK with pseudoinverse of Jacobian

- place the goal (circle) by doubleclick

Sample applet - IK with transpose of Jacobian

- place the goal (circle) by doubleclick

Notes from developing the applets above

- since applets differ in the way the Jacobian is being inversed (transpose vs. pseudoinverse) both applets have to use different value of alpha.
- smaller number of alpha means slower convergence (it takes longer to reach the goal)
- in applet 1 where pseudoinverse is in use I mentioned that goal out of the arm's reach causes that the arm jitters.

Reference

http://www.cs.cmu.edu/~./15464-s13/lectures/lecture6/IK.pdf

http://mathworld.wolfram.com/Jacobian.html

0 #34 ayenaxeprew 2019-04-04 17:34
http://theprettyguineapig.com/amoxicillin/ - Amoxicillin 500mg Capsules For Sale 18 mug.icuq.concordia.sk.gfb.rk http://theprettyguineapig.com/amoxicillin/

0 #33 oturomi 2019-04-04 16:37
http://theprettyguineapig.com/amoxicillin/ - Buy Amoxicillin Amoxicillin 500mg Capsules cjw.kqne.concordia.sk.ndv.nx http://theprettyguineapig.com/amoxicillin/

0 #32 onowagixh 2019-03-24 16:55
http://theprettyguineapig.com/amoxicillin/ - Amoxicillin 500 Mg Amoxicillin http://theprettyguineapig.com/amoxicillin/

0 #31 ouqicorofof 2019-03-24 16:16
http://theprettyguineapig.com/amoxicillin/ - Amoxicillin Online Buy Amoxicillin http://theprettyguineapig.com/amoxicillin/

0 #30 smartphone pliable 2019-03-24 15:03
Selon les nouvelles rumeurs, le fabriquant smartphone Huawei pourrait sortir son portable pliable avant samsung et apple longuement désirables, les téléphones portable pliables
sont maintenant une réalité mais quel modèle
de portable flexible sélectionner ? Guide d'Achat 2019 des meilleurs smartphones
avec Écran mou. après plusieurs mois de folles rumeurs, Samsung a
dévoilé son mobile élastique Galaxy Fold. longuement attendus,
les smartphones pliables sont maintenant une réalité.
https://zik-miki.fr/smartphone-pliable/

0 #29 Smart parking 2019-03-07 01:11
Trouvez et réservez votre place de parking au meilleur prix avec Allopark.com, Location de stationnement de
particulier ou d'entreprise non loin des aéroports en france et sur le continent européen. Réserver une place de
stationnement en ligne c'est simple, rapide et vous offre la possibilité d'économiser de l'argent.

0 #28 Bertie 2019-03-01 09:10
Definitely consider that that you said. Your favorite justification appeared to be on the internet the easiest thing to take into accout of.
I say to you, I definitely get annoyed even as people think about concerns that
they just do not realize about. You managed
to hit the nail upon the top and defined out the entire thing with no need side-effects , other folks can take a signal.

Will likely be again to get more. Thanks

0 #27 Seo forums 2019-02-24 06:51
GHS Tools, c'est une équipe de PRO SEO et Black Hat SEO qui partagent leurs opinions et échangent des bons plans pour gagner du temps au
quotidien. Vous voulez apprendre à faire du SEO ? Venez sur le forum : https://www.ghstools.fr/forum/

0 #26 SEO 2019-02-23 05:30
Conseiller seo, spécialiste en seo google et programmeur web
de savoir-faire, nicolaseo optimise vos sites web et prend en charge le seo en mode seo black ou white en fonction de votre
prévision de financement. Visitez le site web de ce conseiller
search engine optimization : https://www.nicolas-sotton.ch/consultant-seo/

0 #25 Forum seo Français 2019-02-06 13:37
Pour tout savoir de la publicité Google vous pouvez venir avec nous sur l'un des
meilleurs forums search engine optimisation https://www.ghstools.fr/forum/ optimisation pour les moteurs de recherche, hébergement web, rédaction, analyse technique apprennez à
tout faire avec des trucs et astuces et des applications pour programmeurs.