[Documentation] [TitleIndex] [WordIndex

!

Note: This tutorial assumes that you have completed the previous tutorials: RGB-D Hand-Held Mapping With a Kinect.
(!) 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.

Wifi Signal Strength Mapping (User Data Usage)

Description: This tutorial shows how to add user data during mapping that will be saved directly in RTAB-Map's database for convenience.

Tutorial Level: INTERMEDIATE

Introduction

Version >0.11.14 required.

This tutorial will show how to create a map including information taken with any other sensor (e.g., the user data). For convenience, we will map Wifi signal strength of the environment. The screenshot below shows how the Wifi signal strength is visualized. It is just a level bar used (sensor_msgs/Pointcloud2), but more fancy output like Markers can be used to customize the look. Wifi mapping 1 Wifi mapping 2

How to Publish User Data (wifi_signal_pub)

To add user data to map, rtabmap node has topics called user_data and user_data_async. The first one is used when parameter subscribe_user_data:=true, and it will be synchronized with other sensor data. It means that the publishing rate of this topic should be high (at least as fast as the images received). The second topic user_data_async is asynchronous. It should be used only when user data is published slower than the detection rate of rtabmap (default 1 Hz). The received user data will be saved in the next node created in rtabmap (if user data is published faster than nodes are created, old user data will be overwritten).

For this example, we use user_data_async with a Wifi signal data published each 2 seconds. Here is the basic information needed to publish a rtabmap_ros/UserData topic (the full code is here):

   1 #include <rtabmap_ros/MsgConversion.h>
   2 #include <rtabmap_ros/UserData.h>
   3 
   4 int main(int argc, char** argv)
   5 {
   6    //... node initialization stuff
   7 
   8    ros::Rate rate(0.5); 
   9 
  10    ros::Publisher wifiPub = nh.advertise<rtabmap_ros::UserData>("wifi_signal", 1);
  11    
  12    while(ros::ok())
  13    {
  14       ros::Time stamp = ros::Time::now();
  15 
  16       // Get signal strength...
  17       int dBm = ...
  18 
  19       // Create user data [level, stamp].
  20       // OpenCV matrix is used for convenience. Any format is accepted.
  21       // However, if CV_8UC1 format is used, make sure rows > 1 as 
  22       // rtabmap will think it is already compressed.
  23       cv::Mat data(1, 2, CV_64FC1);
  24       data.at<double>(0) = double(dBm);
  25 
  26       // We should set stamp in data to be able to
  27       // retrieve it from the saved user data as we need 
  28       // to get precise position in the graph afterward.
  29       data.at<double>(1) = stamp.toSec();
  30 
  31       rtabmap_ros::UserData dataMsg;
  32       dataMsg.header.frame_id = "wifi_link";
  33       dataMsg.header.stamp = stamp;
  34 
  35       // Convert OpenCV matrix to UserData msg. Optionally, 
  36       // we can choose to compress the data now (here we keep uncompressed).
  37       rtabmap_ros::userDataToROS(data, dataMsg, false);
  38       
  39       // Publish data!
  40       wifiPub.publish<rtabmap_ros::UserData>(dataMsg);
  41       
  42       ros::spinOnce();
  43       rate.sleep();
  44    }
  45    return 0;
  46 }

How to Retrieve User Data (wifi_signal_sub)

rtabmap publishes rtabmap_ros/MapData topic after each update. In this topic, we can get the user data that we published to rtabmap earlier, which is now linked to graph. Here is an example (the full code is here):

   1 #include <rtabmap_ros/MapData.h>
   2 #include <rtabmap_ros/MsgConversion.h>
   3 
   4 std::map<double, int> wifiLevels;
   5 void mapDataCallback(const rtabmap_ros::MapDataConstPtr & mapDataMsg)
   6 {
   7    // Convert MapData message in more user friendly objects
   8    rtabmap::Transform mapToOdom;
   9    std::map<int, rtabmap::Transform> poses;
  10    std::multimap<int, rtabmap::Link> links;
  11    std::map<int, rtabmap::Signature> signatures;
  12 
  13    rtabmap_ros::mapDataFromROS(*mapDataMsg, poses, links, signatures, mapToOdom);
  14 
  15    // The user data of the latest node added to 
  16    // map is contained in signatures map. Iterate over 
  17    // to get the data. Handle the case where we can 
  18    // receive only latest data, or if all data are published
  19    for(std::map<int, rtabmap::Signature>::iterator iter=signatures.begin(); iter!=signatures.end(); ++iter)
  20    {
  21       int id = iter->first;
  22       rtabmap::Signature & node = iter->second;
  23 
  24       if(!node.sensorData().userDataCompressed().empty())
  25       {
  26          cv::Mat data;
  27          node.sensorData().uncompressDataConst(0 ,0, 0, &data);
  28 
  29          if(data.type() == CV_64FC1 && data.rows == 1 && data.cols == 2)
  30          {
  31             // format [int level, double stamp], see wifi_signal_pub_node.cpp
  32             int level = data.at<double>(0);
  33             double stamp = data.at<double>(1);
  34             wifiLevels.insert(std::make_pair(stamp, level));
  35          }
  36          else if(!data.empty())
  37          {
  38             ROS_ERROR("Wrong user data format for wifi signal.");
  39          }
  40       }
  41    }
  42 
  43    // "wifiLevels" contains all signal values sorted 
  44    // by timestamp. We can then find their exact position 
  45    // on the graph. See referred source code for details...
  46 }
  47 
  48 
  49 
  50 int main(int argc, char** argv)
  51 {
  52    //... node initialization stuff
  53 
  54    ros::Subscriber mapDataSub = nh.subscribe("/rtabmap/mapData", 1, mapDataCallback);
  55 
  56    ros::spin();
  57 }

Example of Usage

Here is an example using a hand-held RGB-D camera:

$ roslaunch freenect_launch freenect.launch depth_registration:=true
$ roslaunch rtabmap_ros rtabmap.launch rtabmap_args:="--delete_db_on_start" user_data_async_topic:=/wifi_signal rtabmapviz:=false rviz:=true
$ rosrun rtabmap_ros wifi_signal_pub _interface:="wlan0"
$ rosrun rtabmap_ros wifi_signal_sub

In RVIZ, add PointCloud2 topic called wifi_signals published from wifi_signal_sub node. Note that you may need to start wifi_signal_pub in sudo. To do so:

$ sudo su
$ source /opt/ros/kinetic/setup.bash
$ source /home/{user_name}/catkin_ws/devel/setup.bash (if rtabmap is built from source)
$ rosrun rtabmap_ros wifi_signal_pub interface:="wlan0"

If you move the camera, you should see the signal strength bars like in the screenshots above.

Example of Result

You can show the map of the screenshots above using this database demo_wifi.db (taken with a stereo camera) with the lines below:

$ roslaunch rtabmap_ros rtabmap.launch database_path:=~/Downloads/demo_wifi.db rtabmapviz:=false rviz:=true
$ rosrun rtabmap_ros wifi_signal_sub
// In RVIZ, add `PointCloud2` topic called `wifi_signals`
$ rosservice call /rtabmap/publish_map 1 1 0

2019-10-19 13:11