Issue with Pausing and Resuming Simulation (with Python/ZeroMQ)

Typically: "How do I... ", "How can I... " questions
Post Reply
dav_paul
Posts: 3
Joined: 02 Dec 2021, 22:00

Issue with Pausing and Resuming Simulation (with Python/ZeroMQ)

Post by dav_paul »

Good day,

I am currently working with the Python ZeroMQ API method of interacting with the simulator. My objective is to use CoppeliaSim to record demonstrations of manipulations on basic shapes with a robot arm and gripper. I wish to record a sequence of actions one by one by pausing and resuming the simulation in steps.

I am doing this as follows: 1) start the simulation in a base state, 2) perform one action and record position/orientation of objects, 3) pause the simulation when an action is complete, 4) resume the simulation to record another action, 4) repeat steps 2 - 4 for different actions, and 5) stop the simulation when entire demonstration is completed.

I am currently using the functions sim.startSimulation(), sim.stopSimulation(), sim.pauseSimulation(), and sim.getSimulationState() to perform this all. The following shows some function calls I made that use these (based on the ZeroMQ tutorial files):

Code: Select all

# python
def _stopDemo():
    sim.stopSimulation()
    while sim.getSimulationState() != sim.simulation_stopped:
        time.sleep(0.1)

def _pauseDemo():
    sim.pauseSimulation()
    while sim.getSimulationState() != sim.simulation_paused:
        time.sleep(0.1)

def _startDemo():
    sim.startSimulation()
    while sim.getSimulationState() != sim.simulation_advancing_running:
        time.sleep(0.1)
I use keystrokes that are detected by the Python client to call upon these operations.

My issue is that I am unable to resume my simulation after recording my first action. Once I send the resume command (via sim.startSimulation()), the Python client hangs, and the simulation does not seem to receive the call to resume. If I instead stop instead of pause (and I deselect the "Reset scene to initial state" option in the "Simulation Settings" for Coppelia), I can successfully start and stop recording action by action. However, I am faking some grasps by attaching the objects to a gripper, so stopping and starting will detach the objects between actions, unlike when the simulation is paused. This disrupts the flow of recording, especially if I need to keep an object grasped without slipping or dropping between actions.

Is there something that I am not considering for pausing/resuming correctly? Thank you!

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

Re: Issue with Pausing and Resuming Simulation (with Python/ZeroMQ)

Post by coppelia »

Hello,

yes, you are right, something's wrong!
With CoppeliaSim V4.2.0, you can download the updated version of the ZeroMQ remote API add-on, or simply add following, in simAddOnZMQ remoteAPI.lua:

Code: Select all

function sysCall_suspended()
    zmqRemoteApi.handleQueue()
end
Thanks!
Cheers

dav_paul
Posts: 3
Joined: 02 Dec 2021, 22:00

Re: Issue with Pausing and Resuming Simulation (with Python/ZeroMQ)

Post by dav_paul »

Thank you for the swift reply! That worked like a charm.

Post Reply