ROS for LabVIEW

ROS for LabVIEW is a set of LabVIEW VIs that enables two-way communication between ROS and LabVIEW on different machines. It allows the user to initialize nodes, publish and subscribe to various types of topics, and create a ROS Master within in LabVIEW.

This demonstration shows how to install the addon to your LabVIEW library, configure your network properly, as well as how to interact with a Clearpath Husky from LabVIEW. Note that these instructions were made for LabVIEW 2014 running on Windows 10, and ROS Indigo running on Ubuntu Trusty (14.04). Slight variations may apply for different operating systems.

Installing ROS for LabVIEW

Installing from LabVIEW Package Manager

Open labVIEW and follow the these steps:

  1. Open the Package Manager inside LabVIEW by clicking Tools -> VI Package Manager
  2. Scroll down to ROS for LabVIEW Software, rick click and select Install,
  3. Accept license agreements and install

By default, the contents of this package will install into your LabVIEW directory under:

\LabVIEW 2014\vi.lib\Tufts CEEO ROS for LabVIEW Software

Installing from Source

Quit LabVIEW and follow the these steps:

  1. Go to the ROS for LabVIEW Github repository

  2. Select Clone or download -> Download ZIP in top right

  3. Unzip folder, and open subfolder ROS-forLabVIEW-Software-master

  4. Copy the folder ROS for LabVIEW Software to user.lib in your LabVIEW directory

    In Windows:

    C:\Program Files\National Instruments\LabVIEW 2014\user.lib
    

    On MAC:

    Applications:National Instruments:LabVIEW 2014:user.lib
    

Using ROS for LabVIEW VIs

The libraries that you just installed can now be used by inserting the blocks into you project VI.

If you installed the addon using the Package Manager, right click on your project VI Block Diagram, navigate to Addons and select ROS for LabVIEW icon as shown below:

_images/UsingRL1.png

If you installed the library from source, right click on your project VI Block Diagram, navigate to User Libraries and select ROS for LabVIEW icon as shown below:

_images/UsingRL2.png

There are various VIs that can now be inserted into your project. Some of available VIs are shown in the figure below. A few of the most useful VIs include the ROS Topic Initiate/Read/Write/Repeat/Close. There are also message parsing and message building VIs which allow you to build messages that can be read by ROS as well as parse message coming from ROS into formats that can be read by LabVIEW. These VIs are built for common ROS message types such as std_msgs, geometry_msgs sensor_msgs and nav_msgs. However, you may have to create your own. This will be discussed in more detail later in this tutorial.

_images/UsingRL2.png

Other VIs enabling the user to communicate with various devices such as a Baxter, ROSRIO, NAO and Turtlebot are also available. For an example of using the Baxter VIs, refer to NI’s case study.

This tutorial assumes that you have ROS installed and configured properly. See the ROS 101: A Practical Example above, or refer to http://wiki.ros.org/ROS/Tutorials

Configure Network

Assuming you have LabVIEW installed on one MAC or PC machine (we will call it the LabVIEW computer) and ROS installed on another Linux machine (we will call it the ROS computer). Note that this tutorial has not been tested with ROS installed on a Windows or Mac operating system, nor has it been tested using a virtual machine. We recommend installing ROS on a computer with Ubuntu.

The first step is to make sure both the LabVIEW computer and the ROS computer can communicate with each other. You will need to connect both computers to the same network (via Wi-Fi or Ethernet cable). There are two ways to configure your network to ensure that you will always have two-way communication between the two computers. This can be done using DHCP reservation or using hostfiles.

We recommend using DHCP reservation to ensure that the IP address for each computer stays the same every time you connect to your network. It is also easier if you have many devices trying to communicate to each other since you do not need to constantly check and update the host file for each computer.

Determine Current Network Parameters

  1. Connect all computers to your network

  2. Run the IP configuration command on each computer:

    For Windows, open command prompt and enter:

    ipconfig /all
    

    Locate and write down the Host Name, as well as the Physical Address (Or MAC) and the IP Address for the adapter in use (i.e. use wireless adapter if connected wirelessly or ethernet adapter if connected via ethernet).

    _images/ConfigNetwork1.png

    For Ubuntu, open terminal and enter:

    ifconfig -a
    

    Locate and write down the HWaddr (or physical/MAC address), the inet addr (IP address) as well as the hostname which will be shown on your command line. You can also locate and/or edit the hostname by entering:

    sudo gedit /etc/hosts
    
    _images/ConfigNetwork2.png

