Robot transformation and matrix

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
franzengel
Posts: 29
Joined: Wed May 30, 2012 11:26 am

Robot transformation and matrix

Post by franzengel »

Hi,

I've a little question about the robot workbench. The following code:

Code: Select all

from Robot import *
from Part import *
from FreeCAD import *
w=Waypoint(Placement(Vector(2000,0,i*100+1000),Vector(0,0,1),90),"LIN","Pt")
print w
print w.Pos
print w.Pos.toMatrix()

leads to:

Code: Select all

Waypoint [LIN Pt (2000,0,1000;90,0,0)v=2000 ]
Placement [Pos=(2000,0,1000), Yaw-Pitch-Roll=(90,0,0)]
Matrix ((2.22045e-16,-1,0,2000),(1,2.22045e-16,0,0),(0,0,1,1000),(0,0,0,1))

That makes me crazy. I think that the rotation matrix of the homogenous matrix from Yaw-Pitch-Roll=90,0,0 shout looks like this:
0 -1 0
1 0 0
0 0 1

The results looks like a rotation of -90 for Yaw. Because of the right-hand rule.

regards,
Franz
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Robot transformation and matrix

Post by wmayer »

Something is strange. That's the Euler convention we're using: http://de.wikipedia.org/wiki/Eulerwinke ... eugtechnik
and if using the Euler angles (90,0,0) you'll get the matrix [[0,1,0],[-1,0,0],[0,0,1]]

And here is the formula to get the rotation matrix from the quaternion: http://de.wikipedia.org/wiki/Quaternion ... n_Matrizen or http://en.wikipedia.org/wiki/Conversion ... n_matrices
which gives the transposed matrix when using the values of the quaternion.

:?:
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Robot transformation and matrix

Post by NormandC »

Why was this posted to Features Announcements? That forum is to basically announce new features.

I moved this topic to Developers corner, but left the "ghost" topic.
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Robot transformation and matrix

Post by shoogen »

wmayer wrote:Something is strange.
I think at this point it's worth noticing that the textual representation of quaternions in FreeCAD is quite unusual. The real (w) part is last component. In most textbooks the indexing stars with the real (w) part.
EDIT:

Code: Select all

 * q[0] = x, q[1] = y, q[2] = z and q[3] = w,
* where the quaternion is specified by q=w+xi+yj+zk.
n the other hand in the sourcecode the components are called q0 to q3.

The using blender i get w = x = sqrt(2), y = z = 0. If i enter FreeCAD.Rotation(0.707,0,0,0.707) (x,y,z,w). I get yaw = 90°
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Robot transformation and matrix

Post by shoogen »

Now i am totally confused.

Code: Select all

>>> FreeCAD.Rotation(90,0,0).Axis #yaw (z)
Vector (0, 0, 1)
>>> FreeCAD.Rotation(0,90,0).Axis #picth(y)
Vector (0, 1, 0)
>>> FreeCAD.Rotation(0,0,90).Axis #roll (x)
Vector (1, 0, 0)
EDIT:
seems to be correct
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Robot transformation and matrix

Post by shoogen »

franzengel wrote:The results looks like a rotation of -90 for Yaw. Because of the right-hand rule.
FreeCAD Matrices are stored in http://en.wikipedia.org/wiki/Row-major_order
i can't see the implication of the right-hand rule in this case.
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Robot transformation and matrix

Post by wmayer »

shoogen wrote:
wmayer wrote:Something is strange.
I think at this point it's worth noticing that the textual representation of quaternions in FreeCAD is quite unusual. The real (w) part is last component. In most textbooks the indexing stars with the real (w) part.
EDIT:

Code: Select all

 * q[0] = x, q[1] = y, q[2] = z and q[3] = w,
* where the quaternion is specified by q=w+xi+yj+zk.
n the other hand in the sourcecode the components are called q0 to q3.

The using blender i get w = x = sqrt(2), y = z = 0. If i enter FreeCAD.Rotation(0.707,0,0,0.707) (x,y,z,w). I get yaw = 90°
We're following the same convention as OpenInventor does. In the document of SbRotation it says:

Code: Select all

  q[0] = x, q[1] = y, q[2] = z and q[3] = w, where the quaternion is
  specified by q=w+xi+yj+zk
However, I realized that their implementation of getValue(SbMatrix & matrix) looks totally different compared to ours.
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Robot transformation and matrix

Post by wmayer »

From the English wikipedia article http://en.wikipedia.org/wiki/Conversion ... n_matrices:
The orthogonal matrix (post-multiplying a column vector) corresponding to a clockwise/left-handed rotation by the unit quaternion is given by the inhomogeneous expression:
So, the given formula applies to column-order matrices. Or am I wrong? And in FreeCAD we have implemented exactly this way but our matrices are row-ordered. So, if am right then we simply have to transpose the rotational part of our implementation inside Rotation::getValue(Matrix4D & matrix).

On the other hand this method is often used to get the matrix from a quaternion and I have nowhere seen any problems before.

Opinions?
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Robot transformation and matrix

Post by wmayer »

shoogen wrote: I think the math in FreeCAD is right. And the your example from yesterday leaves out the fact the formula is for clockwise angles. Because of the definition what of global and local reference system.
wmayer wrote: Something is strange. That's the Euler convention we're using: http://de.wikipedia.org/wiki/Eulerwinke ... eugtechnik
and if using the Euler angles (90,0,0) you'll get the matrix [[0,1,0],[-1,0,0],[0,0,1]

I think that in the original complaint the fact that the matrix is row major has been overlooked.

So before changing anything could anyone please provide some test cases. (or textbook examples)

EDIT: (I got my copy of the Dubbel (a german textbook))
Azimut, Inclination and Bank Angle are defined clockwise.

Therefore the usage in FreeCAD does not reflect DIN 9300. But i don't think that we should change that.
In the german wikipedia article there are to pictures one showing clockwise angles the second one showing counter clockwise angles.

No, I won't change anything because I have tested the use of Rotation::getValue() in a case working with arbitrary combined rotations and this works very well. So, changing anything there will cause a lot of problems on other sides. But besides that it is amazing how many different conventions exist (especially for the Euler angles) that heavily deviates from pure school math. And this makes it really difficult to pick up the right formula to convert between different representations.

Btw, just found another resource in German using exactly the same formulas that we have and it seems to comply with school math [1]

[1] http://www.uninformativ.de/bin/SpaceSim-2401fee.pdf

EDIT: Before posting this message I saw a posting from you shoogen. Did you delete it or did I do it by accident :oops: In any case I have found and saved it from my browser cache.
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Robot transformation and matrix

Post by shoogen »

I deleted it because i discovered to many mistakes in it.
The pictures in the wikipedia show CCW angles. But the formulars are for clockwise rotations. I think the people took the right forumals from the textbook but didn't give the explanations required.
Thererefore i wanted to rework my post once i found those explanations.
I'm even more confused by the pdf you referenced. I think that the rotation in formula (2.15) is negative. The same for (2.17 - 2.19)
Post Reply