Пример #1
0
    def __init__(self, node_name, port):
        """Create the NetNode object. Registers the methods in
        this NetNode instance as callbacks for the CmdListener
        object. This is an 'inversion of control' in some respects.
        Params:
            node_name - The name of the ROS node.
            port      - The port to send/receive commands on
        """
        #Create network communication object
        self.listener = CmdListener('', port)

        #Add listeners
        self.listener.add_connect_listener(self.on_connect)
        self.listener.add_data_listener(self.on_data)
        self.listener.add_dc_listener(self.on_dc)

        self.node_name = node_name

        #Create publishers/service proxies for communicating with the
        #control node.
        self.get_inputs_srv = rospy.ServiceProxy(
            '/oark_control_node/get_inputs', GetInputs)
        self._command_pub = rospy.Publisher('/oark_control_node/command',
                                            Command,
                                            latch=True,
                                            queue_size=10)

        self.disconnected_srv = rospy.ServiceProxy(
            '/oark_control_node/disconnected', Empty)
        self.connected_srv = rospy.ServiceProxy('/oark_control_node/connected',
                                                Connected)
Пример #2
0
    def __init__(self, node_name, port):
        """Create the NetNode object. Registers the methods in
        this NetNode instance as callbacks for the CmdListener
        object. This is an 'inversion of control' in some respects.
        Params:
            node_name - The name of the ROS node.
            port      - The port to send/receive commands on
        """
        #Create network communication object
        self.listener = CmdListener('', port)

        #Add listeners
        self.listener.add_connect_listener(self.on_connect)
        self.listener.add_data_listener(self.on_data)
        self.listener.add_dc_listener(self.on_dc)

        self.node_name = node_name

        #Create publishers/service proxies for communicating with the
        #control node.
        self.get_inputs_srv = rospy.ServiceProxy('/oark_control_node/get_inputs',
                                                 GetInputs)
        self._command_pub = rospy.Publisher('/oark_control_node/command',
                                            Command,
                                            latch=True,
                                            queue_size=10)

        self.disconnected_srv = rospy.ServiceProxy('/oark_control_node/disconnected',
                                                   Empty)
        self.connected_srv = rospy.ServiceProxy('/oark_control_node/connected',
                                                Connected)
Пример #3
0
class NetNode(object):
    """A network node. Creates methods used as callbacks from
    CmdListener. CmdListener will receive network messages
    and send them to this node. This node will then process them
    and send them on to the control node.
    """

    def __init__(self, node_name, port):
        """Create the NetNode object. Registers the methods in
        this NetNode instance as callbacks for the CmdListener
        object. This is an 'inversion of control' in some respects.
        Params:
            node_name - The name of the ROS node.
            port      - The port to send/receive commands on
        """
        #Create network communication object
        self.listener = CmdListener('', port)

        #Add listeners
        self.listener.add_connect_listener(self.on_connect)
        self.listener.add_data_listener(self.on_data)
        self.listener.add_dc_listener(self.on_dc)

        self.node_name = node_name

        #Create publishers/service proxies for communicating with the
        #control node.
        self.get_inputs_srv = rospy.ServiceProxy('/oark_control_node/get_inputs',
                                                 GetInputs)
        self._command_pub = rospy.Publisher('/oark_control_node/command',
                                            Command,
                                            latch=True,
                                            queue_size=10)

        self.disconnected_srv = rospy.ServiceProxy('/oark_control_node/disconnected',
                                                   Empty)
        self.connected_srv = rospy.ServiceProxy('/oark_control_node/connected',
                                                Connected)


    def on_connect(self, addr):
        """Called when a connection is received. Will start the video
        stream if available
        Params:
            addr - The IP address of the connected device.
        """
        rospy.loginfo('Connected to ' + str(addr))

        #The first member of the addr tuple is the IP address
        self.connected_srv(str(addr[0]))


    def on_data(self, msg_type, msg):
        """Receives a message from the caller, turns it into the appropriate
        ROS message and then forwards it to another function to handle the message.
        This method is assumed to be called in a separate thread and so
        is allowed to block if necessary.
        Params:
            msg_type - An integer identifier of the message. All network
                       messages have a message type. The mapping for this
                       can be found in net_consts.
            msg      - A serialized string containing the message data.
        """
        rospy.loginfo('Got data')

        #Deserialise msg
        ros_msg = net_consts.MSGS[msg_type]()
        ros_msg.deserialize(msg)

        try:
            #Send message to its own handler function
            msg_name = net_consts.MSGS[msg_type].__name__

            print 'Received message ', msg_name, ' of type ', msg_type

            msg_func = getattr(self, 'on_' + msg_name.lower())
            msg_func(ros_msg)
        except KeyError, ke:
            rospy.logwarn(msg_type, ' is not a valid message type')
        except AttributeError, ae:
            rospy.logwarn('No function to handle ROS msg <' + msg_name + '>')
Пример #4
0
class NetNode(object):
    """A network node. Creates methods used as callbacks from
    CmdListener. CmdListener will receive network messages
    and send them to this node. This node will then process them
    and send them on to the control node.
    """
    def __init__(self, node_name, port):
        """Create the NetNode object. Registers the methods in
        this NetNode instance as callbacks for the CmdListener
        object. This is an 'inversion of control' in some respects.
        Params:
            node_name - The name of the ROS node.
            port      - The port to send/receive commands on
        """
        #Create network communication object
        self.listener = CmdListener('', port)

        #Add listeners
        self.listener.add_connect_listener(self.on_connect)
        self.listener.add_data_listener(self.on_data)
        self.listener.add_dc_listener(self.on_dc)

        self.node_name = node_name

        #Create publishers/service proxies for communicating with the
        #control node.
        self.get_inputs_srv = rospy.ServiceProxy(
            '/oark_control_node/get_inputs', GetInputs)
        self._command_pub = rospy.Publisher('/oark_control_node/command',
                                            Command,
                                            latch=True,
                                            queue_size=10)

        self.disconnected_srv = rospy.ServiceProxy(
            '/oark_control_node/disconnected', Empty)
        self.connected_srv = rospy.ServiceProxy('/oark_control_node/connected',
                                                Connected)

    def on_connect(self, addr):
        """Called when a connection is received. Will start the video
        stream if available
        Params:
            addr - The IP address of the connected device.
        """
        rospy.loginfo('Connected to ' + str(addr))

        #The first member of the addr tuple is the IP address
        self.connected_srv(str(addr[0]))

    def on_data(self, msg_type, msg):
        """Receives a message from the caller, turns it into the appropriate
        ROS message and then forwards it to another function to handle the message.
        This method is assumed to be called in a separate thread and so
        is allowed to block if necessary.
        Params:
            msg_type - An integer identifier of the message. All network
                       messages have a message type. The mapping for this
                       can be found in net_consts.
            msg      - A serialized string containing the message data.
        """
        rospy.loginfo('Got data')

        #Deserialise msg
        ros_msg = net_consts.MSGS[msg_type]()
        ros_msg.deserialize(msg)

        try:
            #Send message to its own handler function
            msg_name = net_consts.MSGS[msg_type].__name__

            print 'Received message ', msg_name, ' of type ', msg_type

            msg_func = getattr(self, 'on_' + msg_name.lower())
            msg_func(ros_msg)
        except KeyError, ke:
            rospy.logwarn(msg_type, ' is not a valid message type')
        except AttributeError, ae:
            rospy.logwarn('No function to handle ROS msg <' + msg_name + '>')