trouble with the remoteAPI

Report crashes, strange behaviour, or apparent bugs
Post Reply
Oz@SIT
Posts: 19
Joined: 10 Jul 2014, 10:03

trouble with the remoteAPI

Post by Oz@SIT »

Dear Sirs:

Thank you for the new release of CoppeliaSim v. 4.6.0!

I have some trouble with the remoteAPI.

My program is as follows:

from coppeliasim_zmqremoteapi_client import RemoteAPIClient

client = RemoteAPIClient()
sim = client.getObject('sim')
client.setStepping(True)

sim.startSimulation()
while(True):
pass
-----------------------------------------------------------------

The problem is when sim.startSimulation() is invoked, the following error appeared on the screen:

Connectivity >> ZMQ remote API server@addOnScript: abort execution


I removed the client.setStepping(True) line, then the simulator runs fine.

Is there something wrong with my code?

Thanks for your help,

Oz

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

Re: trouble with the remoteAPI

Post by coppelia »

Hello Oz,

when in stepping mode, CoppeliaSim will pause simulation until sim.step() is called. After sim.step() is called, exactly one simulation step is executed before the next pause, etc.

Cheers

Oz@SIT
Posts: 19
Joined: 10 Jul 2014, 10:03

Re: trouble with the remoteAPI

Post by Oz@SIT »

Thanks for the note.
I am back in my home, where CoppeliaSim is still v. 4.5.1.
On v.4.5.1, the former code (without step()) works.

I will check the code with step() tomorrow with v.4.6.0.

Thank you for your kind help.

Oz

Oz@SIT
Posts: 19
Joined: 10 Jul 2014, 10:03

Re: trouble with the remoteAPI

Post by Oz@SIT »

For v.4.5.1, I checked the followings:
With an empty scene A) doesn't run (no printout), but B) runs (prints the count variable).

My code is:

A)
from coppeliasim_zmqremoteapi_client import RemoteAPIClient
import time

client = RemoteAPIClient()
sim = client.getObject('sim')
client.setStepping(True)

sim.startSimulation()
count = 0
while(True):
time.sleep(0.05)
client.step()
count += 1
print(count)

B)
from coppeliasim_zmqremoteapi_client import RemoteAPIClient
import time

client = RemoteAPIClient()
sim = client.getObject('sim')
client.setStepping(True)

sim.startSimulation()
count = 0
while(True):
time.sleep(0.05)
# client.step()
count += 1
print(count)

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

Re: trouble with the remoteAPI

Post by coppelia »

You need to make sure to match the corresponding CoppeliaSim version and client application. With CoppeliaSim V4.5.1, you can't use:

Code: Select all

from coppeliasim_zmqremoteapi_client import RemoteAPIClient
but you should use:

Code: Select all

from zmqRemoteApi import RemoteAPIClient
There are other finer details with CoppeliaSim V4.6, where you can use:

Code: Select all

sim = client.require('sim') # instead of sim = client.getObject('sim') 
sim.setStepping(sw) # instead of client.setStepping(sw)
sim.step() # instead of client.step()
Also adding a sleep in a stepping simulation very rarely makes sense, and just slows down things unnecessarily

Cheers

Oz@SIT
Posts: 19
Joined: 10 Jul 2014, 10:03

Re: trouble with the remoteAPI

Post by Oz@SIT »

Thank you very much for your explanation.
I now can run the simulator with v.4.6.0.

I would like to run the simulation in real-time mode.
I try to check the mode with
sim.getRealTimeSimulation()
but it returns an exception of "type object 'sim' has no attribute 'getRealTimeSimulation'." Has the name of the function been changed?

Also, could you tell me how to set the real-time mode in python?

Thanks,

Oz

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

Re: trouble with the remoteAPI

Post by coppelia »

There was a glitch somewhere, and now the function is called sim.getIsRealTimeSimulation somehow... next release will have the sim.getRealTimeSimulation function available again.

But you can also use sim.getBoolParam and sim.setBoolParam with sim.boolparam_realtime_simulation to get/set that state.

Cheers

Oz@SIT
Posts: 19
Joined: 10 Jul 2014, 10:03

Re: trouble with the remoteAPI

Post by Oz@SIT »

Thank you for the quick reply.
I have tried it and have had a good result.

Thank you for your continued help,

Oz

Post Reply