Robot disappears when stopping the simulation - Python API

Typically: "How do I... ", "How can I... " questions
Post Reply
neveryoubetray
Posts: 2
Joined: 06 Dec 2017, 14:12

Robot disappears when stopping the simulation - Python API

Post by neveryoubetray » 06 Dec 2017, 23:26

Hey guys,

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...')
    

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

Re: Robot disappears when stopping the simulation - Python API

Post by coppelia » 09 Dec 2017, 18:03

Hello,

by default, objects will be reset to their original position/orientation at the end of a simulation. By default too, objects added to the simulation while simulation is running, will be removed at the end of a simulation.

You can change the default behaviour in the simulation properties. Or you can add the object before simulation is started.

Cheers

neveryoubetray
Posts: 2
Joined: 06 Dec 2017, 14:12

Re: Robot disappears when stopping the simulation - Python API

Post by neveryoubetray » 11 Dec 2017, 00:18

Legend! Thank you.

Post Reply