Using DHCP Reservation

This section will differ for each type of router that is being used, but the general steps are the following:

  1. Log onto your router webpage (you will need the admin username and password for the router)
  2. Find connected clients, or DHCP Reservation in the network settings
  3. For each device (i.e. LabVIEW and ROS computer) add a new reservation and enter the MAC address, IP address, and hostname that was determined in the above section.

You can also assign other IP addresses instead of the ones initially assigned.

Using Host Files

If you would prefer not to change your network settings (or are unable to do so), you can store hostnames and their associated IP addresses by editing the respective host files for each computer.

For Windows, enter:

notepad C:\windows\system32\drivers\etc\hosts

For Ubuntu, enter:

sudo gedit /etc/hosts

Add the hostname and IP address for each computer that was determined above. Note that you will need to add all hostname/IP pairs to the host files on all computers. This will need to be checked every time you reconnect your devices to the network as the IP addresses may change.

Check for Two-way Communication

We need to confirm that each computer can now talk to each other on the network. Assuming the IP for the ROS computer is 192.168.0.155 with hostname ClearpathNC, and the IP for the LabVIEW computer is 192.168.0.120 with hostname SDIC-PC1.

First open up a terminal and ping the ROS computer from the ROS computer:

ping 192.168.0.155

Similarly with the LabVIEW computer, open up the command prompt and enter:

ping 192.168.0.120

In both cases, you should receive replies from the same IP address. You should also be able to ping using the hostname.

Now, ping the LabVIEW computer from the ROS computer:

ping 192.168.0.120

Similarly, ping the ROS computer from the LabVIEW computer:

ping 192.168.0.155

If this fails, then the computers cannot see each other on the network. You will need to reconfigure your network or hosts files. For more information and some additional troubleshooting methods, see ROS tutorials on Network Setup.

One common issue that blocks the two way communication is the Windows firewall. If you cannot ping your Windows computer from your Ubuntu computer, try creating a firewall rule. If your computers can ping each other, you can skip the next section.

Creating a Windows Firewall Rule

If you are using Windows on your LabVIEW computer, you will probably need to create a firewall rule. Follow these steps and then retry to ping the computers:

  1. Open Control Panel -> System and Security -> Windows Firewall -> Advanced Settings

  2. Rick click on Inbound Rules and select New Rule..

  3. Assign the following properties to the new rule:

    • Select Custom Rule under Rule Type
    • Apply to All Programs under Program
    • Select ICMPv4 for Protocol type under Protocol and Ports
    • Apply to Any IP address for local and remote IP addresses under Scope
    • Selecty Allow the connection under Actions
    • Check off Domain, Private and Public under Profile
    • Assign a name such as “ICMPv4 Rule for ROS communication” and select Finish

Note: you may also have to do the same thing with an Outbound Rule.

Drive a Husky with LabVIEW

We are now ready to start building our code in LabVIEW and communicating with ROS. In this section, we will learn how to create a VI in LabVIEW to drive a Husky in simulation on another device. To do this, we will need to start a ROS Master on the ROS computer, then initialize a node in LabVIEW which will publish velocity commands that can be subscribed to by any device connected to the ROS Master.

First, let’s launch a Husky in Gazebo that will subscribe to the velocity commands from LabVIEW. You will need to install husky desktop and husky simulator, refer to ROS 101:Drive a Husky tutorial for instructions. Once these have been installed on your ROS computer, open a new terminal and enter:

roslaunch husky_gazebo husky_empty_world.launch

This should launch Gazebo with a Husky in the middle of an empty world as shown below:

_images/DriveAHusky1.png

Now let’s open rqt graph to visualise all the current nodes and topics, in a new terminal:

rqt_graph
_images/DriveAHusky2.png

You should see something like the photo above. To drive the Husky, we want to publish to the /husky_velocity_controller/cmd_vel topic. You can also publish to /cmd_vel instead, however if you have multiple devices that are controlled by cmd_vel commands (e.g. turtlebot or turtlesim), then this may cause issues. Now we know the topic we need to publish to in LabVIEW, so all we need now is to find the type of messages that we need to send to that topic. In a new terminal on your ROS computer, enter:

