Cannot load scenes with Python API

Typically: "How do I... ", "How can I... " questions
Post Reply
Posts: 3
Joined: 18 Aug 2018, 05:15

Cannot load scenes with Python API

Post by easonok » 03 Sep 2018, 22:29


I need to run a simulation repeatedly for 3 times and collect data from each simulation, thus I am trying to use the simxLoadScene() and simxCloseScene() functions to do so.

Here is what I am doing:

1. Create a clean, brand new scene in VREP.

2. Add

Code: Select all

function sysCall_init()

to the new scene in a remoteApiCommandServer.

3. Start the simulation for the brand new scene.

4. Run this Python API script:

Code: Select all

print ('Program started')
vrep.simxFinish(-1) # just in case, close all opened connections
clientID=vrep.simxStart('',19999,True,True,5000,5) # Connect to V-REP
if clientID!=-1:
    print ('Connected to remote API server')
    for _ in range(0, 3):

    	# Loading the scene
    	ret = vrep.simxLoadScene(clientID, "PATH TO THE DESIRED SCENE", 0, vrep.simx_opmode_blocking)

    	print (ret) # Returns 8 right now, which means there is a server error.

    	# Start the simulation for the desired scene
   	ret = vrep.simxStartSimulation(clientID, vrep.simx_opmode_oneshot)
    	print (ret) # Returns 1 right now
    	######### Collect data in the current simulation. ##########

    	# Stop simulation and close the scene
    	vrep.simxStopSimulation(clientID, vrep.simx_opmode_oneshot)
    	vrep.simxCloseScene(clientID, vrep.simx_opmode_blocking)

    # Before closing the connection to V-REP, make sure that the last command sent out had time to arrive. You can guarantee this with (for example):

    # Now close the connection to V-REP:

    print ('Failed connecting to remote API server')
print ('Program ended')
However, I am not able to load the scene. I was looking at the VREP GUI and the desired scene was never loaded up on there.

Also, no data was collected in the process, thus I am sure the scene wasn't loaded (the script for the collecting of data worked well when I just opened the desired scene and ran it).

Any idea why this didn't work? I am not very familiar with the remote API yet so any help will be appreciated!

Post Reply