(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Advanced Networking for Turtlebot

Description: Advanced methods for setting up networking on your turtlebot

Tutorial Level: ADVANCED

Background

The default networking setup on Ubuntu assumes that you are using the machine as a desktop or a laptop. Robots tend to have slightly different requirements; for example, you might want your robot to connect to a wireless network without having to log in, or you might just want it to be more stable than NetworkManager can achieve.

Be careful; this is a tutorial for advanced users who are comfortable with linux. Administration concepts are presented at a high level; it is assumed that you know about how to navigate the file system, change file ownership, edit system configuration files, and generally use the command line.

Disabling NetworkManager

If NetworkManager is installed and set to run with upstart (the default), it will try to manage your network interfaces. We can either

  • 1 Remove it:
    •  sudo apt-get purge network-manager network-manager-gnome 

    1 Disable it:
    • Edit /etc/init/network-manager.conf and add the line manual near the beginning of the file.

Clean up your interface names

Sometimes, the turtlebot installer gets confused about interface numbers; and you end up with interfaces eth1 and wlan1 instead of eth0 and wlan0 (or other oddities). Remove /etc/udev/rules.d/70-persistent-net.rules to reset the interface numbers for your machine.

Background

If you're interested in how it works, read man 5 interfaces, man 8 iwconfig and man 5 wpa_supplicant.conf. Otherwise, just follow the examples and enjoy.

Setting up wired network connections

Setting up a wired network connection is easy.

For each wired network device, (ex: eth0), add the following lines to /etc/networking/interfaces

auto eth0
iface eth0 inet dhcp

Setting up wireless

Wired connections are a little trickier; you'll need a few lines of configuration for each wireless network you want your robot to try to connect to.

Examples assume your wireless device is wlan0. If it has some other name, use that instead.

First, add these lines to /etc/networking/interfaces

auto wlan0
iface wlan0 inet manual
   wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

Create /etc/wpa_supplicant/wpa_supplicant.conf if it doesn't exist. It should be owned by root.

For each wireless network:

  • 1 Run wpa_passphrase <SSID> and enter the password for your wireless network 1 Append the output to /etc/wpa_supplicant/wpa_supplicant.conf 1 Add an id_str="<NAME>" line to this network declaration. It should turn out looking something like this:

    • network={
              ssid="Blue"
              #psk="asdf"
              psk=asdf
              id_str="blue"
              scan_ssid=1
      }

    1 Add a line to /etc/network/interfaces like iface <NAME> inet dhcp

The order that networks are listed will determine the order that wpa_supplicant tries to connect to them.

Testing

If you've made changes to your network configuration, you should run sudo service networking restart to pick them up.

You can use iwconfig to inspect which wireless network you're connected to, and ifconfig to see statistics about your network interfaces, including the IP address assigned (if you have one). ifconfig -a shows all intefaces, even if they aren't up. ifconfig <INTERFACE> shows only the configuration for a particular interface.

watch iwconfig is useful for watching the status of your wireless connection (or anything else, really). Ctrl-C to stop.

Fallback to AdHoc Networking

This is a trick I've employed successfully on my personal robot; it creates and manages an ad-hoc network if it can't find any know networks to connect to. This way, you can take your robot on a field trip and still be able to connect to it from a laptop.

Install dnsmasq:

sudo apt-get install dnsmasq

At the bottom of /etc/wpa_supplicant/wpa_supplicant.con, add:

network={
        id_str="adhoc"
        ssid="turtlebot"
        mode=1
        frequency=2412
        key_mgmt=NONE
}

You can change the SSID and frequency as you see fit; note that the frequency is specified in MHz and should be one of the legal 802.11 bands in your region. If you want to set a password, read man 5 wpa_supplicant.conf for how to set key_mgmt, and use wpa_passphrase to generate the proper psk hash.

Add the following lines to /etc/network/interfaces

iface adhoc inet static
   address 192.168.2.1
   netmask 255.255.255.0
   network 192.168.2.0
   post-up /etc/init.d/dnsmasq start
   pre-down /etc/init.d/dnsmasq stop

Move, delete, read or otherwise trash /etc/dnsmasq.conf and replace it with:

address=/<HOSTNAME>/192.168.2.1
interface=wlan0
bind-interfaces
no-hosts
dhcp-range=192.168.2.10,192.168.2.100,1h

Set <HOSTNAME> to the hostname of your turtlebot, of course.

When you connect to this wireless network, your laptop should get an IP address, and you should be able to connect to your turtlebot by name.

Wiki: turtlebot/Tutorials/Advanced Networking Setup (last edited 2014-09-08 08:52:02 by AustinHendrix)