<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hey all - especially Benoit,<br>
<br>
wow, I would never have aspersed the python API to mess up the matrix
mult. ...<br>
<br>
I really appreciate your help, without your engagement I would have
calculated matrices for the next few weeks.<br>
I needed to alter the code somewhat, because the DoF are little
different from my "sample amature" so I added <br>
an additional axis to the "def EulerAngleFromMatrix(R, axis)" function.<br>
<br>
Everything seems to be fine so far, so I created a video which shows
how Blender can controll a real Robot (Software).<br>
THANKS again - big time!<br>
<br>
Here's the video: <a class="moz-txt-link-freetext" href="http://www.vimeo.com/5699910">http://www.vimeo.com/5699910</a><br>
<br>
Cheers, Florian<br>
<br>
<br>
<br>
Benoit Bolsee wrote:
<blockquote cite="mid:6205B68722484415BE543B99DA1FE01B@Benoit95"
 type="cite">
  <meta http-equiv="Content-Type" content="text/html; ">
  <title>Message</title>
  <meta content="MSHTML 6.00.2900.5803" name="GENERATOR">
  <div><span class="625344518-17072009"><font color="#0000ff"
 face="Arial" size="2">Hi Florian,</font></span></div>
  <div><span class="625344518-17072009"></span>&nbsp;</div>
  <div><span class="625344518-17072009"><font color="#0000ff"
 face="Arial" size="2">I had a look on your file and modified it to get
it working. While doing that, I noticed several important points:</font></span></div>
  <div><span class="625344518-17072009"><font color="#0000ff"
 face="Arial" size="2">- better use dictionary access by bone name
instead of index number, it is more portable</font></span></div>
  <div><span class="625344518-17072009"><font color="#0000ff"
 face="Arial" size="2">- you cannot avoid using the bone rest pose
because Blender introduces 180 roll all the time, which ruins the angle
calculation based only on the pose matrix</font></span></div>
  <div><span class="625344518-17072009"><font color="#0000ff"
 face="Arial" size="2">- I discovered a major flaw in the MathUtil
library: it treats the matrix as row major for matrix operations like
multiplication but Blender returns column major matrices. I wonder how
nobody noticed that. I had implement my own matrix multiplication
function to work around that. Maybe it is my ignorance of the Blender
Python API.</font></span></div>
  <div><span class="625344518-17072009"></span>&nbsp;</div>
  <div><span class="625344518-17072009"><font color="#0000ff"
 face="Arial" size="2">Attached you will find the&nbsp;script that gives
exact joint angles. The logic is quite simple and systematic: the joint
angle is computed from the difference between 1) the pose of a bone
when combining the&nbsp;pose of its parent and its own rest pose 2) its
actual pose. The difference is only due to the angle and as you only
use 1DoF joints, it is quite simple to extract the angle.</font></span></div>
  <div><span class="625344518-17072009"></span>&nbsp;</div>
  <div><span class="625344518-17072009"><font color="#0000ff"
 face="Arial" size="2">Regards,</font></span></div>
  <div><span class="625344518-17072009"><font color="#0000ff"
 face="Arial" size="2">Benoit</font></span></div>
  <div><span class="625344518-17072009"></span>&nbsp;</div>
  <blockquote dir="ltr"
 style="border-left: 2px solid rgb(0, 0, 255); padding-left: 5px; margin-left: 5px; margin-right: 0px;">
    <div class="OutlookMessageHeader" dir="ltr" align="left"
 lang="en-us"><font face="Tahoma" size="2">-----Original Message-----<br>
    <b>From:</b> <a class="moz-txt-link-abbreviated" href="mailto:robotics-bounces@blender.org">robotics-bounces@blender.org</a>
[<a class="moz-txt-link-freetext" href="mailto:robotics-bounces@blender.org">mailto:robotics-bounces@blender.org</a>] <b>On Behalf Of </b>Florian Lier<br>
    <b>Sent:</b> jeudi 16 juillet 2009 20:51<br>
    <b>To:</b> Blender and Robotics; Blender Foundation Python list<br>
    <b>Subject:</b> [Robotics] Computing IK Joint Angles Pt.3<br>
    <br>
    </font></div>
    <div class="moz-text-html" lang="x-western"><font
 face="Helvetica, Arial, sans-serif" size="-1">Hey all and especially
Benoit,<br>
    <br>
i've implemented Benoits approach for computing joint angles (in
degrees)<br>
    <br>
To recapitulate the problem:<br>
    <br>
I've modelled a robot arm with 5 joints (all joints are revolute
joints). The arm is<br>
driven by an "empty" target to an IK solver on top of the bone chain. I
need to<br>
get the joint angles in degrees or rad. Those joint angles are in range
of the X,Y,Z<br>
limits of the bones which form the chain.<br>
    <br>
The approach: <br>
    </font>
    <pre wrap=""><b><font face="Helvetica, Arial, sans-serif">relativePose[n] =<span
 class="moz-txt-citetags"> </span>inverse(poseMatrixTail[n-1])*poseMatrix[n]
<span class="moz-txt-citetags">
"</span>where n is the bone for which you compute the joint values and
<span class="moz-txt-citetags"></span>poseMatrixTail is simply poseMatrix where the 4th column is replaced by
<span class="moz-txt-citetags"></span>tail.<span
 class="moz-txt-citetags"> </span>For the root bone, poseMatrixTail is the identity matrix."

</font></b><font face="Helvetica, Arial, sans-serif">As far as I've tested the setup all angles are computed correctly. The only problem is, that
I need to convert the angles from poseMatrix -&gt; toEuler(). That's the last pitfall. Euler angles
are a bit tricky because the represent [yaw, pitch, bank]. By rotating some (or one) of the
parent bone/s the YAW, PITCH, BANK locally changes for the "target bone" [n] (for which I want to
compute the joint angle) so the resulting angle is either positive or negative - what's not THAT bad. 
The biggest problem is - an euler angle is represented like [x (yaw),z (pitch),y (bank)]. 
Let's assume a bone rotates about the x axis (its' DoF). If all bones are in rest position the output when 
rotation the bone is like: [100, x, x] after rotation one of it's parents the result is maybe: [x,x,100]. 
To me there's so predictable coherence whether the result can be found in x y or z.

<b>How can someone solve this problem?</b>

I've digged deep in the blender source code especially in armature.c and the IK_Solver sources.
The angle I need is represented as a float value in there :/.  

[blender source from svn]

blender/intern/iksolver/intern/IK_QSegment.cpp [line 602]

BUT wrapping this code to Python, making the code invokable and finally extending the Python API 
seems a little to exaggerated to me ... 

So having the feature to extract several angles from an IK chain would be great in case of using blender
for robotics.

It would be great if someone can help me out - or if we can solve this problem in a more general manner
like really extending the python API ? I'll attach the appropriate blend file so everybody can play around
or visualize the problem. Most of the code is documented.

You can find the blend file here: <b><a moz-do-not-send="true"
 class="moz-txt-link-freetext"
 href="http://www.icram.de/BpyJointAngles.blend">http://www.icram.de/BpyJointAngles.blend</a></b>

Cheers, Florian


P.S. Sorry for crossposting this, but this is / maybe / not only a robotics issue...

</font></pre>
    <br>
    </div>
  </blockquote>
  <pre wrap=""><pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Robotics mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Robotics@blender.org">Robotics@blender.org</a>
<a class="moz-txt-link-freetext" href="http://lists.blender.org/mailman/listinfo/robotics">http://lists.blender.org/mailman/listinfo/robotics</a>
</pre></pre>
</blockquote>
<br>
</body>
</html>