How to use callScriptFunction in threaded script?

Typically: "How do I... ", "How can I... " questions
Post Reply
elephant
Posts: 8
Joined: 11 Feb 2021, 18:29

How to use callScriptFunction in threaded script?

Post by elephant »

In legacy remote API side, im using the python function like this:

Code: Select all

sim.simxCallScriptFunction(clientID, 'Dobot', sim.sim_scripttype_childscript, 'movetoPoss', [50,0,0,0], [], [], bytearray(), sim.simx_opmode_blocking)
and the threaded child script on Dobot robot is:

Code: Select all

function movetoPos(j1,j2,j3,j4,enable)
    modelBase=sim.getObjectAssociatedWithScript(sim.handle_self)
    modelName=sim.getObjectName(modelBase)
    motorHandles = {}
    j={j1*math.pi/180,j2*math.pi/180,j3*math.pi/180,j4*math.pi/180}

    for i=1,4,1 do
        motorHandles[i]=sim.getObjectHandle('Dobot_motor'..i)
    end
    for i=1,4,1 do
        sim.setJointTargetPosition(motorHandles[i],j[i])
        sim.wait(2)
    end
   
    if enable then
        sim.setIntegerSignal(modelName .."_suctionCup",1)
    else
        sim.setIntegerSignal(modelName .."_suctionCup",0)
    end
    return {},{},{},''
end

function sysCall_threadmain()
    --[[
    --Motor1,Motor2,Motor3,Motor4,Suction Cup
    movetoPos(50,50,47,0,true)
    movetoPos(100,0,0,45,true)
    movetoPos(50,50,47,45,false)
    movetoPos(50,0,0,45,false)
    movetoPos(0,0,0,0,false)
    --]]
end

function movetoPoss(j1, j2, j3, j4)
    movetoPos(50,20,20,60,true)
end

using the function movetoPoss (yes, with 2 's' just for tests) and getting the error message "External call to simCallScriptFunction failed (movetoPoss@Dobot): Failed calling script function."

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

Re: How to use callScriptFunction in threaded script?

Post by coppelia »

Hello,

Make sure that the script that you are calling is initialized. This means, the script should have started, and not yet ended. In your case, the script immediately ends, and so it will immediately deinitialize.

Cheers

elephant
Posts: 8
Joined: 11 Feb 2021, 18:29

Re: How to use callScriptFunction in threaded script?

Post by elephant »

coppelia wrote:
16 Feb 2021, 10:13
Hello,

Make sure that the script that you are calling is initialized. This means, the script should have started, and not yet ended. In your case, the script immediately ends, and so it will immediately deinitialize.

Cheers
But how can i do it? " the script should have started, and not yet ended"

fferri
Posts: 714
Joined: 09 Sep 2013, 19:28

Re: How to use callScriptFunction in threaded script?

Post by fferri »

Have a while loop running continuously in the main thread function, like it's done in the default threaded script.

elephant
Posts: 8
Joined: 11 Feb 2021, 18:29

Re: How to use callScriptFunction in threaded script?

Post by elephant »

fferri wrote:
19 Feb 2021, 09:48
Have a while loop running continuously in the main thread function, like it's done in the default threaded script.
Thank you! that solved my problem.

Post Reply