-
Notifications
You must be signed in to change notification settings - Fork 451
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
Add pause and reset services to hector_mapping #86
Add pause and reset services to hector_mapping #86
Conversation
find_package(catkin REQUIRED COMPONENTS | ||
roscpp | ||
nav_msgs | ||
visualization_msgs | ||
tf | ||
message_filters | ||
laser_geometry | ||
tf_conversions | ||
message_generation | ||
std_srvs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I separated by one-per-line (for readability), but I can revert this if requested...
In addition, I added the package std_srvs
so that I can add the service calls to this code
@@ -50,6 +50,7 @@ HectorMappingRos::HectorMappingRos() | |||
, tfB_(0) | |||
, map__publish_thread_(0) | |||
, initial_pose_set_(false) | |||
, pause_scan_processing_(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The node starts as "unpaused" (no changes in behavior)
// Initialize services to reset map, and toggle scan pause | ||
resetMapService_ = node_.advertiseService("reset_map", &HectorMappingRos::resetMapCallback, this); | ||
toggleScanProcessingService_ = node_.advertiseService("pause_mapping", &HectorMappingRos::pauseMapCallback, this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new services
if (pause_scan_processing_) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if paused, then we don't process scanCallback
bool HectorMappingRos::resetMapCallback(std_srvs::Trigger::Request &req, | ||
std_srvs::Trigger::Response &res) | ||
{ | ||
ROS_INFO("HectorSM Reset map service called"); | ||
slamProcessor->reset(); | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty much the same behavior as in sysMsgCallback
bool HectorMappingRos::pauseMapCallback(std_srvs::SetBool::Request &req, | ||
std_srvs::SetBool::Response &res) | ||
{ | ||
if (req.data && !pause_scan_processing_) | ||
{ | ||
ROS_INFO("HectorSM Mapping paused"); | ||
} | ||
else if (!req.data && pause_scan_processing_) | ||
{ | ||
ROS_INFO("HectorSM Mapping no longer paused"); | ||
} | ||
pause_scan_processing_ = req.data; | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simple service callback that sets pause_scan_processing_
to whatever was requested in req
#include <std_srvs/SetBool.h> | ||
#include <std_srvs/Trigger.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new necessary includes
bool resetMapCallback(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res); | ||
bool pauseMapCallback(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new service callbacks
ros::ServiceServer resetMapService_; | ||
ros::ServiceServer toggleScanProcessingService_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ros service servers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, we use snake_case for variable names, though, this is a bit inconsistent in this repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good! that goes along with Google's Style Guide! I will make these variables snake_case, and maybe I'll spend sometime in the future to fix this whole class (in another PR).
@@ -140,6 +148,7 @@ class HectorMappingRos | |||
bool initial_pose_set_; | |||
Eigen::Vector3f initial_pose_; | |||
|
|||
bool pause_scan_processing_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class variable that determines whether we should process scans or not
ros::ServiceServer resetMapService_; | ||
ros::ServiceServer toggleScanProcessingService_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, we use snake_case for variable names, though, this is a bit inconsistent in this repo.
Thank you for your PR! |
@StefanFabian thank you very much for your review! I have addressed your concerns, and I hope that the PR is up to standards right now =) |
Thank you for your contribution! |
thanks for the prompt reviews, @StefanFabian! I have updated the wiki documentation to reflect the updates in this PR... In the meantime, I wonder if it would be of interest to have a service call that handles Hector management in a single call (see the definition below). I have been using this in a fork of mine, but it might benefit other ROS hector users:
|
This maybe a dumb question but I made all the changes and now I'm wondering what button to push or command to write to pause Hector slam. (I'm not too familiar with cpp). |
If you're okay with using the command line, then here are some commands that you can use:
|
If you want to have it in your code, you could either incorporate system calls to the commands above, or (if you want to do it right) setup a ROS service client. Here is the ROS reference for that: http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28c%2B%2B%29 |
Please absolutely never use system calls in C++. |
I have an application in which I need to pause/resume/reset
hector_mapping
. I made these modifications, and I believe that it might be useful to other users as well.I noticed that it was possible to reset the map by publishing the string
reset
in the topicsys_msg_topic
, but I needed it to be a service call instead of a topic publishing (I needed to block my code execution until the map was effectively reset).I hope that these modifications are considered useful, and that this can merge to the main branch.
Note: I will add comments to my code changes to clarify everything I did
Note 2: This PR would provide a solution to the old issue in #37
Note 3: This PR is backward-compatible, as it doesn't change any behavior for code that interfaces with
hector_mapping
, it only adds new services that can be used when interfacing with itcloses #37