Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

Pause service for rosbag player - #949

Merged
mikepurvis merged 8 commits into
ros:kinetic-develfrom
locusrobotics:pause-service
Jan 21, 2017
Merged

mikepurvis merged 8 commits into
ros:kinetic-develfrom
locusrobotics:pause-service

Conversation

@ayrton04

Copy link
Copy Markdown
Contributor

We've recently required the ability to pause playback in rosbag play via service calls within code. The changes include the addition of a spinOnce() call within doPublish() so that we can process the service request. I'm not sure if having callbacks in the Player class is acceptable, or if this functionality would be useful for anyone else, but I thought it worth a PR.

Comment thread tools/rosbag/src/player.cpp Outdated
}
else
{
ros::WallDuration shift = ros::WallTime::now() - paused_time_;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this logic is duplicated in the keyboard input processing below, and can put it in a method if preferred.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for merging methods

@dirk-thomas dirk-thomas changed the title Pause service Pause service for rosbag player Dec 14, 2016
@tappan-at-git

tappan-at-git commented Dec 22, 2016 •

Copy link
Copy Markdown
Contributor

I think having the service be namespaced is a good call, even if we need node_handle_ to be at the base namespace of the node. Otherwise you'll have issues if you run more than one rosbag record instance in the same namespace. Tom has rightly pointed out that 1) this is for playback, not recording, and 2) having a service namespaced under an anonymous node is ridiculously unhelpful.

That said, it may be good to rename the service to something a little less generic if we can't conveniently namespace it. rosbag_pause could be a good match with the existing style.

Comment thread tools/rosbag/src/player.cpp Outdated

if (res.success)
{
res.message = (requested_pause_state_ ? "Pause" : "Resume") + std::string(" requested.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this should be past tense? Eg, Bag playback is now paused/resumed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix.

Comment thread tools/rosbag/src/player.cpp Outdated
requested_pause_state_(false),
terminal_modified_(false)
{
pause_service_ = node_handle_.advertiseService("pause", &Player::pauseCallback, this);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously a different service name here.

Perhaps another option might be:

ros::NodeHandle private_node_handle('~');
pause_service_ = private_node_handle.advertiseService("pause", &Player::pauseCallback, this);

This should get you a rosbag/pause service name, but it will be trivial to rename/remap it from roslaunch or wherever else.

@ayrton04 ayrton04 Jan 10, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure what the best route was here. The problem with a private node handle is that if you're running rosbag play outside a launch file, it will by default be given an anonymous name, and so calling the service is a pain (e.g., rosservice call /play_1484077899473435649/pause). As I couldn't envisage a use case wherein we'd be running more than one rosbag play instance, I figured a service in the global namespace would work.

However, I also can't really see using this outside of a launch file, and even if we did, we could assign a name via the command line. I'll move it back to the private node handle.

@mikepurvis

Copy link
Copy Markdown
Member

This seems simple and straightforward. I'd support a merge if the service name can be sorted out.

@mikepurvis

Copy link
Copy Markdown
Member

LGTM.

@jspricke jspricke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! +1 apart from some comments.

Comment thread tools/rosbag/src/player.cpp Outdated
terminal_modified_(false)
{
ros::NodeHandle private_node_handle("~");
pause_service_ = private_node_handle.advertiseService("pause", &Player::pauseCallback, this);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe name it "pause_playback"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, can do.


ros::NodeHandle node_handle_;

ros::ServiceServer pause_service_;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this changes the ABI, but I don't think anyone is relying on that @dirk-thomas ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can avoid breaking the ABI than we should for sure aim for that. While we don't "guarantee" it we try to make an effort where possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Shall I make this static?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ABI would be maintained if all the new fields (and method) were appended to the class rather than inserted.

However, IMO this is not worth it for the loss in source readability— there are unlikely to be external packages linking to this class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I can go either way. Let me know what you'd all prefer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave it as it is.

Comment thread tools/rosbag/src/player.cpp Outdated
}
else
{
ros::WallDuration shift = ros::WallTime::now() - paused_time_;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for merging methods

@mikepurvis

Copy link
Copy Markdown
Member

Looks great— thanks Tom!

@mikepurvis
mikepurvis merged commit bd7e89c into ros:kinetic-devel Jan 21, 2017
ggallagher01 pushed a commit to clearpathrobotics/ros_comm that referenced this pull request Jan 26, 2017
* Adding pause service to rosbag Player class

* Adding std_srvs dependency

* Making response more informative

* Using private node handle to advertise service

* Removing private namespace from node handle

* PR feedback: changing response message to past tense and advertising service using a private node handle.

* PR feedback: changing service name and placing pause handling logic in a method
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants