-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
map_server refactor and cleanup (#1624)
* [WIP] map_server refactor and cleanup nav2_map_server/mapio (map input-optput library): * Move OccupancyGrid messages saving code from MapSaver::mapCallback() to saveMapToFile() function * Rename and move try_write_map_to_file() MapSaver method to tryWriteMapToFile() function * Move map saving parameters into one SaveParameters struct * Reorganize map saving parameters verification code from MapSaver to new checkSaveParameters() function * Correct logging for incorrect input cases in checkSaveParameters() * Copy loadMapFromYaml() method from OccupancyGridLoader * Move loadMapFromFile() method from OccupancyGridLoader * Rename and move load_map_yaml() OccupancyGrid method to loadMapYaml() function * Move LoadParameters struct from OccupancyGridLoader nav2_map_server/map_saver: * Completely re-work MapSaver node: - Switch MapSaver from rclcpp::Node to nav2_utils::LifecycleNode - Revise MapSaver node parameters model - Add saveMapTopicToFile() method for saving map from topic - Remove future-promise synchronization model as unnecessary * Add "save_map" service with new SaveMap service messages * Rename map_saver_cli.cpp -> map_saver_cli_main.cpp file and map_saver -> to map_saver_cli executable * Add ability to save a map from custom topic ("-t" cli-option) * Restore support of "--ros-args" remappings * Update help message in map_saver_cli * New map_saver_server_main.cpp file and map_saver_server executable: continuously running server node * New launch/map_saver_server.launch.py: map_saver_server launcher nav2_map_server/map_server: * Revise MapServer node parameters model * Rename loadMapFromYaml() -> loadMapResponseFromYaml() * Add node prefix to "map" and "load_map" service names * Fix crash: dereferencing nullptr in map_server running as a node while handling of incorrect input map name * Add updateMsgHeader() method for correcting map message header when it belongs to instantiated object * Rename main.cpp -> map_server_main.cpp file * Minor changes and renames to keep unified code style nav2_util/map_loader: * Remove as duplicating of loadMapFromFile() from MapIO library other: * Update nav2_map_server/README * Fix testcases * Fixes for cpplint, uncrustify, flake8 and test_occ_grid_node failures * Fixing review comments * Rename mapio -> map_io * Move all OccGridLoader functionality into MapServer. Remove OccGridLoader * Switch all thresholds to be floating-point * Switch loadMapFromYaml() returning type to LOAD_MAP_STATUS and remove duplicating code from loadMapResponseFromYaml() * Make mapCallback() to be lambda-function * Make saveMapCallback() to be class method * Utilize local rclcpp_node_ from LifecycleNode instead of map_listener_. Remove map_listener_ and got_map_msg_ variables. * Rename load_map_callback() -> loadMapCallback() and make it to be class method * Rename handle_occ_callback() -> getMapCallback() and make it to be class method * Force saveMapTopicToFile() and saveMapToFile() to work with constant arguments * map_saver_cli: move arguments parsing code into new parse_arguments() function * Rename test_occ_grid_node -> test_map_server_node and fix test * Rename test_occ_grid -> test_occ_grid and fix test * Fix copyrights * Fix comments * Update README * Increase test coverage * Fixing review comments * Separate map_server and map_saver sources * Fix copyrights * Suppress false-positive uncrustify failure
- Loading branch information
1 parent
3205861
commit b01810b
Showing
46 changed files
with
2,431 additions
and
1,613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) 2018 Intel Corporation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/* OccupancyGrid map input-output library */ | ||
|
||
#ifndef NAV2_MAP_SERVER__MAP_IO_HPP_ | ||
#define NAV2_MAP_SERVER__MAP_IO_HPP_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "nav2_map_server/map_mode.hpp" | ||
#include "nav_msgs/msg/occupancy_grid.hpp" | ||
|
||
/* Map input part */ | ||
|
||
namespace nav2_map_server | ||
{ | ||
|
||
struct LoadParameters | ||
{ | ||
std::string image_file_name; | ||
double resolution{0}; | ||
std::vector<double> origin{0, 0, 0}; | ||
double free_thresh; | ||
double occupied_thresh; | ||
MapMode mode; | ||
bool negate; | ||
}; | ||
|
||
typedef enum | ||
{ | ||
LOAD_MAP_SUCCESS, | ||
MAP_DOES_NOT_EXIST, | ||
INVALID_MAP_METADATA, | ||
INVALID_MAP_DATA | ||
} LOAD_MAP_STATUS; | ||
|
||
/** | ||
* @brief Load and parse the given YAML file | ||
* @param yaml_filename Name of the map file passed though parameter | ||
* @return Map loading parameters obtained from YAML file | ||
* @throw YAML::Exception | ||
*/ | ||
LoadParameters loadMapYaml(const std::string & yaml_filename); | ||
|
||
/** | ||
* @brief Load the image from map file and generate an OccupancyGrid | ||
* @param load_parameters Parameters of loading map | ||
* @param map Output loaded map | ||
* @throw std::exception | ||
*/ | ||
void loadMapFromFile( | ||
const LoadParameters & load_parameters, | ||
nav_msgs::msg::OccupancyGrid & map); | ||
|
||
/** | ||
* @brief Load the map YAML, image from map file and | ||
* generate an OccupancyGrid | ||
* @param yaml_file Name of input YAML file | ||
* @param map Output loaded map | ||
* @return status of map loaded | ||
*/ | ||
LOAD_MAP_STATUS loadMapFromYaml( | ||
const std::string & yaml_file, | ||
nav_msgs::msg::OccupancyGrid & map); | ||
|
||
|
||
/* Map output part */ | ||
|
||
struct SaveParameters | ||
{ | ||
std::string map_file_name{""}; | ||
std::string image_format{""}; | ||
double free_thresh{0.0}; | ||
double occupied_thresh{0.0}; | ||
MapMode mode{MapMode::Trinary}; | ||
}; | ||
|
||
/** | ||
* @brief Write OccupancyGrid map to file | ||
* @param map OccupancyGrid map data | ||
* @param save_parameters Map saving parameters. | ||
* @return true or false | ||
*/ | ||
bool saveMapToFile( | ||
const nav_msgs::msg::OccupancyGrid & map, | ||
const SaveParameters & save_parameters); | ||
|
||
} // namespace nav2_map_server | ||
|
||
#endif // NAV2_MAP_SERVER__MAP_IO_HPP_ |
Oops, something went wrong.