Loading a grid_map from a rosbag file is not showing on RViz

asked 2019-07-16 14:54:56 -0600

RayROS gravatar image

Hello, I am trying to load a grid_map that I previously saved into a rosbag. The rosbag file is currently saved on my Desktop There seems to be no errors as I run the example but for some reasons I am not able to visualize the grid_map on RViz. Below the small example code I am using:

#include <ros/ros.h>
#include <grid_map_ros/grid_map_ros.hpp>
#include <Eigen/Eigen>
#include <grid_map_msgs/GridMap.h>
#include <string>
#include <iostream>
#include <rosbag/bag.h>
#include <rosbag/view.h>

#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH

using namespace std;
using namespace grid_map;

// load the grid map from file
// this will be the bag.file previously recorded
void loadGridMapFromFile(std::string gridMapBagName)
{
    //reading the bag where the grid map is recorded
    rosbag::Bag gridBag;
    gridBag.open(gridMapBagName, rosbag::bagmode::Read);

    std::vector<std::string> gridTopic;
    gridTopic.push_back(std::string("grid_map"));
    rosbag::View view(gridBag, rosbag::TopicQuery(gridTopic));
}

int main(int argc, char** argv)
{
    ros::init(argc, argv, "grid_map_loader");
    ros::NodeHandle nh;
    ros::Publisher pub = nh.advertise<grid_map_msgs::GridMap>("grid_map", 1, true);

    GridMap map({"elevation"});
    map.setFrameId("map");
    loadGridMapFromFile("/home/to/Desktop/grid_map_example.bag");
    ros::Rate rate(.1);
    while (nh.ok()) {
        ros::Time time = ros::Time::now();
        map.setTimestamp(time.toNSec());
        grid_map_msgs::GridMap msg;
        GridMapRosConverter::toMessage(map, msg);
        pub.publish(msg);
        rate.sleep();
    }
    return 0;
}

After also doing additional research I run the following command because I realized that I was missing the static_transform_publisher but that also didn't work. Below the command I have been using:

rosrun tf static_transform_publisher 1 0 0 0 0 0 1 world_frame map 100

What am I missing? Thanks for shedding light on this issue.

edit retag flag offensive close merge delete