CoppeliaRobotics / zmqRemoteApi

Other
34 stars 9 forks source link

Stepping mode on Python #2

Closed virusapex closed 1 year ago

virusapex commented 1 year ago

I'm not sure if this is an intended behavior, but I'm running an example "simpleTest.py" and calling a simulation in stepping mode for the second time doesn't retain simulation stepping and engine just runs as fast as it can, similar to asynchronous example above. It seems like disabling and enabling setStepping helps. Is it the intended way to use this method? I'm asking since I constantly require to reset the simulation for reinforcement learning. Thank you in advance for the answer.

Coppelia commented 1 year ago

@virusapex, so does simpleTest.py work as expected? It should run one simulation in non-stepping, then another in stepping mode. Once the client ends, the stepping mode is not retained, this is normal behaviour.

virusapex commented 1 year ago
# Run a simulation in stepping mode:
client.setStepping(True)
sim.startSimulation()
while (t := sim.getSimulationTime()) < 3:
    s = f'Simulation time: {t:.2f} [s] (simulation running synchronously '\
        'to client, i.e. stepped)'
    print(s)
    sim.addLog(sim.verbosity_scriptinfos, s)
    client.step()  # triggers next simulation step
sim.stopSimulation()
# If you need to make sure we really stopped:
while sim.getSimulationState() != sim.simulation_stopped:
    time.sleep(0.1)

client.setStepping(False)
client.setStepping(True)
sim.startSimulation()
while (t := sim.getSimulationTime()) < 3:
    s = f'Simulation time: {t:.2f} [s] (simulation running synchronously '\
        'to client, i.e. stepped)'
    print(s)
    sim.addLog(sim.verbosity_scriptinfos, s)
    client.step()  # triggers next simulation step
sim.stopSimulation()

Everything is fine with the example code. But look at this one instead. It's the same, I only added second call for stepping simulation. I agree, stepping mode isn't being retained after first simulation ends, but in order for this parameter to work on the next one, I have to disable it and then enable it again in order for stepping mode to work properly. Otherwise, even if I call client.setStepping(True) again, simulation is going to operate in non-stepping mode.

Coppelia commented 1 year ago

You are right. That is a confusing way that function operates. I pushed a change, please try it. You will still have to explicitely enable the stepping mode after each simulation run, but no more off and on switching

virusapex commented 1 year ago

Yup, this is better and working fine now. Thank you for your respond!