Get Object Velocity in ZYX

Typically: "How do I... ", "How can I... " questions
Post Reply
amirmmi
Posts: 23
Joined: 08 Jan 2022, 23:38

Get Object Velocity in ZYX

Post 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)
	

coppelia
Site Admin
Posts: 10504
Joined: 14 Dec 2012, 00:25

Re: Get Object Velocity in ZYX

Post 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

zhangm365
Posts: 46
Joined: 19 Jun 2021, 12:58

Re: Get Object Velocity in ZYX

Post 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.

coppelia
Site Admin
Posts: 10504
Joined: 14 Dec 2012, 00:25

Re: Get Object Velocity in ZYX

Post by coppelia »

Have a look here about CoppeliaSim's Euler angles and conversion, and the demo scene scenes/eulerAngles.ttt.

Cheers

Post Reply