fix: correct rclpy logger calls to use f-strings (pre-existing bugs)
rclpy RcutilsLogger.info/warning/debug() do not accept printf-style positional format args. Also fix p["use_phone_timestamp"] → p["use_phone_ts"] key mismatch in __init__ log line. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
29a4d8cf55
commit
5f54150708
@ -164,8 +164,8 @@ class MqttRos2BridgeNode(Node):
|
|||||||
self._mqtt_connect()
|
self._mqtt_connect()
|
||||||
|
|
||||||
self.get_logger().info(
|
self.get_logger().info(
|
||||||
"MQTT→ROS2 bridge started — broker=%s:%d use_phone_ts=%s",
|
f"MQTT→ROS2 bridge started — broker={p['mqtt_host']}:{p['mqtt_port']}"
|
||||||
p["mqtt_host"], p["mqtt_port"], p["use_phone_timestamp"],
|
f" use_phone_ts={p['use_phone_ts']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# ── Param helper ─────────────────────────────────────────────────────────
|
# ── Param helper ─────────────────────────────────────────────────────────
|
||||||
@ -197,7 +197,7 @@ class MqttRos2BridgeNode(Node):
|
|||||||
)
|
)
|
||||||
self._mqtt.loop_start()
|
self._mqtt.loop_start()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.get_logger().warning("MQTT initial connect error: %s", str(e))
|
self.get_logger().warning(f"MQTT initial connect error: {e}")
|
||||||
|
|
||||||
def _on_mqtt_connect(self, client, userdata, flags, rc) -> None:
|
def _on_mqtt_connect(self, client, userdata, flags, rc) -> None:
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
@ -206,17 +206,17 @@ class MqttRos2BridgeNode(Node):
|
|||||||
for topic in (_TOPIC_IMU, _TOPIC_GPS, _TOPIC_BATTERY, _TOPIC_IOS_GPS):
|
for topic in (_TOPIC_IMU, _TOPIC_GPS, _TOPIC_BATTERY, _TOPIC_IOS_GPS):
|
||||||
client.subscribe(topic, qos=0)
|
client.subscribe(topic, qos=0)
|
||||||
self.get_logger().info(
|
self.get_logger().info(
|
||||||
"MQTT connected to %s:%d — subscribed to 4 phone topics",
|
f"MQTT connected to {self._p['mqtt_host']}:{self._p['mqtt_port']}"
|
||||||
self._p["mqtt_host"], self._p["mqtt_port"],
|
" — subscribed to 4 phone topics"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.get_logger().warning("MQTT connect failed rc=%d", rc)
|
self.get_logger().warning(f"MQTT connect failed rc={rc}")
|
||||||
|
|
||||||
def _on_mqtt_disconnect(self, client, userdata, rc) -> None:
|
def _on_mqtt_disconnect(self, client, userdata, rc) -> None:
|
||||||
self._mqtt_connected = False
|
self._mqtt_connected = False
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
self.get_logger().warning(
|
self.get_logger().warning(
|
||||||
"MQTT disconnected (rc=%d) — paho will reconnect", rc
|
f"MQTT disconnected (rc={rc}) — paho will reconnect"
|
||||||
)
|
)
|
||||||
|
|
||||||
def _on_mqtt_message(self, client, userdata, message) -> None:
|
def _on_mqtt_message(self, client, userdata, message) -> None:
|
||||||
@ -228,7 +228,7 @@ class MqttRos2BridgeNode(Node):
|
|||||||
try:
|
try:
|
||||||
self._q.put_nowait((topic, message.payload))
|
self._q.put_nowait((topic, message.payload))
|
||||||
except queue.Full:
|
except queue.Full:
|
||||||
self.get_logger().debug("MQTT queue full — dropping %s", topic)
|
self.get_logger().debug(f"MQTT queue full — dropping {topic}")
|
||||||
|
|
||||||
# ── Queue drain (ROS2 executor thread) ────────────────────────────────────
|
# ── Queue drain (ROS2 executor thread) ────────────────────────────────────
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ class MqttRos2BridgeNode(Node):
|
|||||||
self._err_count.get(topic, {}) # just access
|
self._err_count.get(topic, {}) # just access
|
||||||
if topic in self._err_count:
|
if topic in self._err_count:
|
||||||
self._err_count[topic] += 1
|
self._err_count[topic] += 1
|
||||||
self.get_logger().debug("JSON decode error on %s: %s", topic, e)
|
self.get_logger().debug(f"JSON decode error on {topic}: {e}")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -263,7 +263,7 @@ class MqttRos2BridgeNode(Node):
|
|||||||
except (KeyError, TypeError, ValueError) as e:
|
except (KeyError, TypeError, ValueError) as e:
|
||||||
if topic in self._err_count:
|
if topic in self._err_count:
|
||||||
self._err_count[topic] += 1
|
self._err_count[topic] += 1
|
||||||
self.get_logger().debug("Payload error on %s: %s — %s", topic, e, data)
|
self.get_logger().debug(f"Payload error on {topic}: {e} — {data}")
|
||||||
|
|
||||||
# ── Timestamp helper ──────────────────────────────────────────────────────
|
# ── Timestamp helper ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
@ -285,8 +285,7 @@ class MqttRos2BridgeNode(Node):
|
|||||||
drift = abs(now_epoch - phone_ts)
|
drift = abs(now_epoch - phone_ts)
|
||||||
if drift > self._p["warn_drift_s"]:
|
if drift > self._p["warn_drift_s"]:
|
||||||
self.get_logger().warning(
|
self.get_logger().warning(
|
||||||
"Phone clock drift %.2f s (frame_id=%s) — using ROS2 clock",
|
f"Phone clock drift {drift:.2f} s (frame_id={frame_id}) — using ROS2 clock"
|
||||||
drift, frame_id,
|
|
||||||
)
|
)
|
||||||
hdr.stamp = self.get_clock().now().to_msg()
|
hdr.stamp = self.get_clock().now().to_msg()
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user