Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map saving and serialization services return bool #546

Open
wants to merge 1 commit into
base: melodic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion slam_toolbox/include/slam_toolbox/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ inline bool fileExists(const std::string& name)
return (stat (name.c_str(), &buffer) == 0);
}

inline void write(const std::string& filename,
inline bool write(const std::string& filename,
karto::Mapper& mapper,
karto::Dataset& dataset)
{
try
{
mapper.SaveToFile(filename + std::string(".posegraph"));
dataset.SaveToFile(filename + std::string(".data"));
return true;
}
catch (boost::archive::archive_exception e)
{
ROS_ERROR("Failed to write file: Exception %s", e.what());
return false;
}
}

Expand Down
2 changes: 2 additions & 0 deletions slam_toolbox/src/map_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ bool MapSaver::saveMapCallback(
{
ROS_WARN("Map Saver: Cannot save map, no map yet received on topic %s.",
map_name_.c_str());
resp.success = false;
return false;
}

Expand All @@ -62,6 +63,7 @@ bool MapSaver::saveMapCallback(
int rc = system("rosrun map_server map_saver");
}
ros::Duration(1.0).sleep();
resp.success = true;
return true;
}

Expand Down
9 changes: 8 additions & 1 deletion slam_toolbox/src/slam_toolbox_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ bool SlamToolbox::serializePoseGraphCallback(
slam_toolbox_msgs::SerializePoseGraph::Response &resp)
/*****************************************************************************/
{
bool success = false;
std::string filename = req.filename;

// if we're inside the snap, we need to write to commonly accessible space
Expand All @@ -593,7 +594,8 @@ bool SlamToolbox::serializePoseGraphCallback(
}

boost::mutex::scoped_lock lock(smapper_mutex_);
serialization::write(filename, *smapper_->getMapper(), *dataset_);
success = serialization::write(filename, *smapper_->getMapper(), *dataset_);
resp.success = success;
return true;
}

Expand Down Expand Up @@ -706,6 +708,7 @@ bool SlamToolbox::deserializePoseGraphCallback(
{
ROS_ERROR("Deserialization called without valid processor type set. "
"Undefined behavior!");
resp.success = false;
return false;
}

Expand All @@ -714,6 +717,7 @@ bool SlamToolbox::deserializePoseGraphCallback(
if (filename.empty())
{
ROS_WARN("No map file given!");
resp.success = false;
return true;
}

Expand All @@ -730,6 +734,7 @@ bool SlamToolbox::deserializePoseGraphCallback(
{
ROS_ERROR("DeserializePoseGraph: Failed to read "
"file: %s.", filename.c_str());
resp.success = false;
return true;
}
ROS_DEBUG("DeserializePoseGraph: Successfully read file.");
Expand All @@ -755,9 +760,11 @@ bool SlamToolbox::deserializePoseGraphCallback(
req.initial_pose.y, req.initial_pose.theta);
break;
default:
resp.success = false;
ROS_FATAL("Deserialization called without valid processor type set.");
}

resp.success = true;
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion slam_toolbox_msgs/srv/DeserializePoseGraph.srv
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ int8 LOCALIZE_AT_POSE = 3
string filename
int8 match_type
geometry_msgs/Pose2D initial_pose
---
---
bool success
1 change: 1 addition & 0 deletions slam_toolbox_msgs/srv/SaveMap.srv
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
std_msgs/String name
---
bool success
3 changes: 2 additions & 1 deletion slam_toolbox_msgs/srv/SerializePoseGraph.srv
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
string filename
---
---
bool success