ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to get new messages while executing a service request?

asked 2015-09-30 12:21:40 -0600

Sebastian gravatar image

I have written a class called "Driver" which advertises a service. Basically, this service will accept a point (x,y) and return a boolean. It rotates the turtlebot towards the point, and then drives until it reaches that point. The boolean it returns indicates whether or not the robot successfully reached that point.

The design of the service is relatively simple. It periodically sends velocity commands to the robot, as required.

The only time it will return false is when one of the robot bumpers is activated, which can be detected via messages.

My question is: what is the correct design for detecting this bumper change while executing the service request?

My way of doing this is to make another callback inside of the Driver class which specifically handles the bumper message. Then, I would call ros::spinOnce() inside my velocity command loop so that I can detect the message incoming. The bumper callback would set some state in the Driver class, which would be detected by my service request.

I think this would work, but is there a better way?

I was also curious what would happen if multiple service requests were sent to my node. Wouldn't the ros::spinOnce() inside my loop detect the second request and start executing it? This would screw everything up because I can't be handling two services at once. Or perhaps I misunderstand the ROS API behavior in that case.

Thank you for your help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-09-30 18:49:34 -0600

Sebastian gravatar image

I implemented it like I said and no problems yet.

edit flag offensive delete link more

Comments

1

Calling spinOnce() from within a callback is really not recommended. For long running actions that need to be interruptible, want to change behaviour based on input or provide feedback while running, please use actions.

gvdhoorn gravatar image gvdhoorn  ( 2015-10-01 13:51:24 -0600 )edit

Also: for the general case of handling more than a single callback at the same time, look at multithreaded and asynchronous spinners.

gvdhoorn gravatar image gvdhoorn  ( 2015-10-01 13:52:33 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-09-30 12:21:40 -0600

Seen: 221 times

Last updated: Sep 30 '15