## How to get float table values from Lua script to Python

Typically: "How do I... ", "How can I... " questions
Posts: 9
Joined: 05 Apr 2021, 16:26

### How to get float table values from Lua script to Python

I have used a Yolo model to detect a point and called a Lua script to get the world coordinates for that point.
This is my Python code to call the script to detect the door ,

Code: Select all

res,retInts,coords,retStrings,retBuffer= vrep.simxCallScriptFunction(clientID,'Dummy',vrep.sim_scripttype_childscript,'get_door_coord',[],center_coord,[],emptyBuff,vrep.simx_opmode_blocking)
This is the function in Lua Script, (I had modified the script from Blob to 3D sensor):

Code: Select all

function get_door_coord(inInts,inFloats,inStrings,inBuffer)
sensor = sim.getObjectHandle('v0')
local res
res,nearClip=sim.getObjectFloatParameter(sensor,sim.visionfloatparam_near_clipping)
res,farClip=sim.getObjectFloatParameter(sensor,sim.visionfloatparam_far_clipping)
res,xAngle=sim.getObjectFloatParameter(sensor,sim.visionfloatparam_perspective_angle)
res,resX=sim.getObjectInt32Parameter(sensor,sim.visionintparam_resolution_x)
res,resY=sim.getObjectInt32Parameter(sensor,sim.visionintparam_resolution_y)
yAngle=xAngle
local ratio=resX/resY
if resX>resY then
yAngle=2*math.atan(math.tan(xAngle/2)/ratio)
else
xAngle=2*math.atan(math.tan(yAngle/2)/ratio)
end

local m=sim.getObjectMatrix(sensor,-1)
local x_pos = inFloats[1]
local y_pos = inFloats[2]
local depthV = sim.getVisionSensorDepthBuffer(sensor,1+math.floor(x_pos*(resX-0.99)),1+math.floor(y_pos*(resY-0.99)),1,1)
local depth = nearClip + (farClip - nearClip) * depthV[1]
local coord = {0,0,depth}
coord[1] = depth*math.tan(xAngle*0.5)*(0.5-x_pos)/0.5
coord[2] = depth*math.tan(yAngle*0.5)*(y_pos-0.5)/0.5
coord = sim.multiplyVector(m,coord)
print(coord)

return {},{coord},{},''
end
For the above code I had printed the coordinates value to check if they are computed and I do get a value but when I return it to the Python script I do not get any values i,.e, all the return values are blank except the 'ret' which has the return status. The return value is 8 for 'ret'. If this is a error value, then I would like to know how to rectify it.

I need to know if there is any error in calling or returning of the function and how to get the values of the coordinates to the Python script.

Posts: 9
Joined: 05 Apr 2021, 16:26

### Re: How to get float table values from Lua script to Python

I have just seen the return codes and it shows that the return code 8 is because of an error on server side.
I cannot understand what the error is because when printing the value in the Lua script the values are printed whereas when the values are returned it is not returning.
Is there anyway to troubleshoot where the error is occurring or is there any solution for it?

coppelia
Posts: 8531
Joined: 14 Dec 2012, 00:25

### Re: How to get float table values from Lua script to Python

Hello,

return {},{coord},{},''
return {},coord,{},''