synchronous mode in ZeroMQ

Typically: "How do I... ", "How can I... " questions
Post Reply
dzic_HQU
Posts: 11
Joined: 12 Mar 2022, 07:15

synchronous mode in ZeroMQ

Post by dzic_HQU »

Hello! ZeroMQ remote API is very convenient, but I don't know how to config synchronous mode in ZeroMQ with python, Can you give me a demo? And I want to set timestep "dt" in my code.

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

Re: synchronous mode in ZeroMQ

Post by coppelia »

Hello,

here a demo in stepped (or synchronous) mode:

Code: Select all

import time

from zmqRemoteApi import RemoteAPIClient

print('Program started')

client = RemoteAPIClient()
sim = client.getObject('sim')

# 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()

print('Program ended')
Cheers

Post Reply