I'm having a problem when trying to reset the model using simxStopSimulation. If V-REP is opened manually, a robot dragged in, the simulation ran and stopped, the robot returns to the original position. But all efforts to do this using a python script has resulted in the robot disappearing, the simxStartSimulation will then run the simulation without a robot and the position of the robot returns zeros.
I have tried my own model, and a supplied NAO model with the same results. I also have tried starting V-REP externally first, then loading the model from the python script. The problem seems to occur even if I try to manually click the stop button once the model has been loaded from the script.
I'll add as well that I have tried loading a scene instead of a model, the scene loads but the robot isn't in it from the start.
The folder containing the script also has vrep.py, vrepConst.py and remoteAPI.so (I am using Ubuntu 16.04).
Am I missing something in my implementation?
Thanks for your time!
Code: Select all
def run(): path = "/home/brendan/V-REP_PRO_EDU_V3_4_0_Linux/" vrep_path = path + 'vrep.sh' args = [vrep_path] inst = sp.Popen(args) time.sleep(5) v.simxFinish(-1) # just in case, close all opened connections clientID=v.simxStart('127.0.0.1',19997,True,True,5000,5) # Connect to V-REP if clientID!=-1: print ('Connected to remote API server') v.simxSynchronous(clientID,True) v.simxStartSimulation(clientID,v.simx_opmode_blocking) model_path = '/home/brendan/Dropbox/robot/mybot_ws/src/vrep/scripts/NAO.ttm' # scene_path = '/home/brendan/Dropbox/robot/mybot_ws/src/vrep/scripts/nao_scene.ttt' _, robot_handle = v.simxLoadModel(clientID, model_path, 0, v.simx_opmode_blocking) # robot_handle = v.simxLoadScene(clientID, model_path, 0, v.simx_opmode_blocking) print(robot_handle) for i in range(1000): _, xyz = v.simxGetObjectPosition(clientID, robot_handle, -1, # retrieve absolute, not relative, position v.simx_opmode_blocking) print(xyz) if i%100 == 0 and i != 0: print("fallen over") v.simxStopSimulation(clientID, v.simx_opmode_blocking) v.simxGetPingTime(clientID) v.simxSynchronous(clientID,True) v.simxStartSimulation(clientID,v.simx_opmode_blocking) time.sleep(5) v.simxSynchronousTrigger(clientID) v.simxFinish(clientID) print('connection closed...')