34 #include <nav_msgs/GetMap.h> 36 #include <geometry_msgs/Quaternion.h> 41 #include <map_organizer_msgs/OccupancyGridArray.h> 71 for (
auto& map : maps->maps)
78 void mapCallback(
const nav_msgs::OccupancyGrid* map,
const int floor)
80 ROS_INFO(
"Received a %d X %d map @ %.3f m/pix",
83 map->info.resolution);
85 std::string mapdatafile = mapname_ + std::to_string(floor) +
".pgm";
86 ROS_INFO(
"Writing map occupancy data to %s", mapdatafile.c_str());
87 FILE* out = fopen(mapdatafile.c_str(),
"w");
90 ROS_ERROR(
"Couldn't save map file to %s", mapdatafile.c_str());
94 fprintf(out,
"P5\n# CREATOR: Map_generator.cpp %.3f m/pix\n%d %d\n255\n",
95 map->info.resolution, map->info.width, map->info.height);
96 for (
unsigned int y = 0; y < map->info.height; y++)
98 for (
unsigned int x = 0; x < map->info.width; x++)
100 unsigned int i = x + (map->info.height - y - 1) * map->info.width;
101 if (map->data[i] == 0)
105 else if (map->data[i] == +100)
118 std::string mapmetadatafile = mapname_ + std::to_string(floor) +
".yaml";
119 ROS_INFO(
"Writing map occupancy data to %s", mapmetadatafile.c_str());
120 FILE* yaml = fopen(mapmetadatafile.c_str(),
"w");
122 geometry_msgs::Quaternion orientation = map->info.origin.orientation;
124 double yaw, pitch, roll;
127 fprintf(yaml,
"image: %s\nresolution: %f\n" 128 "origin: [%f, %f, %f]\nheight: %f\n" 129 "negate: 0\noccupied_thresh: 0.65\nfree_thresh: 0.196\n\n",
130 mapdatafile.c_str(), map->info.resolution,
131 map->info.origin.position.x, map->info.origin.position.y, yaw, map->info.origin.position.z);
139 #define USAGE "Usage: \n" \ 141 " map_saver [-f <mapname>] [ROS remapping args]" 143 int main(
int argc,
char** argv)
146 std::string mapname =
"map";
148 for (
int i = 1; i < argc; i++)
150 if (!strcmp(argv[i],
"-h"))
155 else if (!strcmp(argv[i],
"-f"))
map_organizer_msgs::OccupancyGridArray maps
int main(int argc, char **argv)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
MapGeneratorNode(const std::string &mapname)
void mapCallback(const nav_msgs::OccupancyGrid *map, const int floor)
void mapsCallback(const map_organizer_msgs::OccupancyGridArrayConstPtr &maps)
ROSCPP_DECL void spinOnce()
void getEulerYPR(tf2Scalar &yaw, tf2Scalar &pitch, tf2Scalar &roll, unsigned int solution_number=1) const