Page 1 of 1

Sometimes cannot succeed to switch scene through python remote api

Posted: 28 Aug 2019, 09:53
by lyz
Hello, everyone
I have a problem about the subject. I write the python remote api code to control vrep start、stop、load scene and so on. I want switch some scenes through python remote api, But sometimes it is invalid. Here is my main code, if I add sleep some seconds, the scene switch will be better, but not absolute.

Code: Select all

                    
if (switch_map) :
    vrep.simxStopSimulation(clientID, vrep.simx_opmode_oneshot)
    vrep.simxCloseScene(clientID, vrep.simx_opmode_blocking)
    vrep.simxLoadScene(clientID, scene, 0xFF, vrep.simx_opmode_blocking)
    time.sleep(2)

    _, baseHandle = vrep.simxGetObjectHandle(clientID, 'Vehicle', vrep.simx_opmode_blocking)
    # set robot pose
    vrep.simxSetObjectPosition(clientID, baseHandle, -1, jpos, vrep.simx_opmode_blocking)
    vrep.simxSetObjectOrientation(clientID, baseHandle, -1, jyaw, vrep.simx_opmode_oneshot_wait)

    print ("load scene : " + scene)
    # start simulation
    vrep.simxStartSimulation(clientID, vrep.simx_opmode_oneshot)
Does anybody have this problem? please help me, thanks a lot.

Re: Sometimes cannot succeed to switch scene through python remote api

Posted: 28 Aug 2019, 13:26
by coppelia
Hello,

could it be that some sort of timeout was hit? Can you try to increase the timeout that you specify in simxStart?
Could it be that it takes close to 5 seconds?
If that doesn't work, try to first transfer the file via simxTransferFile and then load it locally.

Also, simxStopSimulation will always take more time to execute, even if in blocking mode. This is because a running simulation can't instantaneously stop. It will first try to stop threaded script, then run a last simulation step. So it might also be that simxCloseScene simply fails because the simulation hasn't yet stopped.

Cheers

Re: Sometimes cannot succeed to switch scene through python remote api

Posted: 30 Aug 2019, 04:41
by lyz
OK, thank you very much. I add one second time sleep under the stop simulation command. And now it is succeed to switch scene every time.

Code: Select all

            
            vrep.simxStopSimulation(clientID, vrep.simx_opmode_oneshot)
            time.sleep(1)
            vrep.simxCloseScene(clientID, vrep.simx_opmode_blocking)
            vrep.simxLoadScene(clientID, scene, 0xFF, vrep.simx_opmode_blocking)

Re: Sometimes cannot succeed to switch scene through python remote api

Posted: 30 Aug 2019, 05:35
by coppelia
Better would be to use simxGetInMessageInfo with simx_headeroffset_server_state to check if simulation has stopped.

Cheers

Re: Sometimes cannot succeed to switch scene through python remote api

Posted: 02 Sep 2019, 11:12
by lyz
OK, Thanks a lot.