CoppeliaSim official tutorial BØ-based remote API

This article is a translation of the official course, if infringement, please contact deleted

BØ-based remote API

Remote control simulation allows API B0 (or emulator itself) from an external application or remote hardware (e.g., a real robot, a remote computer, etc.). CoppeliaSim B0-based remote API consists of about a hundred specific functions and composition of a generic function that can be called from C ++ applications, Python scripts, Java applications, Matlab program or Lua script. BlueZero and interact through the middleware and interface cards and CoppeliaSim CoppeliaSim based remote API functions of B0. All of these are hidden to the user. Remote API lets one or several external applications with synchronous or asynchronous way to interact with CoppeliaSim (asynchronous by default), and even supports remote control of the simulator (for example, remote loading scenario, start, pause or stop simulation).
"Synchronize" the meaning of the word is that each simulation cycle is synchronized with the operation of Remote API application (ie, the emulator will wait for a trigger signal from the client to the next time t + dt at the beginning of a simulation cycle). Blocking / non-blocking operations synchronous / asynchronous different. Remote API also supports blocking and non-blocking operations.
Based on a similar invocation API function calls remotely with the conventional B0 API function, but there is one major difference:

Most B0-based remote API functions require an additional parameter: the communication channel for performing topic or function call. The topic may be one of the following five function return value:

simxServiceCall: This topic allowed to execute the function in blocking mode, i.e., the command to the server (i.e. CoppeliaSim), performed on the server, and then returns the response to the client. In order to obtain the command only if the response from the server (disposable) Using this category (e.g. simxGetObjectHandle ServiceCall usually performed).
simxDefaultPublisher: This topic allowed to execute the function in non-blocking mode, i.e., the function is sent to the server (i.e. CoppeliaSim), and control is immediately returned to the client (i.e., the client will not wait for the reply from the server). Only you do not want to send commands on the server / server response is not required when using this theme (for example, simxSetJointPosition DefaultPublisher will typically be used to perform).
simxDefaultSubscriber: This subject continues to perform the functions of the notification server, and in response to continuous stream to the client. The client receives a response to the callback function. Only if you wish to receive a response from the server the same command executed consecutively, only use this theme. (Eg simxGetJointForce often use DefaultSubscriber execution). Defined callback function called by the function simxSpinOnce (when responsive to the input buffer).
simxCreatePublisher: This simxDefaultPublisher very similar, except that the publisher created a special topic, namely the creation of a dedicated distribution channels. Assign specific functions / commands to specific publisher may be useful, especially for large amounts of data (for example simxSetVisionSensorImage generally use a dedicated publisher to perform).
simxCreateSubscriber: This simxDefaultSubscriber very similar, except that, to create a dedicated subscribers theme that creates a private subscriber channel. Assign specific functions / commands to specific subscribers, particularly large amounts of data (e.g., simxGetVisionSensorImage typically performed using dedicated subscriber), it may be useful.

By default, B0-based remote API clients and servers (ie CoppeliaSim) will run asynchronously. However, it can allow customers to trigger each simulated step alone end to achieve synchronous operation. The following is an example of a synchronization pattern Python:

import b0RemoteApi
import time

