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

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

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;
    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"});
    ros::Rate rate(.1);
    while (nh.ok()) {
        ros::Time time = ros::Time::now();
        grid_map_msgs::GridMap msg;
        GridMapRosConverter::toMessage(map, msg);
    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


Maybe it is too late to help you. But I guess you did not initialize your map properly.

status = loadFromBag ("/home/to/Desktop/grid_map_example.bag", "the topic name of the grid map in the ROS bag", map);

http://docs.ros.org/en/melodic/api/gr... .

TimpunKampun gravatar image TimpunKampun  ( 2021-01-14 02:42:26 -0500 )edit