Skip to content

Commit

Permalink
Added Service response structure for save map and serialize Posegraph (
Browse files Browse the repository at this point in the history
…SteveMacenski#421)

* Added Service response structure for save map and serialize Posegraph

* Updated Segmentation_fault to Undefined_failure condition

* Updated result of serialize service

* Updated code according to the project's style guide

Co-authored-by: SumontreeP <[email protected]>
  • Loading branch information
Tarzoozoo and SumontreeP authored Jul 16, 2021
1 parent 05dfd3b commit fd353d7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
4 changes: 3 additions & 1 deletion include/slam_toolbox/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ inline bool fileExists(const std::string & name)
return stat(name.c_str(), &buffer) == 0;
}

inline void write(
inline bool write(
const std::string & filename,
karto::Mapper & mapper,
karto::Dataset & dataset,
Expand All @@ -43,9 +43,11 @@ inline void write(
try {
mapper.SaveToFile(filename + std::string(".posegraph"));
dataset.SaveToFile(filename + std::string(".data"));
return true;
} catch (boost::archive::archive_exception e) {
RCLCPP_ERROR(node->get_logger(),
"Failed to write file: Exception %s", e.what());
return false;
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/map_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ bool MapSaver::saveMapCallback(
RCLCPP_WARN(node_->get_logger(),
"Map Saver: Cannot save map, no map yet received on topic %s.",
map_name_.c_str());
response->result = response->RESULT_NO_MAP_RECEIEVD;
return false;
}

Expand All @@ -61,10 +62,20 @@ bool MapSaver::saveMapCallback(
RCLCPP_INFO(node_->get_logger(),
"SlamToolbox: Saving map as %s.", name.c_str());
int rc = system(("ros2 run nav2_map_server map_saver_cli -f " + name + " --ros-args -p map_subscribe_transient_local:=true").c_str());
if (rc == 0) {
response->result = response->RESULT_SUCCESS;
} else {
response->result = response->RESULT_UNDEFINED_FAILURE;
}
} else {
RCLCPP_INFO(node_->get_logger(),
"SlamToolbox: Saving map in current directory.");
int rc = system("ros2 run nav2_map_server map_saver_cli --ros-args -p map_subscribe_transient_local:=true");
if (rc == 0) {
response->result = response->RESULT_SUCCESS;
} else {
response->result = response->RESULT_UNDEFINED_FAILURE;
}
}

rclcpp::sleep_for(std::chrono::seconds(1));
Expand Down
8 changes: 6 additions & 2 deletions src/slam_toolbox_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,12 @@ bool SlamToolbox::serializePoseGraphCallback(
}

boost::mutex::scoped_lock lock(smapper_mutex_);
serialization::write(filename, *smapper_->getMapper(),
*dataset_, shared_from_this());
if (serialization::write(filename, *smapper_->getMapper(), *dataset_, shared_from_this())) {
resp->result = resp->RESULT_SUCCESS;
} else {
resp->result = resp->RESULT_FAILED_TO_WRITE_FILE;
}

return true;
}

Expand Down
6 changes: 6 additions & 0 deletions srvs/SaveMap.srv
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
std_msgs/String name
---
# Result code defintions
uint8 RESULT_SUCCESS=0
uint8 RESULT_NO_MAP_RECEIEVD=1
uint8 RESULT_UNDEFINED_FAILURE=255

uint8 result
7 changes: 6 additions & 1 deletion srvs/SerializePoseGraph.srv
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
string filename
---
---
# Result code defintions
uint8 RESULT_SUCCESS=0
uint8 RESULT_FAILED_TO_WRITE_FILE=255

uint8 result

0 comments on commit fd353d7

Please sign in to comment.