Document and Question for coppeliaSim.lib

Typically: "How do I... ", "How can I... " questions
Post Reply
zhengkz
Posts: 17
Joined: 16 Jul 2021, 20:58

Document and Question for coppeliaSim.lib

Post by zhengkz »

Hi,

I wonder where I can find documents for coppeliaSim.lib? I only see several examples in the CoppeliaSim's library section of the manual but I don't find the specific document to explain the arguments for several functions like, simInitialize, simRunGui, simLoop, etc.

To be more specific, I have two questions:
1. Should simLoop always be used as simLoop(None, 0) ?
2. Another thing is that if I only use simInitialize without simRunGui, does it mean headless running? Then, what's the purpose of the headless argument in the simRunGui?

Thanks,
kz

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

Re: Document and Question for coppeliaSim.lib

Post by coppelia »

Hello Kz,

yes, for now, keep the arguments of simLoop unchanged. In a future version, there might be more possibilities.

Then, you can run CoppeliaSim in two types of headless mode:

a) only supressing the GUI part (emulated headless mode): this will run quite similarly with the regular mode, with the difference that dialogs are not initialized nor shown. From the command line, you'd start the default CoppeliaSim client with:

Code: Select all

coppeliaSim -h
The Python client however should be invoked with:

Code: Select all

python3 coppeliaSim.py -H
b) running CoppeliaSim in true headless mode: this is a different library, which does not have any GUI thread. So simRunGui won't have to be called in that mode when starting via the Python client. From the command line, you'd start the default CoppeliaSim client with:

Code: Select all

coppeliaSim -H
The Python client however should be invoked with:

Code: Select all

python3 coppeliaSim_noUI.py

zhengkz
Posts: 17
Joined: 16 Jul 2021, 20:58

Re: Document and Question for coppeliaSim.lib

Post by zhengkz »

Hi,

I have some further questions. What's the difference between simLoop(None, 0) and sim.step(). I find my thread will be blocked after I call sim.step() even though I have set sim.setStepping(True).

Best,
Kz

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

Re: Document and Question for coppeliaSim.lib

Post by coppelia »

If as in your case you run within the CoppeliaSim thread, i.e. you loaded the coppeliaSim library via Python, then you should use simLoop or simStep (instead of sim.step). But in the end, simStep is a subset of simLoop: simLoop is meant to be used when running CoppeliaSim via the GUI, e.g.:

Code: Select all

    while not simGetExitRequest():
        simLoop(None, 0)
In above code, start simulation, stop simulation, etc. should come from the GUI or from some other control entity (e.g. a remote API client). Also, in above, you do not have direct control of each simulation steps.
However if you do not have any other interaction from the GUI or similar, or you want to perfectly control when the next simulation step happens, use simStep, e.g.:

Code: Select all

    sim.loadScene('path/to/scene.ttt')
    simStart()
    for i in range(1000):
        t = sim.getSimulationTime()
        print(f'Simulation time: {t:.2f} [s] (simulation running synchronously to client, i.e. stepped)')
        simStep()
    simStop()
    simDeinitialize()
simStep however only works when simulation is running. Above is actually equivalent to:

Code: Select all

    sim.loadScene('path/to/scene.ttt')
    simStart()
    for i in range(1000):
        t = sim.getSimulationTime()
        print(f'Simulation time: {t:.2f} [s] (simulation running synchronously to client, i.e. stepped)')
        simLoop(None, 0)()
    simStop()
    simDeinitialize()
Cheers

Post Reply