0

I am trying to figure out quaternions for orienting the end effector according to wcp of 6 dof robotic arm, Even though it can be solved using euler angles but it suffers from gimbal lock situations. I did try packages like pyquaternion. But somehow its getting difficult to build an intuition about them ,euler angles are a lot simple to deal with.

The way I am trying to solve it is by given input as rotation vector then computing rotation matrix and then finally quaternion

I have tried looking into different solutions like the one project done by thepoorengineer.com pyquaternion package and others

  • See and the [quaternion2hab](https://github.com/stla/PyVistaMiscellanous/blob/811b712bf82e8e57237b9be9f72788f6b6581cc0/stiletto_animation.py) function. – Stéphane Laurent Mar 20 '23 at 15:52

1 Answers1

0

Everything you need to know about Quaternions and are not afraid to ask [SO].

  1. A unit quaternion represents a single rotation about an arbitrary axis using 4 parameters, grouped as a vector and a scalar. The layout is usually either vector-scalar or scalar-vector. I prefer the vector-scalar form.

    As such a rotation about an axis z by an angle θ is

    eq1

    There is a requirement here that the magnitude is one |v|^2+s^2=1, otherwise the quaternion will not represent an elementary rotation.

  2. You can chain multiple rotations together using the quaternion product ⓧ and the order of operation matters such as with multiplying rotation matrices.

    eq2

  3. The inverse of a unit quaternion is simply found by negating the vector part

    eq3

  4. To transform a vector p using the quaternion q=(v,s) follow this rule

    eq4

  5. You can convert from/to a 3×3 rotation matrix at any point using the following expressions

    • To rotation matrix R

    eq5a

    where 1 represents the identity matrix, and [v×] represents the 3×3 cross product skew symmetric matrix and is defined as

           |  0 -v3  v2 |
    [v×] = | v3   0 -v1 |
           | -v2 v1   0 |
    

    Note that square the above matrix [v×][v×] also has a closed-form solution of a symmetric matrix that needs to be coded because it is used in rotations a lot

               | -v2^2-v3^2    -v1*v2    -v1*v3     |
    [v×][v×] = |   v1*v2    -v1^2-v3^2   -v2*v2     |
               |   v1*v3       -v2*v3   -v1^2-v3^2  |
    
    • From Rotation Matrix R

      eq5b

    • To/From Euler Angles, use the conversion to a rotation matrix, and then the Euler angle extraction from R. This is not very efficient, and the reason to use quaternions is to derive R instead of yaw/pitch/roll. Also, the whole gimbal lock thing as you mentioned.

  6. In a simulation environment you can integrate a quaternion q over time t in an ODE scheme by evaluating the quaternion derivative

    eq6

    This may seem that it would veer off from a unit quaternion rather rapidly, but it does not do so by much. Nevertheless, it is recommended after the integration steps to re-normalize the quaternion q by dividing each parameter by the magnitude √(|v|^2+s^2).

John Alexiou
  • 28,472
  • 11
  • 77
  • 133
  • I would note that your answers for 4 and 5 depend on the convention of the quaternion. The sign of the cross product terms will flip depending on whether the convention is active or passive. I would also note that the quaternion derivative shown in 6 depends on how omega is coordinatized. You can get the omega being on the right or left side, and can either get a + or - sign on the derivative depending on this and the quaternion convention. Bottom line is you need to be very careful and know what you are doing before blindly applying these formulas. – James Tursa Apr 01 '23 at 01:00
  • @JamesTursa - thank you. As long as you are consistent in your conventions you are ok. All the above formulas work together under the same conventions. I have successfully applied them to numerous sim projects and they work exactly as intended. – John Alexiou Apr 01 '23 at 02:14