forked from Pythocrates/rozmo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zmq_bridge.py
executable file
·49 lines (32 loc) · 1.06 KB
/
zmq_bridge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/env python
#-*- coding: utf-8 -*-
'''
This is a simple example how to translate ROS messages into ZeroMQ messages.
'''
import random
import sys
import time
import zmq
import rospy
from std_msgs.msg import String
PORT = 5556
class ZMQBridge(object):
def __init__(self, *args , **kwargs):
super(ZMQBridge, self).__init__(*args, **kwargs)
rospy.init_node('zmq_bridge')
self.__create_ros_communication()
self.__create_zmq_communication()
def __create_ros_communication(self):
self.__word_sub = rospy.Subscriber('/word', String, self.receive_ros_word)
def __create_zmq_communication(self):
context = zmq.Context()
self.__word_socket = context.socket(zmq.PUB)
self.__word_socket.bind('tcp://*:{p}'.format(p=PORT))
def publish_zmq_word(self, word):
print('Publishing')
self.__word_socket.send(word)
def receive_ros_word(self, word):
self.publish_zmq_word(word.data)
if __name__ == '__main__':
zmq_bridge = ZMQBridge()
rospy.spin()