ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

Hey, we support both ROS and LabVIEW on our mobile products, so it's been occasionally convenient to have the two chat to each other. We've adopted an approach pretty similar to what lifesayko and Eric Perko are doing. In Python, though, packing up a message that LabVIEW's "Unflatten From String" block will recognize is really easy. This is really all there is to it:

class LabviewProxy:
    def __init__(self):
        rospy.init_node('labview_proxy')

        self.ip = rospy.get_param('~ip', '')
        self.port = rospy.get_param('~port', 12345)
        self.sock = socket.socket(socket.AF_INET,
                              socket.SOCK_DGRAM)

        rospy.Subscriber("cmd_vel", Twist, self.cmd_vel_handler)
        rospy.spin()

  def cmd_vel_handler(self, data):
        msg = struct.pack('!dd', data.linear.x, data.angular.z)
        self.sock.sendto(msg, (self.ip, self.port))

You can find the syntax for Python's struct.pack and struct.unpack format strings in the official documentation. From there, it's relatively simple to put together the reverse: listening on a socket and publishing messages from LabVIEW out to ROS.

In the longer run, it would be helpful to have support for the ROS messaging stack in LabVIEW itself (VIs generated from message definitions, etc), but this is a sufficient stopgap in the short term.