Multiple nodes publish to one topic, all fields in msg are not populated at once
I set up a minimum ROS package that demonstrates my issue.
Consider a robot that has two sensors, each sensor publishes to the same topic (i.e. /sensorData) but each sensor populates a different subset of the message.
For example the .msg might be:
int64 sensorAout1
int64 sensorAout2
int64 sensorBout1
int64 sensorBout2
Where sensorA populates the first two fields, and sensorB the last two fields. When a listener node subscribes to this topic, then at any one instant the topic is never fully populated with values from both sensors, instead it switches between the two. For example, the output from the listener node contains the sensorA data but blanks for sensorB and then vice versa.
Is there a way to resolve this? perhaps setting up the sensors as services and a seperate node that packages it all into one topic /sensorData?