Page 1 of 1

Get Object Velocity in ZYX

Posted: 10 Feb 2022, 01:38
by amirmmi
Hello,
I want to get the derivatives of Euler angles of a dummy in ZYX format. How can I do this by using sim.getObjectVelocity?
I have to add that I used the following code to get Euler angles in XYZ order and verify its results by comparing it with the sim.getObjectVelocity function and then using it for ZYX, but the results were not even close.

Code: Select all

function sysCall_init()
	-- in frame t:
	t1 = sim.getSimulationTime()
	m1=sim.getObjectMatrix(objHandle,-1)
	
function sysCall_sensing()
	-- in frame t+dt:
	t2 = sim.getSimulationTime()
	dt = t2 - t1
	t1 = t2

	linearVelocity, angularVelocity=sim.getObjectVelocity(objHandle)
	
	sim.invertMatrix(m1)
	m2=sim.getObjectMatrix(objHandle,-1)
	m=sim.multiplyMatrices(m1,m2) -- now m is the transf. matrix of obj at t, expressed relative to the transf. matrix of 			obj at t+dt
	euler=sim.getEulerAnglesFromMatrix(m)
	da={euler[1]/dt,euler[2]/dt,euler[3]/dt}
	m1 = m2
	
	print(angularVelocity)
	print(da)
	

Re: Get Object Velocity in ZYX

Posted: 10 Feb 2022, 09:01
by coppelia
Hello,

in your code, your are computing the derivative of the Euler angles relative to the previous object frame, which is correct. sim.getObjectVelocity has a bug, if you use sim.getObjectVelocity, then make sure to combine the object handle with the sim.handleflag_axis flag, which will return a vector expressed in the absolute ref. frame, that indicates the instantaneous rotation axis (the rotation angle is given via the vector's length), which is the usual way of representing a rotation velocity.

Additionally, have a look at sim.yawPitchRollToAlphaBetaGamma or sim.alphaBetaGammaToYawPitchRoll, and the demo scene scenes/eulerAngles.ttt

Cheers

Re: Get Object Velocity in ZYX

Posted: 11 Feb 2022, 10:03
by zhangm365
Dear amirmmi:

What is default format of the Euler angles of a dummy in CoppeliaSim? Is it Z-Y-X axis?

Best Wishes.

Re: Get Object Velocity in ZYX

Posted: 11 Feb 2022, 10:24
by coppelia
Have a look here about CoppeliaSim's Euler angles and conversion, and the demo scene scenes/eulerAngles.ttt.

Cheers