Ejemplo n.º 1
0
 def __init__(self,nodeName='b0RemoteApi_pythonClient',channelName='b0RemoteApi',inactivityToleranceInSec=60,setupSubscribersAsynchronously=False):
     self._channelName=channelName
     self._serviceCallTopic=channelName+'SerX'
     self._defaultPublisherTopic=channelName+'SubX'
     self._defaultSubscriberTopic=channelName+'PubX'
     self._nextDefaultSubscriberHandle=2
     self._nextDedicatedPublisherHandle=500
     self._nextDedicatedSubscriberHandle=1000
     b0.init()
     self._node=b0.Node(nodeName)
     self._clientId=''.join(random.choice(string.ascii_uppercase+string.ascii_lowercase+string.digits) for _ in range(10))
     self._serviceClient=b0.ServiceClient(self._node,self._serviceCallTopic)
     self._serviceClient.set_option(3,1000) #read timeout of 1000ms
     self._defaultPublisher=b0.Publisher(self._node,self._defaultPublisherTopic)
     self._defaultSubscriber=b0.Subscriber(self._node,self._defaultSubscriberTopic,None) # we will poll the socket
     print('\n  Running B0 Remote API client with channel name ['+channelName+']')
     print('  make sure that: 1) the B0 resolver is running')
     print('                  2) V-REP is running the B0 Remote API server with the same channel name')
     print('  Initializing...\n')
     self._node.init()
     self._handleFunction('inactivityTolerance',[inactivityToleranceInSec],self._serviceCallTopic)
     print('\n  Connected!\n')
     self._allSubscribers={}
     self._allDedicatedPublishers={}
     self._setupSubscribersAsynchronously=setupSubscribersAsynchronously
Ejemplo n.º 2
0
 def simxCreatePublisher(self,dropMessages=False):
     topic=self._channelName+'Sub'+str(self._nextDedicatedPublisherHandle)+self._clientId
     self._nextDedicatedPublisherHandle=self._nextDedicatedPublisherHandle+1
     pub=b0.Publisher(self._node,topic,0,1)
     pub.init()
     self._allDedicatedPublishers[topic]=pub
     self._handleFunction('createSubscriber',[topic,dropMessages],self._serviceCallTopic)
     return topic
Ejemplo n.º 3
0
    def __init__(self,
                 nodeName=None,
                 channelName=None,
                 inactivityToleranceInSec=60,
                 setupSubscribersAsynchronously=False,
                 timeout=3):

        if nodeName == None:
            nodeName = 'b0RemoteApi_pythonClient' + str(threading.get_ident())
        if channelName == None:
            channelName = 'b0RemoteApiAddOn'

        self._channelName = channelName
        self._serviceCallTopic = channelName + 'SerX'
        self._defaultPublisherTopic = channelName + 'SubX'
        self._defaultSubscriberTopic = channelName + 'PubX'
        self._nextDefaultSubscriberHandle = 2
        self._nextDedicatedPublisherHandle = 500
        # print(f'(nodeName:{{{nodeName}}} channelName:{{{channelName}}})')
        self._nextDedicatedSubscriberHandle = 1000
        # print('Calling b0.init()')
        b0.init()
        # print('Calling b0.Node(nodeName)')
        self._node = b0.Node(nodeName)
        self._clientId = ''.join(
            random.choice(string.ascii_uppercase + string.ascii_lowercase +
                          string.digits) for _ in range(10))
        self._serviceClient = b0.ServiceClient(self._node,
                                               self._serviceCallTopic)
        self._serviceClient.set_option(3, timeout * 1000)  #read timeout
        self._defaultPublisher = b0.Publisher(self._node,
                                              self._defaultPublisherTopic)
        self._defaultSubscriber = b0.Subscriber(
            self._node, self._defaultSubscriberTopic,
            None)  # we will poll the socket
        # print('\n  Running B0 Remote API client with channel name ['+channelName+']')
        # print('  make sure that: 1) the B0 resolver is running')
        # print('                  2) CoppeliaSim is running the B0 Remote API server with the same channel name')
        # print('  Initializing...\n')
        self._node.init()
        self._handleFunction('inactivityTolerance', [inactivityToleranceInSec],
                             self._serviceCallTopic)
        # print('\n  Connected!\n')
        self._allSubscribers = {}
        self._allDedicatedPublishers = {}
        self._setupSubscribersAsynchronously = setupSubscribersAsynchronously
Ejemplo n.º 4
0
#coding:utf-8
import b0
import pyrealsense2 as rs
import numpy as np
import time

pc = rs.pointcloud()
points = rs.points()
pipe = rs.pipeline()
pipe.start()

node = b0.Node('pointcloud-pub')
pub = b0.Publisher(node, 'pc')
node.init()
print('Publishing to topic "%s"...' % pub.get_topic_name())

try:
    while not node.shutdown_requested():
        frames = pipe.wait_for_frames()

        depth = frames.get_depth_frame()
        # color = frames.get_color_frame()
        # pc.map_to(color)

        points = pc.calculate(depth)

        pts = [pt for pt in np.asanyarray(points.get_vertices()) if any(pt)]
        pub.publish(np.array(pts).tobytes())
        # time.sleep(0.1)
        # print("sending point cloud")
Ejemplo n.º 5
0
# -*- coding: utf-8 -*-
import b0
import time

if not b0.is_initialized():
    b0.init()
node = b0.Node('python-publisher')
pub = b0.Publisher(node, 'A')
node.init()
print('Publishing to topic "%s"...' % pub.get_topic_name())
i = 0
while not node.shutdown_requested():
    msg_str = u'µsg-%d' % i
    i += 1
    print('Sending message "%s"...' % msg_str)
    msg = msg_str.encode('utf-8')
    pub.publish(msg)
    node.spin_once()
    time.sleep(1)
node.cleanup()
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
import b0
import numpy as np
import cv2
import time

cam = cv2.VideoCapture(0)

node = b0.Node('python-camera-node')
camera_pub = b0.Publisher(node, 'camera')
node.init()

while not node.shutdown_requested():
    ret_val, img = cam.read()
    img = cv2.flip(img, 1)
    ok, arr = cv2.imencode('.jpg', img)
    if ok:
        msg = arr.tostring()
        print('Sending message %d' % len(msg))
        camera_pub.publish(msg)
    node.spin_once()
    time.sleep(0.1)

node.cleanup()

cv2.destroyAllWindows()