Start a motion after the previous motion is done (or command)

Typically: "How do I... ", "How can I... " questions
Post Reply
zhy149
Posts: 132
Joined: 14 Apr 2021, 20:18

Start a motion after the previous motion is done (or command)

Post by zhy149 »

Hello Coppelia,

I'd like to achieve the effect that a command is executed after the previous one is fully finished.
For example, I have two Inverse Kinematics movements, but I want the second one to be executed after the first one is done (now what I do is to do sim.wait(some time) or use time.sleep in python remote API), is there some way that I can get a signal indicating that the previous command is done so I don't need to wait or sleep?

Thank you!

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

Re: Start a motion after the previous motion is done (or command)

Post by coppelia »

Hello,

if you are using a threaded script, then you simply write the commands sequentially. You can also use sim.wait in there. From a non-threaded script things are a bit different and will depend on how you implemented things. But the recommended path is to use a threaded script for that. e.g.:

Code: Select all

function sysCall_init()
    corout=coroutine.create(coroutineMain)
end

function sysCall_actuation()
    if coroutine.status(corout)~='dead' then
        local ok,errorMsg=coroutine.resume(corout)
        if errorMsg then
            error(debug.traceback(corout,errorMsg),2)
        end
    end
end

function coroutineMain()
    -- execute command 1
    sim.setIntegerSignal("execDone",1)
    -- execute command 2
    sim.setIntegerSignal("execDone",2)
    sim.wait(1)
    -- execute command 3
    sim.setIntegerSignal("execDone",3)
end
Cheers

Post Reply