ROS2 ns3 Gazebo Demo Part 1 - nps-ros2/ns3_gazebo GitHub Wiki

In this demo we set up and run ROS2 talker and listener nodes in separate Network Namespaces communicating through a Wifi network simulated using ns-3 and communicating with the host:

  • ROS2 autonomy communicates over Wifi
  • ROS2 physics communicates directly with Gazebo running on the host.

Motivation

It is not practical to test robot autonomy logic and Wifi performance using real robots because it is expensive to test with real robots and real robots can get damaged during autonomy logic failure or network communication failure.

Here are the components involved, along with their associated problems:

  • Robot autonomy logic: logic may fail
  • Physical robot and enviornment: costly
  • Wifi network communication: channel may get congested, robot may move out of range

Here is an illustration showing these components:

Real robots

Instead of using real robots, we simulate everything on one computer:

  • Robot autonomy logic
  • Simulated robot physics motion
  • Simulated Wifi network communication

Here is an illustration showing robot autonomy running on one computer using distributed robot components:

Simulated robots

Where:

  • Network Namespaces (nns) provide network separation within one system so that ROS2 messages and services pass between robot autonomy components using simulated Wifi.
  • Real Autonomy logic runs within isolated Network Namespaces. Robot communication between network namespace domains will have their Wifi communication (latency, loss, etc) modeled based on antenna location modeled by Gazebo physics. This works because Gazebo forwards antenna locations to the ns-3 Network Simulator for positional antenna modeling.
  • Simulated Physics within Gazebo controls robot position and velocity. The Real Autonomy logic of a robot interact directly with the Simulated Physics of the same robot using ROS2 messages and services.
  • Simulated Wifi provided by the ns-3 Network Simulator enables simulated Wifi traffic between robot autonomy components running within network namespaces.

Here are the data flows between these components:

Flows between components

Where:

  • (1) shows data flowing between robot autonomy components through the simulated Wifi network.
  • (2) shows the direct link between a robot's autonomy and its physics component within Gazebo.
  • (3) shows the data flow from Gazebo to ns-3, keeping ns-3 up to date about antenna positions.

Setup

Setup for this demo includes the following installation:

  • The ROS2 environment
  • The ns-3 (ns-3.29) Network Simulator
  • The ns-3 Wifi Emulator Program
  • Network Namespaces and their network setup
  • Global Variables

Once setup is complete we run the talker-listener demo between separate network namespaces and between Gazebo and the host.

Install the ROS2 environment

Install the ROS2 environment, see https://github.com/nps-ros2/nps-ros2-examples/wiki/Installing-the-ROS2-Environment.

Install ns-3

Install the ns-3 network simulator, see Installing ns-3.

Build the ns-3 Wifi Eemulator Program

Copy nns_ns3_wifi Wifi emulator program from the repository to the ns-3 scratch/ path, then build it. This program will simulate the Wifi network between robot nodes:

cd ~/repos/ns-3-allinone/ns-3.29
mkdir scratch
cp ~/gits/ns3_gazebo/src/nns_ns3_wifi.cc scratch
./waf build

Install Network Namespaces and Network Topology

Install network namespaces and connect the network:

cd ~/gits/ns3_gazebo/scripts
sudo ./nns_setup.py setup

Here is the resulting network namespace and network topology. The setup script creates five namespaces instead of just the two shown here:

network namespace and network topology

Where:

  • Robot autonomy traffic flows across simulated ns-3 Wifi using subnet 10.0.0.
  • Robot physics traffic flows directly with Gazebo on the host using separate individual subnets: 10.0.1, 10.0.2, etc.

Note: When done, you may remove network namespaces and associated network settings by running nns_setup.py with the teardown option:

cd ~/gits/ns3_gazebo/scripts
sudo ./nns_setup.py teardown

After teardown you may verify that the additional network setup and the network namespaces have been removed:

ip a
sudo ip netns list

Run the Talker Listener Demo

Run the Talker Listener Demo using ns-3 and the namespaces. Use Wireshark, if desired, to capture and inspect Network traffic.

Open a window and start the ns-3 Wifi network simulator:

cd ~/repos/ns-3-allinone/ns-3.29
./waf --run nns_ns3_wifi

Open a window and start a bash process that uses network namespace nns1:

sudo ip netns exec nns1 /bin/bash

and start a talker

ros2 run demo_nodes_cpp talker

Open a window for another network namespace:

sudo ip netns exec nns2 /bin/bash

and start a listener

ros2 run demo_nodes_cpp listener

Several talker/listener test combinations are interesting and may be validated using Wireshark:

  • Host talker to multiple listeners.
  • nns talker to multiple nns listeners with ns3.
  • nns talker to multiple nns listeners with ns3 turned off; listeners will stop listening.

Next

In ROS2 ns3 Gazebo Demo Part 2 we install Gazebo and run the Differential Drive demo to move the talker's Wifi antenna. We demonstrate that the listener fails to receive the talker's messages when the antenna distance exceeds about 20 meters.