<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>

<META content="MSHTML 6.00.2900.5803" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff>
<DIV><SPAN class=625344518-17072009><FONT face=Arial color=#0000ff size=2>Hi 
Florian,</FONT></SPAN></DIV>
<DIV><SPAN class=625344518-17072009><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=625344518-17072009><FONT face=Arial color=#0000ff 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 face=Arial color=#0000ff 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 face=Arial color=#0000ff 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 face=Arial color=#0000ff 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><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=625344518-17072009><FONT face=Arial color=#0000ff 
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><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=625344518-17072009><FONT face=Arial color=#0000ff 
size=2>Regards,</FONT></SPAN></DIV>
<DIV><SPAN class=625344518-17072009><FONT face=Arial color=#0000ff 
size=2>Benoit</FONT></SPAN></DIV>
<DIV><SPAN class=625344518-17072009><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV></DIV>
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT 
  face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> 
  robotics-bounces@blender.org [mailto:robotics-bounces@blender.org] <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 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></BODY></HTML>