Can't enable the B0-based Remote Api

Typically: "How do I... ", "How can I... " questions
Post Reply
Le gourmet
Posts: 2
Joined: 20 Dec 2019, 06:55

Can't enable the B0-based Remote Api

Post by Le gourmet »

Hi,

I'm trying to work on the B0-based Remote Api but i'm getting trouble enabling it when i try to run a script. I'm using Python 3.7 x64 on Win10 and V-REP PRO EDU 3.6.2 (rev0)

As shown in this page http://www.coppeliarobotics.com/helpFil ... ntSide.htm , I installed MessagePack and I put all the following files in my working directory, copying them from VRep's installation folder :
  • b0.py
  • b0RemoteApi.py
  • b0.dll
  • boost_date_time-vc141-mt-x64-1_70.dll
  • boost_filesystem-vc141-mt-x64-1_70.dll
  • boost_program_options-vc141-mt-x64-1_70.dll
  • boost_regex-vc141-mt-x64-1_70.dll
  • boost_serialization-vc141-mt-x64-1_70.dll
  • boost_thread-vc141-mt-x64-1_70.dll
  • libzmq-mt-4_3_2.dll
Then when i try to run the simple test.py with his corresponding demo scene B0-basedRemoteApiDemo.ttt i'm getting this error :

Code: Select all

 File "(working directory)\b0RemoteApi.py", line 6, in <module>
    import b0

  File "(working directory)\b0.py", line 18, in <module>
    libb0 = ct.CDLL(libb0_fullpath)

  File "(my python path)\lib\ctypes\__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)

OSError: [WinError 126] The specified module could not be found
I really don't know what i am doing wrong as i followed every steps of the tutorial. On the server side, after opening B0-basedRemoteApiDemo.ttt, I kept the b0_resolver.exe open and i started the add-on script for the b0 Remote Api Server
[Add-ons --> b0RemoteApiServer].

Any suggestions or recommendations ? I know i'm missing something but i don't know what.

Regards.

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

Re: Can't enable the B0-based Remote Api

Post by coppelia »

Hello,

are you sure that you have all elements in place?

You need to have the resolver running. Then, at the location of your python script, you need b0.dll, plus all of its dependencies:
  • boost_data_time-vc141-mt-x64-1_70.dll
  • boost_filesystem-vc141-mt-x64-1_70.dll
  • boost_program_options-vc141-mt-x64-1_70.dll
  • boost_regex-vc141-mt-x64-1_70.dll
  • boost_thread-vc141-mt-x64-1_70.dll
  • libzmq-mt-4_3_2.dll
  • lz4.dll
  • zlib1.dll
and of course you also need the following python files:
  • b0.py
  • b0RemoteApi.py
Cheers

Le gourmet
Posts: 2
Joined: 20 Dec 2019, 06:55

Re: Can't enable the B0-based Remote Api

Post by Le gourmet »

Hi again,

thank you for your answer and for giving me the 2 files that were missing :
  • lz4.dll
  • zlib1.dll
now it works well.

Thanks again !

anish
Posts: 22
Joined: 27 Jan 2020, 14:15

Re: Can't enable the B0-based Remote Api

Post by anish »

Hai,

I am having CoppeliaSim version 4.00.00 (rev 2) and trying to work with b0 based API. My OS - Ubuntu 16.04 LTS.

I am not able to locate any of these .dll files mentioned above, including b0.dll. But the python files were available at the location: 'CoppeliaSim_Edu_V4_0_0_Ubuntu16_04/programming/b0RemoteApiBindings'

Where should it be actually located and how should install these if in case they are missing?

Thanks in advance!

anish
Posts: 22
Joined: 27 Jan 2020, 14:15

Re: Can't enable the B0-based Remote Api

Post by anish »

Okay,

so I understood it was for windows system and for ubuntu, these are of the form libb0.so and then the following files were added to the working directory:-
  • libb0.so
  • libboost_filesystem.so and libboost_filesystem.so.1.58.0
  • libboost_program_options.so and libboost_program_options.so.1.58.0
  • libboost_regex.so and libboost_regex.so.1.58.0
  • libboost_serialization.so and libboost_serialization.so.1.58.0
  • libboost_system.so and libboost_system.so.1.58.0
  • libboost_thread.so and libboost_thread.so.1.58.0
  • libboost_timer.so and libboost_timer.so.1.58.0
  • libzmq.so.5 and libzmq.so.5.0.0
After this, 'import b0RemoteApi' worked fine, but the following error was displayed:

Code: Select all

  Running B0 Remote API client with channel name [b0RemoteApi]
  make sure that: 1) the B0 resolver is running
                  2) CoppeliaSim is running the B0 Remote API server with the same channel name
  Initializing...


  Connected!

*************************************************************************************
** Leaving... if this is unexpected, you might have to adjust the timeout argument **
*************************************************************************************
Traceback (most recent call last):

  File "<ipython-input-1-7573ba69160e>", line 1, in <module>
    runfile('/home/anish/anaconda_py3_copelia/synchronousImageTransmission.py', wdir='/home/anish/anaconda_py3_copelia')

  File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)

  File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 88, in execfile
    exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)

  File "/home/anish/anaconda_py3_copelia/synchronousImageTransmission.py", line 61, in <module>
    client.simxStopSimulation(client.simxDefaultPublisher())

  File "/home/anish/anaconda_py3_copelia/b0RemoteApi.py", line 49, in __exit__
    self.simxSpinOnce();

  File "/home/anish/anaconda_py3_copelia/b0RemoteApi.py", line 179, in simxSpinOnce
    self._handleReceivedMessage(readData)

  File "/home/anish/anaconda_py3_copelia/b0RemoteApi.py", line 63, in _handleReceivedMessage
    msg[0]=msg[0].decode('ascii')

