Page 1 of 1

How to get deviation for self balancing robot.

Posted: 25 Nov 2021, 09:36
by shreyas7738
I am using sim.getObjectOrientation to get the orientation for self balancing robot.I need to get the robots deviation from its own Z axis.Initially I tried using world frame as reference and it works fine for initial position as I get orientation at index 3 as -1.57. But when I rotate the bot to,the orientation changes to 1.57.Is there anything I could do to get the same deviation irrespective of its orientation wrt the world frame.

Re: How to get deviation for self balancing robot.

Posted: 25 Nov 2021, 16:00
by coppelia
Hello,

working with orientation can be tricky or difficult to wrap your head around. There are at least 3 ways you can understand an orientation:
  • using quaternions: this is rather difficult to understand, but very convenient for calculations. e.g. sim.getObjectQuaternion
  • using Euler angles: this is easier to understand, but not very convenient for calculations. e.g. sim.getObjectOrientation
  • using a rotation matrix: this is probably the easiest to visualize. In CoppeliaSim you can get the transformation matrix for a reference frame: sim.getObjectMatrix
Using the third approach from above, you can easily understand the orientation when you know that your matrix contains the x, y and z unit vectors of your reference frame:

Code: Select all

    local m=sim.getObjectMatrix(objectHandle,-1)
    local unitXAxis={m[1],m[5],m[9]} 
    local unitYAxis={m[2],m[6],m[10]} 
    local unitZAxis={m[3],m[7],m[11]} 
Now you can check the alignment of one of above axes, and compare it with the world reference axes. There you can easily extract various angles.

Cheers