Getting Object Matrix from V-REP

Typically: "How do I... ", "How can I... " questions
Post Reply
robotico
Posts: 11
Joined: 08 Nov 2018, 15:02

Getting Object Matrix from V-REP

Post by robotico » 27 Nov 2018, 00:12

Hello,

I work on a quadricopter project. I use MATLAB on client side. The connection established via RemoteAPI that works on synchronized mode.

As known, we can get the object matrix with

Code: Select all

sim.getObjectMatrix(d)
function easily. To be able to use that matrix on MATLAB side, I use

Code: Select all

simxUnpackFloats()
or

Code: Select all

vrep.simxGetFloatSignal
functions. I tried to get complete matrix in one step or get matrix members individually.
The problem is that, the matrix I get from V-rep is belong to previous simulation step. So I cannot get the current matrix.
How can I get the instantaneous object matrix in MATLAB?

Note: All scene elements' frame are different. For example, in my project I use global frame, quadricopter frame, kinect frame and kinect RGB frame. Their axes are in different orientation. Why did not developer select to create each's frame in same orientation? Because, to be able to handle all orientations with a 6-DoF system is already hard.

Thanks.

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

Re: Getting Object Matrix from V-REP

Post by coppelia » 27 Nov 2018, 08:41

Hello,

you can't, unless you handle this directly inside of a child script. Typically, a simulation step is:
  • Action
  • Sensing
  • Display
  • t=t+dt
  • handle remote API communication
See also the second-last diagram at the bottom of this page.

Cheers

robotico
Posts: 11
Joined: 08 Nov 2018, 15:02

Re: Getting Object Matrix from V-REP

Post by robotico » 03 Dec 2018, 13:25

I think I solve it. In Lua side I created a function using sim.getObjectMatrix and returning Matrix values individually.

Lua side:

Code: Select all

robotMatrixCalc=function(inInts,inFloats,inStrings,inBuffer)
robotHandle=sim.getObjectHandle('Quadricopter_base')
robotMat=sim.getObjectMatrix(robotHandle,-1)
return {},{robotMat[1],robotMat[2],robotMat[3],robotMat[4],robotMat[5],robotMat[6],robotMat[7],robotMat[8],robotMat[9],robotMat[10],robotMat[11],robotMat[12]},{},'' -- return a string
end
And in the Matlab side, I get the instantaneous matrix with vrep.simxCallScriptFunction command through "retFloats" array.

Matlab side:

Code: Select all

[res, retInts, retFloats, retStrings, retBuffer]=vrep.simxCallScriptFunction(clientID,'GetMatrixFunction',vrep.sim_scripttype_childscript,'robotMatrixCalc',[],[],[],[],vrep.simx_opmode_blocking);
Do you confirm that solution?

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

Re: Getting Object Matrix from V-REP

Post by coppelia » 05 Dec 2018, 11:07

That looks correct.

Cheers

robotico
Posts: 11
Joined: 08 Nov 2018, 15:02

Re: Getting Object Matrix from V-REP

Post by robotico » 07 Dec 2018, 00:32

Thank you very much!

Post Reply