nonSimulation loop

Typically: "How do I... ", "How can I... " questions
Post Reply
mikim
Posts: 3
Joined: 29 Mar 2025, 18:32

nonSimulation loop

Post by mikim »

I am working no a project, which requires a modbus communication between python script and Coppelia Sim. I've made a child customization script in Coppelia to establish the client and my python app is providing the server side. I am using pyModbusTCP to make it work.

I now need to start the simulation via the modbus, so I need a loop checking whether there is a set up register or coil for that. Unfortunatelly that causes the Abort. I know aborting can be disabled in usrset.txt, but I'd prefer rather more elegant solution without messing with this settings. Is there any efficient way to do so?

Do you also have any suggestions on how to make the modbus communication as fast as possible? The scene won't be too heavy and I need as little latency as possible. I am using the threaded script, but I can notice slight delay in simulation time when using modbus to write data from simulation to registers in each simulation step.
coppelia
Site Admin
Posts: 10747
Joined: 14 Dec 2012, 00:25

Re: nonSimulation loop

Post by coppelia »

Hello,

not sure I underfstand you correctly. What kind of signal is your Python client providing to CoppeliaSim? If you want to start the simulation from an external Python client you'd normally use the ZeroMQ remote API and simply call sim.startSimulation

Cheers
mikim
Posts: 3
Joined: 29 Mar 2025, 18:32

Re: nonSimulation loop

Post by mikim »

I know ZeroMQ is the best choice, but circumstances force me to start the simualtion via modbus. Now i am prototyping it using pyModbusTCP, but it is going to use serial later on. I just want the sysCall_nonSimulation() to check for a register to be set to 1 from 0 by external pyModbustTCP script and then start the simulation. I know it is not very straightforward... Another option would be to start one side of modbus on one device, then another on the second device to exchange data between them and use the second on to also run Coppelia Sim and control the simulation via ZeroMQ, so: DEVICE1( Modbus ) ----> DEVICE2( Modbus+ZeroMQ ----> Coppelia Sim ). My current workflow is: DEVICE1 ( Modbus ) ----> DEVICE2( Coppelia Sim child script with embedded Modbus ).
coppelia
Site Admin
Posts: 10747
Joined: 14 Dec 2012, 00:25

Re: nonSimulation loop

Post by coppelia »

So do you have something similar to this?

Code: Select all

function sysCall_init()
    sim = require('sim')
    ...
end

function sysCall_nonSimulation()
    if checkForTrigger() then
        sim.startSimulation()
    end
end

function checkForTrigger()
    local triggered = false
    -- do a non-blocking check
    return triggered
end
Is the problem that you are not doing a non-blocking check?

Cheers
Post Reply