Issue with Setting Object Quaternion

Typically: "How do I... ", "How can I... " questions
Post Reply
CroCr
Posts: 90
Joined: 29 Dec 2022, 01:47

Issue with Setting Object Quaternion

Post by CroCr »

I'm having trouble setting the quaternion for an object. I need to control the orientation of a sphere within the body frame {E} (i.e. dummy frame attached to the sphere). So let rWE represent the orientation of {E} with respect to {W}. Now let's say I need to rotate the object about its x-axis, then rdx = cos(angle/2) + sin(angle/2)*i. According to the book "Modern Robotics: Mechanics, Planning, and Control", I need to postmultiply the current orientation of the sphere by the desired orientation as rd = rWE*rdx. The problem I'm encountering is that the sphere's orientation is continuously rotating. I'm setting rWE for each iteration. When I profile the desired (17 deg) and current angle, I get this

Code: Select all

17 , 90
17 , 91.2519
17 , 94.9037
17 , 100.681
17 , 108.222
17 , 117.156
17 , 127.154
17 , 137.937
17 , 149.28
17 , 160.997
17 , 187.067
17 , 175.052
17 , 163.092
17 , 151.325
17 , 139.903
17 , 129.007
17 , 118.852
17 , 109.707
17 , 101.894
17 , 95.7785
17 , 91.7279
17 , 90.0393
17 , 90.851
17 , 94.0953
17 , 99.5225
17 , 106.78
17 , 115.494
17 , 125.325
17 , 135.987

To get and set quaternion, I use sim.getObjectQuaternion(DummyFrameHandle,-1), sim.setObjectQuaternion(SphereHandle,-1,{x,y,z,w}). I understand you might question why I’m multiplying at each iteration. The reason is that the sphere keeps moving, and I need to perform the orientation relative to the body frame.

CoppeliaSim Edu, Version 4.5.1 (rev. 4). Ubuntu 18.04 OS


See this working example,
https://www.dropbox.com/scl/fi/j8isg1ql ... 0oeoy&dl=0

Please help.
coppelia
Site Admin
Posts: 10742
Joined: 14 Dec 2012, 00:25

Re: Issue with Setting Object Quaternion

Post by coppelia »

Hello,

not sure I understand exactly what you are trying to achieve, but below are the CoppeliaSim equivalent routines:

Code: Select all

function quaternionFromEuler(roll, pitch, yaw)
    local m = sim.buildMatrix({0, 0, 0}, {roll, pitch, yaw})
    local p = sim.matrixToPose(m)
    return {p[4], p[5], p[6], p[7]}
end

function multiplyQuaternions(q1, q2)
    local p1 = {0, 0, 0, q1[1], q1[2], q1[3], q1[4]}
    local p2 = {0, 0, 0, q2[1], q2[2], q2[3], q2[4]}
    local p3 = sim.multiplyPoses(p1, p2)
    return {p3[4], p3[5], p3[6], p3[7]}
end
Cheers
CroCr
Posts: 90
Joined: 29 Dec 2022, 01:47

Re: Issue with Setting Object Quaternion

Post by CroCr »

coppelia wrote: 11 Dec 2024, 07:01 Hello,

not sure I understand exactly what you are trying to achieve, but below are the CoppeliaSim equivalent routines:

Code: Select all

function quaternionFromEuler(roll, pitch, yaw)
    local m = sim.buildMatrix({0, 0, 0}, {roll, pitch, yaw})
    local p = sim.matrixToPose(m)
    return {p[4], p[5], p[6], p[7]}
end

function multiplyQuaternions(q1, q2)
    local p1 = {0, 0, 0, q1[1], q1[2], q1[3], q1[4]}
    local p2 = {0, 0, 0, q2[1], q2[2], q2[3], q2[4]}
    local p3 = sim.multiplyPoses(p1, p2)
    return {p3[4], p3[5], p3[6], p3[7]}
end
Cheers

Thank you for your response. I'm trying to control the orientation of a sphere using a joystick that provides three angles. I don't have an issue with translation. As the user sees the scene through the camera, I need the user to move and rotate as they see the scene, similar to video gaming (e.g., a first-person shooter (FPS)). Specifically, a Geomatic Touch device is used, providing three angles about the local frame.
coppelia
Site Admin
Posts: 10742
Joined: 14 Dec 2012, 00:25

Re: Issue with Setting Object Quaternion

Post by coppelia »

Then you are probably better off using Euler angles

Cheers
CroCr
Posts: 90
Joined: 29 Dec 2022, 01:47

Re: Issue with Setting Object Quaternion

Post by CroCr »

coppelia wrote: 12 Dec 2024, 08:16 Then you are probably better off using Euler angles

Cheers
I discovered the problem, but I was unable to solve it. The problem is that I need to rotate with respect to the body frame, so I need to retrieve its current orientation with respect to the world. With pressing the keyboard, there is no issue as this occurs relatively much slower than getting data from the joystick, which gets data at 20Hz. This is the logic I'm looking for
  • determine the desired axis and angle of rotation, rEd = cos(angle/2) + sin(angle/2)*i
  • get the current orientation of the body frame with respect to world rWE.
  • compute the desired orientation rd = rWE*rEd
  • set body orientation with respect to the world.
The issue arises in the third bullet point. The object keeps spinning if this line is executed without changing the angle. In other words, how can I perform the orientation with respect to the body frame? Similar to the functionality included with CoppeliaSim, rotating about its own frame using angles passed from the C++ application.
coppelia
Site Admin
Posts: 10742
Joined: 14 Dec 2012, 00:25

Re: Issue with Setting Object Quaternion

Post by coppelia »

Try to have a look at the demo scene scenes/eulerAngles.ttt: you will see there are many different ways one can generate a rotation and how it is expressed relative to the world or the mobile body. Or maybe I can't exactly grasp what you are trying to achieve exactly ;)

Cheers
CroCr
Posts: 90
Joined: 29 Dec 2022, 01:47

Re: Issue with Setting Object Quaternion

Post by CroCr »

coppelia wrote: 13 Dec 2024, 17:16 Try to have a look at the demo scene scenes/eulerAngles.ttt: you will see there are many different ways one can generate a rotation and how it is expressed relative to the world or the mobile body. Or maybe I can't exactly grasp what you are trying to achieve exactly ;)

Cheers
Thank you for your informative and supportive assistance. I have resolved the problem. Please feel free to remove the post.
Post Reply