Page 1 of 1

trouble with the remoteAPI

Posted: 25 Oct 2023, 10:57
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

Re: trouble with the remoteAPI

Posted: 25 Oct 2023, 13:16
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

Re: trouble with the remoteAPI

Posted: 25 Oct 2023, 15:35
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

Re: trouble with the remoteAPI

Posted: 25 Oct 2023, 15:45
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)

Re: trouble with the remoteAPI

Posted: 25 Oct 2023, 19:33
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

Re: trouble with the remoteAPI

Posted: 26 Oct 2023, 02:12
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

Re: trouble with the remoteAPI

Posted: 26 Oct 2023, 06:26
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

Re: trouble with the remoteAPI

Posted: 26 Oct 2023, 06:40
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