Remote API

The remote API is one of several ways an application can connect with CoppeliaSim. It allows communication between CoppeliaSim and an external application (i.e. an application running in a different process, or on a different machine), is cross-platform, supports service calls (i.e. blocking calls), and also bidirectional data streaming. It comes in two distinct versions/frameworks:

  • The ZeroMQ remote API: it is lightweight and easy to use, offers all API functions also available via a CoppeliaSim script, and currently supports Python and C++ clients.
  • The WebSocket remote API: it is lightweight and easy to use, offers all API functions also available via a CoppeliaSim script, and handles remote calls via WebSocket from a JavaScript.
  • The legacy remote API (or simply remote API): it is comparatively lightweight. It offers a subset of API functions and supports following clients: C/C++, Java, Python, Matlab and Octave.
  • [Remote API flavors]

    As an example, a Python ZeroMQ remote API client receiving and applying back a vision sensor image could look like:

    from time import sleep from zmqRemoteApi import RemoteAPIClient client = RemoteAPIClient('localhost',23000) sim = client.getobject('sim') sensor1Handle=sim.getObject('/VisionSensor') sensor2Handle=sim.getObject('/PassiveVisionSensor') sim.startSimulation() while True: image,resX,resY=sim.getVisionSensorCharImage(sensor1Handle) sim.setVisionSensorCharImage(sensor2Handle,image) sleep(0.01) sim.stopSimulation()

    The same example as above, but for a legacy remote API client:

    import sim from time import sleep clientID=sim.simxStart('127.0.0.1',19997,True,True,5000,5) if clientID!=-1: res,sensor1Handle=sim.simxGetObjectHandle(clientID,'/VisionSensor1',sim.simx_opmode_oneshot_wait) res,sensor2Handle=sim.simxGetObjectHandle(clientID,'/VisionSensor2',sim.simx_opmode_oneshot_wait) res,resolution,image=sim.simxGetVisionSensorImage(clientID,sensor1Handle,0,sim.simx_opmode_streaming) sim.simxStartSimulation(clientID,sim.simx_opmode_oneshot) while (sim.simxGetConnectionId(clientID)!=-1): res,resolution,image=sim.simxGetVisionSensorImage(clientID,sensor1Handle,0,sim.simx_opmode_buffer) if res==sim.simx_return_ok: res=sim.simxSetVisionSensorImage(clientID,sensor2Handle,image,0,sim.simx_opmode_oneshot) sleep(0.01) sim.simxFinish(clientID)