Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for system values reporting #33

Merged
merged 8 commits into from
Jan 4, 2024
Merged
Changes from 2 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
31 changes: 31 additions & 0 deletions inorbit_edge/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
CustomScriptStatusMessage,
CustomCommandRosMessage,
CameraMessage,
SystemStatsMessage,
)
from inorbit_edge.video import CameraStreamer, Camera
from inorbit_edge.missions import MissionsModule
Expand Down Expand Up @@ -56,6 +57,7 @@
MQTT_SUBTOPIC_STATE = "state"
MQTT_SUBTOPIC_CAMERA_V2 = "ros/camera2"
MQTT_SUBTOPIC_OUT_CMD = "out_cmd"
MQTT_SUBTOPIC_SYSTEM_STATS = "system/stats"

MQTT_TOPIC_ECHO = "echo"
MQTT_NAV_GOAL_GOAL = "ros/loc/nav_goal"
Expand Down Expand Up @@ -829,6 +831,35 @@ def set_pairs(key):

self.publish_protobuf(MQTT_SUBTOPIC_CUSTOM_DATA, msg)

def publish_system_stats(self, system_values):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest changing this method's signature to publish_system_stats(self, cpu_load_percentage=None, ram_usage_percentage=None, hdd_usage_percentage=None, total_tx=None, total_rx=None, ts=None, elapsed_seconds=None) This way the SDK users can leverage IDE autocomplete features and minimize the chances of typos in the field names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice suggestion, I agree :)

"""Publishes system information (CPU load, RAM usage, HDD usage, network stats)

Args:
system_values (dict): Key value mappings to publish
{
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.
hdd_usage_percentage (float, value between 0.0 and 1.0): HDD usage.
total_tx (int): Total bytes transmitted
total_rx (int): Total bytes received
ts (int): Timestamp. Defaults to int(time() * 1000).
It is needed to calculate the network rate in InOrbit
elapsed_seconds (float): Duration of the reported period.
It is needed to calculate the network rate in InOrbit
}
"""
msg = SystemStatsMessage()
msg.cpu_load_percentage = system_values.get("cpu_load_percentage")
msg.ram_usage_percentage = system_values.get("ram_usage_percentage")
msg.hdd_usage_percentage = system_values.get("hdd_usage_percentage")
msg.total_tx = system_values.get("total_tx")
msg.total_rx = system_values.get("total_rx")
ts = system_values.get("ts")
msg.timestamp = ts if ts else int(time.time() * 1000)
msg.elapsed_seconds = system_values.get("elapsed_seconds")

self.publish_protobuf(MQTT_SUBTOPIC_SYSTEM_STATS, msg)

def publish_odometry(
self,
ts_start=None,
Expand Down
Loading