Loading a grid_map from a rosbag file is not showing on RViz
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.
Asked by RayROS on 2019-07-16 14:54:56 UTC
Answers
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.
Asked by revida on 2023-06-24 07:10:48 UTC
Comments
Maybe it is too late to help you. But I guess you did not initialize your map properly.
http://docs.ros.org/en/melodic/api/grid_map_ros/html/classgrid__map_1_1GridMapRosConverter.html#a3961e3ceb6a202868d45d078c25827dc .
Asked by TimpunKampun on 2021-01-14 03:42:26 UTC