How to call a function from Threaded Child Script remotely

Typically: "How do I... ", "How can I... " questions
Post Reply
alix
Posts: 44
Joined: 17 Sep 2019, 14:48

How to call a function from Threaded Child Script remotely

Post by alix » 22 Nov 2019, 17:25

Hi,
I am trying to call a function from a threaded child script. It is the same script as Jaco have in "MotionPlanningandGrasping.ttt". I am using the following command:

Code: Select all

res,retInts,retFloats,retStrings,retBuffer=vrep.simxCallScriptFunction(sim_client, "Jaco#0", vrep.sim_scripttype_childscript, 'loadPath',[], [], ['jacoPath_1'], emptyBuff, vrep.simx_opmode_blocking)
It is the function in script that loads the path for motion planning. I have tried it both ways with running simulation and stopped simulation both. I'll appreciate any help in this regard.
Thanks.

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

Re: How to call a function from Threaded Child Script remotely

Post by coppelia » 27 Nov 2019, 14:38

Hello,

sorry for the delay.
If you need to call a threaded child script from a remote client, then keep your script function very simple, like:

Code: Select all

function sysCall_threadmain()
    while sim.getSimulationState()~=sim.simulation_advancing_abouttostop do
        if executeFunctionX==1 then
            -- react to the event
        end
        sim.switchThread()
    end
end

function myFunctionName(inInts,inFloats,inStrings,inBuffer)
    executeFunctionX=1
    return {},{},{},''
end
Remember that the function can only be called while the simulation is running, and while the thread is still operational. If the simulation is not running, or the thread ended, it won't work.

In general it is often times much better to use a non-threaded child script for remote script calls.

Cheers

Post Reply