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!
Originally posted by thebyohazard on ROS Answers with karma: 3562 on 2013-01-08
Post score: 0