Remote API calls getting slower and slower

Report crashes, strange behaviour, or apparent bugs
Post Reply
JoakimMagnusson
Posts: 11
Joined: 09 May 2018, 10:31

Remote API calls getting slower and slower

Post by JoakimMagnusson » 21 Sep 2018, 16:04

Hi,

I have a problem that my python remote API calls are getting slower and slower whenever I run a simulation.
I run in synchronous mode.

For get handles calls I'm doing like this:

Code: Select all

errorCode, handle = vrep.simxGetObjectHandle(self.clientID, string, vrep.simx_opmode_blocking)
For get variable calls I'm first initiating with this call:

Code: Select all

vrep.simxGetObjectPosition(self.clientID, self.hexapod, -1, vrep.simx_opmode_streaming)
and then during the rest of the simulation I'm doing like this:

Code: Select all

while (vrep.simxGetConnectionId(self.clientID) != -1):
			[result,position]=vrep.simxGetObjectPosition(self.clientID, self.hexapod, -1, vrep.simx_opmode_buffer)
			if (result==vrep.simx_return_ok):
 				return position
Worth mentioning is also that I resets my simulation model (of a robot) several times during the simulation. In my reset function, I'm doing like this for all get variable calls:

Code: Select all

vrep.simxGetObjectPosition(self.clientID, self.hexapod, -1, vrep.simx_opmode_discontinue)
Then I remove and reload my model (In order to move it to it's starting position). After this I initiate all get variable calls with simx_opmode_streaming again.

For set variable calls I'm using the simx_opmode_oneshot or simx_opmode_oneshot_wait operators.

I thought doing like this would prevent the simulation from slowing down but it still does. How do I know it's getting slower? I'm timing my simxSynchronousTrigger call which are getting longer and longer during simulation.

Is there something else to have in mind in order to not get any memory leaks or whatever is causing this issue?

I can show more code if necessary but I tried to extract the important parts and thought it would be more helpful than just printing all my code.

JoakimMagnusson
Posts: 11
Joined: 09 May 2018, 10:31

Re: Remote API calls getting slower and slower

Post by JoakimMagnusson » 27 Sep 2018, 10:22

I tried to just restart the simulation instead of removing and reloading my robot model, this made the problem disappear. Restarting the simulation is slower than reloading the model and I would like to use the fastest option. So I still wonder why this problem occur, do I reload the model in the wrong way maybe?

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

Re: Remote API calls getting slower and slower

Post by coppelia » 01 Oct 2018, 07:36

Hello,

I am not sure due to what reason the simulation gets slower. Is it the simulation itself, or the remote API?
My first guess was that it could be the remote API, where streaming data is not properly discontinued. But it seems you are discontinuing streaming commands, so that is not the reason. Can you notice a memory usage increase that is more than what you expect?
Maybe when remove your model, not everything is removed (e.g. a collision checking object) and you end-up with many duplicates? (normally this is automatically handled when removing the model, but specific collision objects are persistent)

Cheers

Post Reply