How to publish an empty or NaN Int16?
I'm using rospy
to publish some Int16
data when a sensor is connected. This works great but when the sensor cannot connect I want to publish either an empty
or NaN
value on the same topic.
When I try the following, the data is actually published as 0
which is misleading in the context of my application.
pub = rospy.Publisher('my_topic', Int16, queue_size=1)
my_empty_message = Int16()
pub.publish(my_empty_message)
I've played around by adding my_empty_message.data = NaN
but NaN
does not seem to be compatible with the message type.
How should I go about this?
NaN
is a floating point concept. It does not exist for integers.Could you clarify why you want to publish messages even if there is no sensor connected?
You can choose not to publish. Alternatively, you can send a value that the sensor can't handle (for example, a negative number or a large number such as 30000) instead of NaN.
I want to publish an empty message to indicate that there is no sensor connection established. Even when I choose not to publish
rostopic echo
shows data as0
when, to me, it ought to be blank or something equivalent toNaN
.What about publishing a "sensor status message" instead + not publishing the sensor data itself when there is no connection? That's both less ambiguous as well as easily implemented.
Could you describe this more?
rostopic echo
will not "make up" data, so if there are no messages published, it will notecho
anything.How would I go about publishing a sensor status message? I guess that means on a separate topic if it's a different message type?
For the second comment, I've realised that I was actually publishing the initialisation of my data variable, i.e.
data = Int16()
, in awhile loop
which I think explains whyrostopic echo
was giving me0
.