## Remote API calling OMPL cannot get value returned, also got weird return state value

Typically: "How do I... ", "How can I... " questions
cxt
Posts: 5
Joined: 08 Sep 2020, 04:12

### Remote API calling OMPL cannot get value returned, also got weird return state value

Hi Coppelia,

I am working on a script trying to find motion plans using OMPL. I use python remote API to call functions in a non-threaded childscript in coppeliasim on the same machine, which is desired to return the planned path to python call. I used to make this happen (also able to save and load path to replay as shown in jaco demo but now failed and got error when loading the path saying wrong argument), but somehow now I can see the path is generated in coppeliasim but cannot be passed to python (verified this by printing path out).

Some thoughts and analysis: I got return state value as 3 which I checked might be no return value tag and timeout tag. The path length I got is 2100 which I think is not super long, and I indeed saw the function returns to python before the values are printed out in coppeliasim functions. Will the network be the issue? I guess on the same machine the speed should not be the problem, but is there a timer for remote call to return? Also I am using blocking mode and I guess it should be.

I attach my python caller function, coppeliasim motion planning function here for reference. Thanks advance for your help!

python:

Code: Select all

def plan(self, target_pose, pathfilename='latest_path', load_path=0, save_path=0):
emptyBuff = bytearray()

# not used
approach_vector = [0, 0, 0]  # often a linear approach is required. This should also be part of the calculations when selecting an appropriate state for a given pose
max_configs_desired_pose = 10  # we will try to find 10 different states corresponding to the goal pose and order them according to distance from initial state
max_trials_config_search = 300  # a parameter needed for finding appropriate goal states
search_count = 30  # how many times OMPL will run for a given task
min_configs_path_planning = 400  # interpolation states for the OMPL path
min_configs_ik_path = 100  # interpolation states for the linear approach path
collision_checking = 1  # whether collision checking is on or off

# Do the path planning here (between a start state and a goal pose, including a linear approach phase):
inInts = [self.robot_target_handle, collision_checking, min_configs_ik_path, min_configs_path_planning,

inFloats = target_pose.flatten().tolist() + approach_vector
# print('inInts', inInts)
# print('inFloats', inFloats)
res, retInts, path, retStrings, retBuffer = sim.simxCallScriptFunction(self.sim_client,
'remoteApiCommandServer',
sim.sim_scripttype_childscript,
'findPath_goalIsPose',
inInts, inFloats, [pathfilename],
self.empty_buff,
sim.simx_opmode_blocking) #sim.simx_opmode_oneshot_wait)
coppeliasim:

Code: Select all

findPath=function(task1, startConfig,goalConfigs,cnt)
-- Here we do path planning between the specified start and goal configurations. We run the search cnt times,
-- and return the shortest path, and its length
for i=2,#goalConfigs,1 do
end
local path=nil
local l=999999999999
for i=1,cnt,1 do
if res and _path then
if _l<l then
l=_l
path=_path
end
end
end
return path,l
end
-- This function will search for several paths between the specified start configuration,
-- and several of the specified goal configurations. The shortest path will be returned
return thePath
end
-- Here we search for several robot configurations...
-- 1. ..that matches the desired pose (matrix)
-- 2. ..that does not collide in that configuration
-- 3. ..that does not collide and that can perform the IK linear approach
local cs={}
local l={}
for i=1,trialCnt,1 do
if c then
local p=0
local same=false
for j=1,#l,1 do
if math.abs(l[j]-dist)<0.001 then
-- we might have the exact same config. Avoid that
same=true
if math.abs(cs[j][k]-c[k])>0.01 then
same=false
break
end
end
end
if same then
break
end
end
if not same then
cs[#cs+1]=c
l[#l+1]=dist
end
end
if #l>=maxConfigs then
break
end
end
if #cs==0 then
cs=nil
end
return cs
end
findPath_goalIsPose=function(inInts,inFloats,inStrings,inBuffer)
local currentState={-1,-1,-1,-1,-1,-1,-1}
local jh={-1,-1,-1,-1,-1,-1,-1}
for i=1,7,1 do
jh[i]=sim.getObjectHandle('LBR4p_joint'..i)
currentState[i]=sim.getObjectPosition(jh[i], -1)
end
metric={0.5,1,1,0.5,0.1,0.2,0.1}
local collisionChecking=inInts[2]>0
local save_path=inInts[9]

local goalPose={}
for i=1,12,1 do goalPose[i]=inFloats[i] end
print('target: ')
local approachVector={}
for i=1,3,1 do approachVector[i]=inFloats[i+12] end

local suff,robotName=sim.getNameSuffix(fullRobotName)

if not collisionChecking then
end

if goalConfigs == nil then
sim.addStatusbarMessage("Can't find any goal configurations given target pose")
return {0},{},{},''
end

sim.addStatusbarMessage('Number of found goal configs: '..tostring(#goalConfigs))
local path
else
print('calculate new path')
end

if path then
for k, v in pairs(path) do
if k < 10 then
print(k, v)
end
end
return {1},path,{},''
else
return {0},{},{},''
end
end

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

### Re: Remote API calling OMPL cannot get value returned, also got weird return state value

Hello,

how do you set-up the remote API client? What are the arguments to simxStart? Try out using a larger negative number for the timeOutInMs argument.

Additionally, for such longer operations, it would be best to send a non-blocking request to CoppeliaSim, have CoppeliaSim handle the request, and inform the client when data is available. Then the client can retrieve the data.

Cheers

cxt
Posts: 5
Joined: 08 Sep 2020, 04:12

### Re: Remote API calling OMPL cannot get value returned, also got weird return state value

Hi,

Thanks for your reply! I use "self.sim_client = sim.simxStart('127.0.0.1', 19997, True, True, 5000, 5)" in python client. I found the API: def simxStart(connectionAddress, connectionPort, waitUntilConnected, doNotReconnectOnceDisconnected, timeOutInMs, commThreadCycleInMs). It seems I set 5000ms in timeout now. I will try to enlarge that, and also try non-blocking request, thanks very much!

coppelia