ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

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

Comments

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 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-24 07:10:48 -0600

Check that RViz is running and configured properly so it can display grid maps, including making sure all necessary visualization plugins for grid mapping have been enabled in RViz.

Verify that grid map data is being extracted from the rosbag file. Although you have opened and created a view in Rosbag, there's no code in Rosbag that extracts grid map data directly; to do this iteratively through messages in View mode to extract grid map data from each one individually.

Once your grid map data has been extracted from Rosbag, make sure it populates properly into your GridMap object before publishing it for visualization by RViz. Without enough data in its GridMap object (map in your code). RViz won't know what to show visually otherwise!

Verify whether the frame IDs used in your code match those expected by RViz, specifically checking that gridMap (map.setFrameId) and static transform publisher frames IDs (static_transform_publisher) use correct and consistent frame IDs.

Verify that RViz is receiving your published grid map messages by using tools such as rostopic echo or rostopic hz to verify if the grid_map topic is publishing what should be expected messages.

By considering these points, you should be able to quickly recognize and address issues related to visualizing grid maps in RViz.

edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 455 times

Last updated: Jun 24 '23