ZMQ Python, reset scene problems.

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

ZMQ Python, reset scene problems.

Post by martin »

Hello Coppelia,

I have been using the "Legacy Remote API" for Python for a long time and I think it is time to upgrade to the new ZMQ Remote API. For this, I am working with Coppelia 4.4 on Ubuntu20.04.

With the Legacy Remote API I had been working in Synchronous mode and wanted to do the same with the ZMQ. However, I have encountered a problem in my first tests, related to the reset of the scene by a stop, and subsequent start.

I've done a simple example to show that.

Code: Select all

import numpy as np
from zmqRemoteApi import RemoteAPIClient

def main():
    
    print('Program started')
    client = RemoteAPIClient()
    sim = client.getObject('sim')
    
    time_steps_each_evaluation = 5
    time_steps_each_angular_increment = 40
    angular_increment = 20.0 * np.pi/180.0
    while (True):
        alfa = 45.0 * np.pi/180.0
        beta = 0.0
        gama = 0.0
            
        client.setStepping(True)
        
        j1 = sim.getObject("/j1")
        j2 = sim.getObject("/j2")
        j3 = sim.getObject("/j3")
        
        sim.startSimulation()

        for timeStep in range(0, time_steps_each_evaluation):

            alfa = alfa + angular_increment
            beta = beta + angular_increment
            gama = gama + angular_increment
        
            sim.setJointTargetPosition(j1, alfa)
            sim.setJointTargetPosition(j2, beta)
            sim.setJointTargetPosition(j3, gama)

            # ----  Getting Stuck here ----
            for m in range(0, time_steps_each_angular_increment):
                client.step()

        sim.stopSimulation()
After the "sim.stopSimulation()" the simulation stops and I started it again with "client.setStepping(True)" and "sim.startSimulation()". However, I think the program usually gets stuck in the "client.step()" section of the "for" loop

I also add a link to the scene https://www.dropbox.com/s/gpmt86uqfll4s ... o.ttt?dl=0

Any help would be appreciated.

Regards!

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

Re: ZMQ Python, reset scene problems.

Post by coppelia »

Hello,

make sure that the simulation has really stopped, before starting again, e.g.:

Code: Select all

sim.stopSimulation()
while sim.getSimulationState()!=sim.simulation_stopped:
    pass
The stepped mode is normally reset at the end of a simulation, and you will have to reactivate it again.
If a strange behaviour persists, try to pull the zmqRemoteApi repository, there was a small change related to stepping mode.

Cheers

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

Re: ZMQ Python, reset scene problems.

Post by martin »

Hello,

Many thanks, it has solved the problem. I thought that with the ZMQ API it was not necessary to wait for the "complete stop", as it was with the legacy API.

Regards!

Post Reply