Skip to content

Commit 92e06a1

Browse files
committed
fix(diagnostics): log messages for valid connection
where previously a "No GameController message received" would be shown for every `rclpy.ok()` iteration
1 parent 0aaac3a commit 92e06a1

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

game_controller_hl/game_controller_hl/receiver.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,9 @@ def receive_forever(self):
9999
while rclpy.ok():
100100
# Try to receive a package
101101
self.receive_and_answer_once()
102-
# Check if we didn't receive a package for a long time and if so
103-
# call the fallback behavior
104-
if self.get_time_since_last_package() > Duration(seconds=self.game_controller_lost_time):
105-
self.publish_diagnostics(False)
106-
else:
107-
self.publish_diagnostics(True)
102+
# Check if we didn't receive a package for a long time for publishing diagnostics
103+
received_message_lately = self.get_time_since_last_package() < Duration(seconds=self.game_controller_lost_time)
104+
self.publish_diagnostics(received_message_lately)
108105

109106

110107
def receive_and_answer_once(self):
@@ -139,14 +136,13 @@ def publish_diagnostics(self, received_message_lately: bool):
139136
"""
140137
This publishes a Diagnostics Array.
141138
"""
142-
self.get_logger().info("No GameController message received", throttle_duration_sec=5)
143-
144139
# initialize DiagnsticArray message
145140
diag_array = DiagnosticArray()
146141

147142
# configure DiagnosticStatus message
148143
diag = DiagnosticStatus(name = "Game Controller", hardware_id = "Game Controller")
149144
if not received_message_lately:
145+
self.get_logger().info("No GameController message received", throttle_duration_sec=5)
150146
diag.message = "Lost connection to game controller for " + str(int(self.get_time_since_last_package().nanoseconds / 1e9)) + " sec"
151147
diag.level = DiagnosticStatus.WARN
152148
else:

0 commit comments

Comments
 (0)