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

This demo is not ready.

Here in Part 3 we use a Gazebo plugin that updates the antenna position in ns-3 directly rather than having a ROS2 Node listen to Gazebo telemetry messages and update the antenna position in ns-3.

The approach of starting a talker and listener and moving the diff drive robot will be the same but the ns-3 program will be quite different. Here we create a Gazebo World plugin and embed our ns-3 program inside this plugin. Gazebo world file gazebo_ros_diff_drive_ns3_gazebo.world will start our Gazebo World plugin. This World file is identical to gazebo_ros_diff_drive_demo.world packaged with ros-crystal-gazebo-ros-pkgs except that it has been modified to additionally load our world plugin, diff_drive_ns3_gazebo_world.

The diff_drive_ns3_gazebo_world plugin has two parts:

  • The ns-3 part that runs the network simulator which passes Wifi traffic between network namespaces.
  • The Gazebo World plugin part that reads the diff drive vehicle model's pose and writes it into the ns-3 antenna location associated with network namespace nns1 on each world update.

Because the ns-3 part blocks, it is run from a thread. When exiting the diff_drive_ns3_ros2 program, you will need to press Ctrl-C twice to exit Gazebo and ns-3.

Setup

Setup for part 2 includes the following installation:

  • Gazebo 9.
  • A ns-3 Wifi Emulator program modified to interact with our Gazebo World plugin to change the antenna position.
  • Setting additional Global variables.

As with Part 2, once setup is complete we run the talker-listener demo over the Wifi emulator while manipulating the antenna position of the talker by issuing ROS2 Twist commands to the differential drive robot being modeled in Gazebo.

Install Gazebo

Install Gazebo 9 as described in ROS2 ns3 Gazebo Demo Part 2.

Although we will be interfacing with Gazebo directly without ROS2 by using a World plugin, we still need to install ros-crystal-gazebo-ros-pkgs in order to issue ROS2 Twist commands to the diff drive robot being modeled in Gazebo. We also need ros-crystal-gazebo-ros-pkgs for the diff drive model plugin libgazebo_ros_diff_drive.so.

Build the diff_drive_ns3_gazebo Program

ns-3 programs are natively built and run using the WAF build tool. Gazebo plugins are natively built using the CMake build tool. We build the diff_drive_ns3_gazebo program using CMake, which is set up to find ns-3 headers and libraries at the paths installed during the setup portion in ROS2 ns3 Gazebo Demo Part 1. Build the diff_drive_ns3_gazebo program:

cd ~/gits/ns3_gazebo/ns3_gazebo_plugin
mkdir build
cd build
cmake ../
make

Set Global Variables for ns-3

Define global variables so that our diff_drive_ns3_gazebo program can find the ns-3 components that were installed in ROS2 ns3 Gazebo Demo Part 1. Please add this to your .initrc file so that the ns-3 parts of diff_drive_ns3_ros2 can run:

# ns-3 compatibility
export LD_LIBRARY_PATH=~/repos/ns-3-allinone/ns-3.29/build/lib:$LD_LIBRARY_PATH
export PATH=$HOME/repos/ns-3-allinone/ns-3.29/build/src/fd-net-device:$HOME/repos/ns-3-allinone/ns-3.29/build/src/tap-bridge:$PATH

Start a new terminal so these ns-3 compatibility global variables are present in your command shell.

Start Gazebo

Start Gazebo with the diff drive demo world:

cd ~/gits/ns3_gazebo/ns3_gazebo_plugin
gazebo --verbose gazebo_ros_diff_drive_ns3_gazebo.world

Sometimes Gazebo doesn't start because a previous run has not fully shut down. Try killall gzserver.

If you like, you may prefer to start the diff drive demo world without the GUI:

cd ~/gits/ns3_gazebo/ns3_gazebo_plugin
gzserver --verbose gazebo_ros_diff_drive_ns3_gazebo.world

Start the Talker Listener Demo

Start the talker listener demo as described in ROS2 ns3 Gazebo Demo Part 2.

Move the diff drive robot

Move the diff drive robot to move the antenna as described in ROS2 ns3 Gazebo Demo Part 2.