AttributeError: 'str' object has no attribute 'decode'

Can you pls help me understand how to resolve this?

Note:
Scene - synchronousImageTransmissionViaRemoteApi.ttt
Pythonfile - synchronousImageTransmission.py (copied from b0RemoteApiBindings folder)

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

Re: Can't enable the B0-based Remote Api

Post by coppelia »

There is indeed a Python version (and MessagePack version) compatibility problem. A fix can be found here. Basically, in b0RemoteApi.py, replace occurences of msgpack.unpackb(xxx) with msgpack.unpackb(xxx,raw=True)

Cheers

anish
Posts: 22
Joined: 27 Jan 2020, 14:15

Re: Can't enable the B0-based Remote Api

Post by anish »

Hai,

It worked like a charm, Thank you!

I am now trying to control a quadcopter using the B0 Remote API. I did all my work in Python Remote API and now I am trying to shift to B0, due to some slowdowns in Python Remote API while streaming images using vision sesor.
But I am not understanding the general layout of B0 Remote API. Like how to implement a for loop to control, regarding datatypes of the returned result of a subscriber, modifying the result and publishing it etc.

Below is a simple code in Python remote API;

Code: Select all

import sim
import sys
import numpy as np
import time

sim.simxFinish(-1)

clientID=sim.simxStart('127.0.0.1',19999,True,True,5000,5)

if clientID!=-1:
    print ('Connected to remote API server')

else:
    print("Not connected to remote API server")
    sys.exit("Could not connect")


#getting object handles for quad control
err_code,target_handle = sim.simxGetObjectHandle(clientID,'Quadricopter_target',sim.simx_opmode_blocking)

    for i in range(60):
       #get pos & orientation
       err_code, target_orien_body = sim.simxGetObjectOrientation(clientID, target_handle, target_handle, sim.simx_opmode_blocking)
       err_code, target_pos_body = sim.simxGetObjectPosition(clientID, target_handle, target_handle, sim.simx_opmode_blocking)
       
       #modify pos & orientation     
       target_pos_body[0] = target_pos_body[0] + (0.018)
       target_orien_body[2] = target_orien_body[2] + 0.02618  
       
       #set pos & orient
       err_code = sim.simxSetObjectOrientation(clientID, target_handle, target_handle, target_orien_body, sim.simx_opmode_oneshot)
       err_code = sim.simxSetObjectPosition(clientID, target_handle, target_handle, target_pos_body, sim.simx_opmode_oneshot)
       time.sleep(0.05)
Below is an attempted B0 version(asynchronous) of the same:

Code: Select all

import b0RemoteApi
import time

with b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient','b0RemoteApi') as client:    
    def L_orienCallback(orien_msg):
        #modify orientation
        target_orien_body = np.array(list(orien_msg[1]), 
        target_orien_body[2] = target_orien_body[2] + 0.02618
        target_orien_body = bytes(target_orien_body)
        #set orientation
        client.simxSetObjectOrientation(target_handle, target_handle, target_orien_body, client.simxDefaultPublisher())
        
    def posCallback(pos_msg):
        #modify pos
        target_pos_body = list(pos_msg[1])
        target_pos_body[0] = target_pos_body[0] + (0.018)
        target_pos_body = bytes(target_pos_body)
        #set pos
        client.simxSetObjectPosition(target_handle, target_handle, target_pos_body, client.simxDefaultPublisher())
    
    def stepSimulation():
        client.simxSpinOnce()

    #getting object handles for quad control
    target_handle=client.simxGetObjectHandle('Quadricopter_target',client.simxServiceCall())   

    for i in range(60):
          #get position & orientation by subscribing
          client.simxGetObjectOrientation(target_handle, target_handle, client.simxDefaultSubscriber(L_orienCallback))
          client.simxGetObjectPosition(target_handle, target_handle, client.simxDefaultSubscriber(posCallback))
          #time.sleep(0.025) 
          
    client.simxStartSimulation(client.simxDefaultPublisher())
    
    startTime=time.time()
    while time.time()<startTime+5:
        stepSimulation()
        
    client.simxStopSimulation(client.simxDefaultPublisher())         
          
I am getting the error:
[22:55:44] B0 Remote API: error while calling function 'GetObjectOrientation': [string "CUSTOMIZATION SCRIPT b0RemoteApiServer"]:356: One of the function's argument type is not correct. (sim.getObjectOrientation)

[22:55:44] B0 Remote API: error while calling function 'GetObjectOrientation': [string "CUSTOMIZATION SCRIPT b0RemoteApiServer"]:356: One of the function's argument type is not correct. (sim.getObjectOrientation)

Could you please help in understanding this?

also, any example implementation in B0 Remote API + python would be greatly helpful. (synchronousImageTransmissionViaRemoteApi.ttt - this I already checked)

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

Re: Can't enable the B0-based Remote Api

Post by coppelia »

Code: Select all

client.simxSetObjectOrientation(target_handle, target_handle, target_orien_body, client.simxDefaultPublisher())
second argument doesn't make sense. Set it to -1 if you want to send the absolute orientation. And for the third argument, simply use [0,0,0.2]

Cheers

Post Reply