Python API Synchronization problem.

Typically: "How do I... ", "How can I... " questions
martin
Posts: 8
Joined: 15 Mar 2016, 10:38

Python API Synchronization problem.

Postby martin » 17 May 2017, 13:52

Hello,

I am using a W10 operating system and the 3.4.0 VREP version and I am runnig the VREP with a external API (Python, through the PyCharm IDE) in synchronous mode.

The experiment consist of testing an evolutionary algorithm and a neural network using a Poppy robot. I need to run many experiments, changing the scene and restart the robot always in the same start position.

For do that, I load a scene where in each iteration I change the position of an object and reload always the same robot model to start always on the same position.

Here I present the pseudocode:

Code: Select all

At the beginnig of the program:

vrep.simxFinish(-1)
vrep.simxStart(vrep_host, vrep_port, True, True, 5000, 5)
vrep.simxSynchronous(clientID, True)
vrep.simxStartSimulation(clientID, vrep.simx_opmode_blocking)

Then, in each evaluation step, I do the following:
        stopSim(clientID)
        getPingTime(clientID)
        loadModel(clientID, vrep_model)
        moveObject(clientID, ovjectHandle, Position to move)
        startSim(clientID)
        getPingTime(clientID)
        getRobotHandlers
       
        (do the evolutive process. Libraries used: OpenCV, Pybrain, DEAP)
       
        closeModel(clienteID)
        getPingTime(clientID)


I stop the simulation before starting the new iteration process for loading the new model and changing the position of an object.
I call "getPingTime" after a stop, start simulation and close model, because if I don't understand bad, it is a blocking function that is executed when the previous commands/orders have been finished and I think taht "stop", "start" and "close" need to be finished before following into the program. Without it, after some iterations, the model appears twice in the scene.

But my problem is the ping time continously increase, iteration by iteration, achieving a time when the program crash for timeout. Furthermore, as there is not high resources consume in RAM memory or Disk on the PC, I am not able to figure where the problem could be. I suppose that it is in the communication between my IDE and the VREP but I don't know how to solve it.

Any idea what could cause this problem and how to solve it?

Regards!

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

Re: Python API Synchronization problem.

Postby coppelia » 17 May 2017, 16:42

Hello,

not sure what is going on, but I guess it might be linked to the fact that the start, and stop simulation commands may take more than one simulation step to execute. I would do something like following:

  • connect to V-REP
  • load a scene with the model already in it
  • move the model
  • start the simulation
  • run the simulation
  • stop the simulation
  • wait until the simulation state is really stopped
  • loop back up to the third bullet point

Cheers

martin
Posts: 8
Joined: 15 Mar 2016, 10:38

Re: Python API Synchronization problem.

Postby martin » 20 May 2017, 13:11

Hello,

I was able to find a solution to this problem. I've followed your suggestion to load an scene with the model in it instead of loading the model each time and I've followed your "step guide". But the problem was still there.
To solve it, I have to finish a and start a new comunication with the VREP each time I make a change into the scene.

This is the pseudocode:

Code: Select all

On each step of the loop:

   # Start of the loop
   vrep.simxFinish(-1)
   clientID_aux = vrep.simxStart(vrep_host, vrep_port, True, True, 5000, 5)
   vrep.simxSynchronous(clientID_aux, True)
   vrep.simxStartSimulation(clientID_aux, vrep.simx_opmode_blocking)
   vrep.simxGetPingTime(ID_scene)
   getRobotHandlers()
   moveObject(clientID, Handle, objectPosition)
   simxSynchronousTrigger(ID_scene)

   (do the evolutive process. Libraries used: OpenCV, Pybrain, DEAP)

   vp.stopSim(clientID)
   vrep.simxGetPingTime(ID_scene)

   # End of the loop and start again.

With this structure, the ping time remanin stable during the hole evolution process (more than 8h) and the program could end successfully.


Return to “General questions”

Who is online

Users browsing this forum: Bing [Bot], mohtashem and 19 guests