<!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=140443209-22072009><FONT face=Arial size=2>Very
nice!</FONT></SPAN></DIV>
<DIV><SPAN class=140443209-22072009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=140443209-22072009><FONT face=Arial size=2>About the Matrix API
mult problem, I got confirmation that this problem exists and the normal way to
work around that is to use something like:</FONT></SPAN></DIV>
<DIV><SPAN class=140443209-22072009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=140443209-22072009><FONT face=Arial size=2>BA =
bones['shoulder'].matrix['ARMATURESPACE'].rotationPart().transposed()</FONT></SPAN></DIV>
<DIV><SPAN class=140443209-22072009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=140443209-22072009><FONT face=Arial size=2>which allows to use
standard multiplication function. Note that in that case, the function to
extract the angle must be changed as the matrix becomes row
major.</FONT></SPAN></DIV>
<DIV><SPAN class=140443209-22072009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=140443209-22072009><FONT face=Arial size=2>You may be
interested to know that I'm working on a project with the KUL to implement a new
IK algorithm and support external IK target in the Game Engine. The new IK
algorithm is stateful, which means that the joint angles are available directly
in the IK state variables (there is no Python API yet to get them).
Being able to track external targets in the GameEngine is an important step for
the robotic applications, it opens the door for simulation and real time control
of robot. More information here: <A
href="http://wiki.blender.org/index.php/Dev:Source/GameEngine/RobotIKSolver">http://wiki.blender.org/index.php/Dev:Source/GameEngine/RobotIKSolver</A></FONT></SPAN></DIV>
<DIV><SPAN class=140443209-22072009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=140443209-22072009><FONT face=Arial
size=2>/Benoit</FONT></SPAN></DIV>
<BLOCKQUOTE
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> mercredi 22 juillet 2009
10:35<BR><B>To:</B> Blender and Robotics<BR><B>Subject:</B> Re: [Robotics]
Computing IK Joint Angles Pt. [SOLVED]<BR><BR></FONT></DIV>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 content="MSHTML 6.00.2900.5803" name=GENERATOR>
<DIV><SPAN class=625344518-17072009><FONT face=Arial color=#0000ff size=2>Hi
Florian,</FONT></SPAN></DIV>
<DIV><SPAN class=625344518-17072009></SPAN> </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></SPAN> </DIV>
<DIV><SPAN class=625344518-17072009><FONT face=Arial color=#0000ff
size=2>Attached you will find the 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 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> </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></SPAN> </DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(0,0,255) 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><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 -> 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" moz-do-not-send="true">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 width="90%" SIZE=4>
_______________________________________________
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></BLOCKQUOTE></BODY></HTML>