Can I sub a child script topic with remote B0 API?

Typically: "How do I... ", "How can I... " questions
Post Reply
Dusty
Posts: 5
Joined: 09 Jul 2018, 10:08

Can I sub a child script topic with remote B0 API?

Post by Dusty »

Hi, I am Mike. I have a question.
I am trying to write a communication between remote python script and child script. I use remote API bluezero B0. I see in child script, there is a plugin 'simb0.' , The API simb0.publisherPublish(), publish messages. Can I use remote API B0, client.Subscriber(self.node, topic, self.my_callback, 0, 1), to receive the messages from child script? I tried it, but failed. Thus, I want to know if it is possible communicating between child script and remote script with B0, using like 'pub' and 'sub'?

fferri
Posts: 1217
Joined: 09 Sep 2013, 19:28

Re: Can I sub a child script topic with remote B0 API?

Post by fferri »

You can create a pair of pub/sub sockets with BlueZero only, using the BlueZero plugin in V-REP, and the BlueZero python bindings in the external python script.

For the Lua script in V-REP you can use something like this (e.g. threaded script):

Code: Select all

pubNode=simB0.nodeCreate('pubNode')
pub=simB0.publisherCreate(pubNode,'topic1')
simB0.nodeInit(pubNode)
i=0
while sim.getSimulationState()~=sim.simulation_advancing_abouttostop do
    sim.addStatusbarMessage('pub is publishing...')
    msg=string.format('msg-%d', i)
    i=i+1
    simB0.publisherPublish(pub,msg)
    sim.wait(1)
    sim.switchThread()
end
simB0.nodeCleanup(pubNode)
simB0.publisherDestroy(pub)
simB0.nodeDestroy(pubNode)
In the external Python script, use something like this:

Code: Select all

import b0

def callback(msg):
    msg_str = msg.decode('utf-8')
    print('Received message "%s"' % msg_str)
node = b0.Node('python-subscriber')
sub = b0.Subscriber(node, 'topic1', callback)
node.init()
print('Subscribed to topic "%s"...' % sub.get_topic_name())
node.spin()
node.cleanup()

Dusty
Posts: 5
Joined: 09 Jul 2018, 10:08

Re: Can I sub a child script topic with remote B0 API?

Post by Dusty »

Cool!!! It works. Thanks for helping! I finally got the messages from child script!

Post Reply