Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You have 2 issues in the line msg = self.get_logger().info("distance: ".format(float(ser.readline()))):

  • You re-assign msg with the return value of .info(...), which is a boolean: True if logging was successful or False if some filter prevented the message from being logged (see here). This is where your main issue comes from.
  • You call .format(...) on a string without any formatting placeholders
  • You read from the serial again _within_ the log message, after which the line you read is lost. Could well be that this reads ' ' which is why you don't get it from your other read.

You maybe meant that line to be:

self.get_logger().info("distance: {}".format(float(sensorvalue)))