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

using a callback for multiple subscribers (emulating physical outputs)

asked 2013-01-08 06:16:53 -0500

thebyohazard gravatar image

Is there any way to pass extra parameters that are not part of the message to a callback function? Or is there a way to get the topic name the on which the incoming message was broadcast?

Or maybe I'm going about this all wrong. Here's why I'm trying to do this:

I have various i/o devices that I am writing nodes to control. They have different numbers of i/o and different information is needed to specify which i/o line to use. For example, one uses ports that can be set as either input or output and another has dedicated inputs and dedicated outputs.

I had originally thought to have different kinds of message types with the different fields, (for example: daq_inputs, plc_inputs, daq_output_command, plc_output_command) but this is inflexible as higher level nodes must be rewritten to use different i/o devices.

I've since changed my strategy to trying to emulate individual inputs and output command topics with the help of config files so the higher nodes don't have to know where the data comes from, they just look for a specific sensor topic and publish commands to specific output topics. Then you can use whatever device to get/change the I/O as long as it is configurable. Example: Map input 1 of the plc to the topic /sensor_1. Map commands on the topic /relay_1_command to change bit 2 of port A on the daq. Simple std_msgs::Bool messages can be used.

Inputs are easy enough: I load the topic name for each used input from a config file, advertise those topics, and publish those from a vector of publishers.

Outputs are trickier, though, because every time you subscribe, you must link a callback. The way I see it, I'll need multiple subscribers, but I only really need one callback. However, I need to know which output to change, and this info can't be part of the message if the higher nodes are to be oblivious. I figure I can either get this info by passing it in through the callback or by the message itself if it knows its topic name.

So again: is there any way to pass extra parameters that are not part of the message to a callback function? Or is there a way to get the topic name the on which the incoming message was broadcast?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-01-08 07:58:57 -0500

thebyohazard gravatar image

I guess I didn't look hard enough before posting. The answer is to use boost::bind to bind the extra parameter to the callback method. There's an example here.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-01-08 06:16:53 -0500

Seen: 2,194 times

Last updated: Jan 08 '13