rostopic info /cmd_vel

You can also enter rostopic info /husky_velocity_controller/cmd_vel which will give the same result. This will show you that those topics require messages of type geometry_msgs/Twist. Now let’s create this in LabVIEW!

On your LabVIEW computer, open a blank LabVIEW project and then add a new VI. On the block diagram (BD) of this new VI, rick click and navigate to your ROS for LabVIEW library. This will be under Addons if you installed the library via the Package Manager, or User Libraries if you installed from source.

Under ROS, drag and drop the following VIs onto your BD as shown:

  • ROS_Topic_Init
  • ROS_Topic_Write
  • ROS_Topic_Close
_images/DriveAHusky3.png

These three VIs are essential for most programs that will publish to ROS. ROS_Topic_Init initiates a node in ROS, and defines the node name, the topic to publish/subscribe to, the type of messages, the queue size and the update rate. The ROS_Topic_Write is the VI that actually publishes the messages that are being created in your project VI. The ROS_Topic_Close kills the node. It is important to kill the node every time you are done running your VI. Otherwise, if you stop and restart your VI without killing your node, or restart your ROS Master, the node may not be re-initialized properly.

Next, let’s define the node name and properties:

  • Right click on the node terminal for the ROS_Topic_Init block, select Create -> Constant and name it /LVHuskyControl
  • Repeat for the ROS_Topic_Close block
  • Right click on the Definitions terminal and select Create -> Constant
  • Fill in the definitions as shown below
_images/DriveAHusky4.png

The top element in the Definitions Constant is the topic we want to publish to and the second is the type of messages to publish as we previously determined.

Next, go to the ROS for LabVIEW library and add a Twist message block to the left of our ROS_Topic_Write block. This can be found under ROS -> MessageBuilder -> geometry_msgs -> add_Twist. Right click on the Twist terminal and create a Control. We can now connect all our VI blocks. Connect the following terminals:

  • ROS_Topic_Init ROS out -> ROS_Topic_Write ROS in
  • add_twist msg_out -> ROS_Topic_Write msg_in
  • ROS_Topic_Write ROS out -> ROS_Topic_Close ROS in
  • ROS_Topic_Init Error out -> ROS_Topic_Write Error in
  • ROS_Topic_Write Error out -> ROS_Topic_Close ROS in
  • ROS_Topic_Close Error out -> Indicator

Now let’s create a while loop to continuously run the ROS_Topic_Write and add_Twist VIs. This will continually publish our messages. Your code should look similar to this (After cleaning up the wires):

_images/DriveAHusky5.png

Finally, let’s map the stop icon on the while loop to a control and add a case structure inside the while loop with a start/stop control. You can also add an indicator to your ROS_Topic_Write output to visualise the messages that are being published. After some visual reconfiguration, your final code should similar to this:

_images/DriveAHusky6.png

We are now ready to drive the Husky with LabVIEW! Add velocity commands, hit run, LabVIEW will ask you to input the Master’s (ROS computer) IP address, and then watch the Husky move in your simulation.

If you open and refresh your rqt graph on your LabVIEW computer, you should see a node named n_LVHuskyControl which is publishing to /husky_velocity_controller/cmd_vel as expected.

Important notes:

  • The stop/start publishing control will be important when you are controlling a real Husky. it is recommended that you one change the velocity commands while the boolean is set to off. This will allow for easier control.
  • Only the Linear x and Angular z can be altered to drive the Husky. This is because the Husky can only move in the x direction (forward/backward) and rotate about the z axis.
  • It is important to ALWAYS end the script by pressing the STOP button on the Front Panel. Do not press the “Abort Execution” button at the top toolbar. You need to exit the while loop to close the node or you will have issues (which can be fixed by restarting your project).
  • You can set your Master’s IP address ahead of time so you don’t have to keep inputting it when you run the code. To do this, search for _ROSDefinition VI, change ROS Master IP and select Make Current Values Default in the edit tab.

The next sections will show you how to download and install Clearpath’s custom VIs which illustrate how to subscribe to Husky odometry data and laser scan data, and how to plot these measurements in LabVIEW.

Download and Install Clearpath VIs

Go to the ROSforLabVIEW-Clearpath Github repository. Clone or download the zip and save the contents to your project directory. If you want the Clearpath VIs to be available as blocks within your BD, you can save the extracted VIs to your user.lib directory and then the blocks will be accessible by rick clicking in your BD and going to User LIbraries.

