Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions inorbit_edge/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ def _on_connect(self, client, userdata, flags, reason_code, properties):
return

# Send robot online status (best effort)
# If this fails and InOrbit is getting data, it will detect discrepancy
# and request a status update via get_state command.
# If this fails and InOrbit is getting system stats data, it will detect
# the discrepancy and request a status update via get_state.
self._send_robot_status(online=True)

# Subscribe to interesting topics
Expand Down Expand Up @@ -766,10 +766,11 @@ def _handle_unload_module(self, module_name):
def _handle_get_state(self):
"""Handle get_state command from InOrbit.

If the robot is offline, the next pose should not be accumulated for odometry
estimation.
Automatically requested by InOrbit when the robot is set to offline but system
stats are sent.

TODO(b-Tomas): implement a proactive way to set the robot online status.
If the robot is offline, the next pose is not accumulated for odometry
estimation.
"""
is_online = True # Default assumption

Expand Down Expand Up @@ -1067,10 +1068,11 @@ def register_command_callback(self, callback):
def set_online_status_callback(self, callback):
"""Set callback to determine robot online status.

Called on a state request from InOrbit. @see _handle_get_state.

Args:
callback: A callable that returns bool indicating if robot is online.
Should return True if robot is online, False otherwise.
Will be called when InOrbit requests status via get_state command.
"""
if callable(callback):
self._online_status_callback = callback
Expand Down Expand Up @@ -1126,14 +1128,7 @@ def _send_robot_status(self, online=True):
)
self.logger.debug(f"{status_str.capitalize()} status sent successfully")
except Exception as e:
fallback_msg = (
"InOrbit will detect via data messages"
if online
else "InOrbit will detect via data absence"
)
self.logger.debug(
f"{status_str.capitalize()} status failed: {e} - {fallback_msg}"
)
self.logger.debug(f"{status_str.capitalize()} status failed: {e}")

def _is_connected(self):
return self.client.is_connected()
Expand Down Expand Up @@ -1370,6 +1365,11 @@ def publish_system_stats(
):
"""Publishes system information (CPU load, RAM usage, HDD usage, network stats)

If sent while the robot is marked as offline, InOrbit will detect the
discrepancy and request a state update via get_state.
It is recommended to always send system stats to ensure the robot state is
consistent at all times.

Args:
cpu_load_percentage (float, value between 0.0 and 1.0): CPU usage.
ram_usage_percentage (float, value between 0.0 and 1.0): RAM usage.
Expand Down