with b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient','b0RemoteApi') as client:    
    doNextStep=True

    def simulationStepStarted(msg):
        simTime=msg[1][b'simulationTime'];
        print('Simulation step started. Simulation time: ',simTime)
        
    def simulationStepDone(msg):
        simTime=msg[1][b'simulationTime'];
        print('Simulation step done. Simulation time: ',simTime);
        global doNextStep
        doNextStep=True
        
    client.simxSynchronous(True)
    client.simxGetSimulationStepStarted(client.simxDefaultSubscriber(simulationStepStarted));
    client.simxGetSimulationStepDone(client.simxDefaultSubscriber(simulationStepDone));
    client.simxStartSimulation(client.simxDefaultPublisher())
    
    startTime=time.time()
    while time.time()<startTime+5: 
        if doNextStep:
            doNextStep=False
            client.simxSynchronousTrigger()
        client.simxSpinOnce()
    client.simxStopSimulation(client.simxDefaultPublisher()

B0-based remote API function from two separate parts, which interact through BlueZero frame:

The client (ie your application):
Based Remote API B0 can be used for many different programming languages on the client. Currently supports the following languages: C ++, Python, Java, Matlab and Lua. You can easily create bindings for other languages.
Server-side (ie CoppeliaSim):
server-based remote API B0 is through CoppeliaSim plugins and Lua scripts (lua / b0RemoteApiServer.lua) implementation. The plug-in should be loaded at startup by the CoppeliaSim: simExtBlueZero.dll, libsimExtBlueZero.dylib or libsimExtBlueZero.so.

Client

All units of the API are in meters, kilograms, seconds, and radians or a combination thereof as a unit (unless explicitly stated otherwise).

To C ++ applications using the API-based remote function B0, simply include the following files in the project:

  1. programming/remoteApiBindings/b0Based/cpp/b0RemoteApi.h
  2. programming/remoteApiBindings/b0Based/cpp/b0RemoteApi.h
  3. Path comprising programming / remoteApiBindings / b0Based / cpp / msgpack-c / include
  4. Path comprising programming / blueZero / include / b0 / bindings
  5. Link blueZero library (eg b0.dll), and do not forget blueZero library itself has a dependency (eg libzmq, boost_chrono, boost_system, boost_thread, etc.).

Check the programming / remoteApiBindings / b0Based / cpp / simpleTest project files, and presentations based on a scene B0 of RemoteApiDemo.ttt appropriate, for more details.

ToPython scriptUse Remote API function B0, you need to do the following:

  1. Python is installed MessagePack: PIP install msgpack
  2. programming/remoteApiBindings/b0Based/python/b0RemoteApi.py
  3. programming/remoteApiBindings/b0Based/python/b0.py
  4. Link blueZero library (eg b0.dll), and do not forget blueZero library itself has a dependency (eg libzmq, boost_chrono, boost_system, boost_thread, etc.).

For additional details, please refer to the programming / remoteApiBindings / b0Based / python / simpleTest.py program, based on the demo scene B0 of RemoteApiDemo.ttt.

To Matlab program using the Remote API function B0, you need to do the following:

  1. programming/remoteApiBindings/b0Based/matlab/b0RemoteApiProto.m
  2. programming/remoteApiBindings/b0Based/matlab/b0RemoteApi.m
  3. Folders programming / remoteApiBindings / b0Based / matlab / msgpack-matlab
  4. blueZero library (eg b0.dll), and do not forget blueZero library itself has a dependency (eg libzmq, boost_chrono, boost_system, boost_thread, etc.).

Check the programming / remoteApiBindings / b0Based / matlab / simpleTest.m program, as well as the corresponding scene B0-based presentation of RemoteApiDemo.ttt, for more details.

Server

Based on the Lua scripting API-based remote server for B0: lua / b0RemoteApiServer.lua. The script makes extensive use of BlueZero interface and functions have been used in custom scripts Models / tools / B0 remote Api server.ttm model and the additional script simAddOnScript-b0RemoteApiServer.lua in. If you miss a particular feature, you can implement it in their own remote API framework.

To the server side (ie CoppeliaSim end) Enable Remote API B0, make sure that loaded successfully (simExtBlueZero.dll, libsimExtBlueZero.dylib or libsimExtBlueZero.so) when BlueZero plug-in has started in CoppeliaSim (you can check the console window to get For information on plug-in loaded.)

Finally, there are two ways B0-based remote API:

  1. Additional startup script simAddOnScript-b0RemoteApiServer.lua: You can in the menu bar [Add-ons --> b0RemoteApiServer] Starting it manually, it can also be started automatically when CoppeliaSim start (in this case, an additional component rename simAddOnScript_b0RemoteApiServer.lua). Provides additional script-based remote API function B0, and without interruption for all scenarios.
  2. Model Models / tools / B0 remote Api server.ttm Drop particular scenario: In this way, based on the API function remote B0 will only be applicable to the particular scene
Released three original articles · won praise 0 · Views 80

Guess you like

Origin blog.csdn.net/qq_29696095/article/details/104466293