The project controlHusky.lvproj should contain three VIs and two subVIs. The Velocity Publisher VI is the same code we produced in the last section. OdometrySubscriber.vi subscribes to the EKF Localized odometry from Gazebo (or your Husky robot), displays the pose (position and orientation) and plots the xy position. OdomLaserSubscriber.vi also subscribes to the laser scans and plots this xy data. parseLaserScan.vi and parseOdometry.vi will be discussed in the next section.

Track a Husky and Plot Lidar Scans

This section will discuss how the OdomLaserSubcriber.vi works and how to use it. Before you open the subscriber VI, let’s open a new Gazebo simulation but this time we will choose a world that has some obstacles in it for the laser to detect. End your current Gazebo simulation and enter the following command into the terminal:

roslaunch husky_gazebo husky_playpen.launch

Now open the OdomLaserSubscriber VI as well as the VelocityPublisher VI. This way we will control the Husky while subscribing to the odometry and laser scans all within LabVIEW. In the front panel of the subscriber, set the Update Time to 300ms and the Max Odom Pts to 500. This will help make sure the subscriber has enough time to keep up with the incoming messages and that you do not run out of memory within LabVIEW. You can then press run on the subscriber, and then run the VelocityPublisher with some velocity command inputs.

The following figure shows the code for the OdomLaserSubscriber as well as the output when the Husky is moving around.

_images/TrackPlotLidar1.png

Let’s look at the code in more detail. In this code, we initiate the node similar to our VelocityPublisher, but we select Subscriber within the topic definition. In this case, we initiate two nodes including one node to retrieve the odometry data (/odometry/filtered topic) and one node to retrieve the laser scan data (/scan topic). We also use ROS_Topic_Read instead of ROS_Topic_Write.

The top case structure allows the user to clear the plot by deleting the array when true. The 2D pose is outputted from the parseOdometry subVI as a cluster with doubles x and y. Pose is then appended to previous pose cluster from the last iterations of the loop and then plotted. The pose cluster will continue to grow as long as the while loop is running until the user clears the graph or until it reaches the maximum number of odometry points specified in the front panel.

_images/TrackPlotLidar2.png

The paseLaserScan subVI outputs a range array and bearing array of size 1 x n where n is the number of beams that your specific laser is publishing. The range and bearing are then turned into x and y position of the light pulse in the Husky’s coordinate frame. This data can then be bundled and plotted.

_images/TrackPlotLidar3.png

Message Building and Parsing

When you want to publish or subscribe to specific types of messages which are not already included in the ROS for LabVIEW library, you will need to write your own message builder and parser. The messages are transferred from ROS to LabVIEW by first flattening the data into a string and then it needs to be parsed into a usable format. Similarly, when you want to publish a specific type of message to ROS from LabVIEW which is not in the ROS for LabVIEW library, you have to build your own message to a format that is readable by the ROS node subscribing to that message. Tufts University has some tutorials in their Github library on message parsing and building.

The parseLaserScan.vi and parseOdometry.vi that are used in this project are good examples of how message parsing is done. These VIs are written specifically to parse the sensor_msgs/LaserScan and nav_msgs/Odometry message types for the /scan and /odometry/filtered topics that are published by the husky, respectively.

Note: If you are having memory problems when running your laser subscriber, you may want to consider reducing the size of your laser scan data. You can do this in parseLaserScan.vi by saving the range measurements to a different data type or by reducing the amount of beams you are saving.

Video Tutorial

The following video shows the above tutorial being implemented in simulation and on a real Husky robot:

Support

The ROSforLabVIEW add-on software was developed and is supported by Tufts University. Neither National Instruments nor Clearpath Robotics will provide technical support for the content of the addon, besides the VIs provided in this demo.

For technical support contact Tufts University at:
Phone: (617) 627-5888 Email: tuftsBaxter@gmail.com Community Group: https://decibel.ni.com/content/groups/ros-for-labview

Additional Information

For more information and additional demos, refer to:

For information on how to implement this on various NI RIO devices, refer to help directory in the Tufts University Github repository. You will need to follow the instructions carefully when deploying a source distribution. The ROSforLabVIEW library has been testing by Tufts University on the myRIO and roboRIO, and should work with other RIO devices.