I'd like to run the simulation 5 times, 30 steps each; so I added a for loop.
Code: Select all
print ('Program started')
vrep.simxFinish(-1) # just in case, close all opened connections
clientID=vrep.simxStart('127.0.0.1',19997,True,True,5000,1) # Connect to V-REP
if clientID!=-1:
print ('Connected to remote API server')
# enable the synchronous mode on the client:
vrep.simxSynchronous(clientID,True)
for j in range(5):
print('simulation',j)
time.sleep(.5) # magic delay
# start the simulation:
e = vrep.simxStartSimulation(clientID,vrep.simx_opmode_blocking)
print('start',e)
# Now step a few times:
for i in range(30):
e = vrep.simxSynchronousTrigger(clientID)
print('synct',e)
# wait till simulation step finish
e = vrep.simxGetPingTime(clientID)
print('getping',e)
# stop the simulation:
e=vrep.simxStopSimulation(clientID,vrep.simx_opmode_blocking)
print('stop',e)
# Now close the connection to V-REP:
vrep.simxFinish(clientID)
However, if I comment out the 'magic delay' of 0.5 second, the simulation #0 will run as usual, but simulation #1, #2, #3, and sometimes #4, will not. It behaved like I forgot to call simxStartSimulation(), because all subsequent calls to simxSynchronousTrigger() returned error code 8.
There seems to be a period of time after simxStopSimulation() when simxStartSimulation() returns code 0 but the simulation won't actually start.
Tested on Win7 x64 and OS X 10.11.3