ZeroMQ remote API

The ZeroMQ remote API is one of several ways an application can connect with CoppeliaSim.

The ZeroMQ remote API allows to control a simulation (or the simulator itself) from an external application or a remote hardware (e.g. real robot, remote computer, etc.). It offers all API functions also available via a CoppeliaSim script: this includes all regular API functions (i.e. sim.* -type functions), but also all API functions provided by plugins (e.g. simOMPL.*, simUI.*, simIK.*, etc.). The ZeroMQ remoteAPI represents a very thin Python wrapper around mentioned API functions, and can be used in the exact same way as from within a CoppeliaSim script.

The ZeroMQ remote API functions are interacting with CoppeliaSim via ZeroMQ and its interface plugin to CoppeliaSim and the ZMQ remote API add-on. All this happens in a hidden fashion to the user. The remote API can let one or several external applications interact with CoppeliaSim in a stepped (i.e. synchronized with each simulation step) or non-stepped way (i.e. the normal operation mode), and even remote control of the simulator is supported (e.g. remotely loading a scene, starting, pausing or stopping a simulation for instance).

Note: the ZeroMQ remote API also runs on CoppeliaSim V4.2.0, if you follow this procedure: clone the ZeroMQ remote API repository into your CoppeliaSim/programming folder. Then use this compatibility add-on and that script, and place them into your CoppeliaSim/ and CoppeliaSim/Lua folders respectively.

See programming/zmqRemoteApi folder or its related repository for examples.


ZeroMQ and CBOR are required packages:

$ /path/to/python -m pip install pyzmq $ /path/to/python -m pip install cbor

Here a very simple example ZeroMQ remote API client code (run it in programming/zmqRemoteApi/clients/python/)

import time from zmqRemoteApi import RemoteAPIClient client = RemoteAPIClient() sim = client.getobject('sim') client.setstepping(True) sim.startSimulation() while (t := sim.getSimulationTime()) < 3: s = f'Simulation time: {t:.2f} [s]' print(s) client.step() sim.stopSimulation()


ZeroMQ is a required package:

Windows, e.g. via vcpkg: $ vcpkg install zeromq Ubuntu: $ sudo apt install libzmq3-dev macOSX, e.g. via brew: $ brew install zeromq

Some examples can be found in programming/zmqRemoteApi/clients/cpp/. Build them with:

$ mkdir build $ cd build $ cmake .. $ cmake --build . --config Release

Here another very simple C++ ZeroMQ remote API client:

#include "RemoteAPIClient.h" #include <iostream> #include <iomanip> int main() { RemoteAPIClient client; client.setStepping(true);"sim.startSimulation", nullptr); float simTime=0.0f; while (simTime<3.0f) { std::cout << "Simulation time: " << std::setprecision(3) << simTime << " [s]" << std::endl; client.step();"sim.getSimulationTime")[0].as<float>(); }"sim.stopSimulation", nullptr); return 0; }


Connecting 2 or more CoppeliaSim instances can easily be achieved with following simple example of a child script:

function sysCall_init() remoteApiClient=require'luaZmqRemoteApi' remoteApiClient.init('',23002) simx=remoteApiClient.getObject('sim') remoteApiClient.setStepping(true) simx.startSimulation() end function sysCall_sensing() remoteApiClient.step() end function sysCall_cleanup() simx.stopSimulation() remoteApiClient.cleanup() end