Part I: Copyliasim simulation diary (III): linkage between copyliasim and python -- the B0 based remote API
When we conduct group robot simulation, we often need to simulate dozens or hundreds of robots. Due to the limited computer resources of a single computer, we often need to conduct joint parallel simulation of multiple computers. This section will explain the specific operation steps.
Specific steps:
First, connect the computers for parallel simulation to the same LAN. Here, I use a router to connect the LAN. After the connection, select one of them as the main computer connected to the simulation software to check its intranet ip. See the specific steps in detail https://jingyan.baidu.com/article/00a07f38f8e483c2d128dc3c.html
The intranet ip of this host computer is shown in the figure:
Then we add an environment variable B0 to this computer_ RESOLVER_ Port, set a port number:
Finally, add another environment variable B0 to other computers_ Resolver so that other computers can connect to the software through LAN:
Relevant codes of the host computer (the computer that opens the software) (generally only controls the operation and end of the simulation):
import b0RemoteApi import time with b0RemoteApi.RemoteApiClient('Scene', 'b0RemoteApi') as client: client.doNextStep = True def simulationStepStarted(msg): simTime = msg[1][b'simulationTime'] def simulationStepDone(msg): simTime = msg[1][b'simulationTime'] client.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 + 1000: if client.doNextStep: client.doNextStep = False client.simxSynchronousTrigger() client.simxSpinOnce() client.simxStopSimulation(client.simxDefaultPublisher())
Other computer related codes (generally only including the control code of the robot):
import b0RemoteApi import time with b0RemoteApi.RemoteApiClient('uav', ' b0RemoteApi') as client: client.doNextStep = True def simulationStepStarted(msg): simTime = msg[1][b'simulationTime'] def simulationStepDone(msg): simTime = msg[1][b'simulationTime'] client.doNextStep = True client.simxSynchronous(True) client.simxGetSimulationStepStarted(client.simxDefaultSubscriber(simulationStepStarted)) client.simxGetSimulationStepDone(client.simxDefaultSubscriber(simulationStepDone)) startTime = time.time() while time.time() < startTime + 150: # Simulation time setting if client.doNextStep: client.doNextStep = False '''Control code''' client.simxSynchronousTrigger() client.simxSpinOnce()
Finally, open b0resolver and simulation software on the host computer, then run the program on the host computer, and then other computers can run their own programs to connect to the simulation software on the host computer and execute the control operation of the robot.
last
This method also bothered me for a long time. Finally, it was solved only after someone answered on the forum. I hope you can consult the user manual and the forum more if you have questions.