Skip to content

Commit

Permalink
Implement robot telemetry exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Apr 9, 2024
1 parent a9760a2 commit b0ae76f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/robot_interface/telemetry/mqtt_client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import time
from abc import ABCMeta, abstractmethod
from queue import Queue
from typing import Callable, Tuple
from typing import Callable, Tuple, Type

from robot_interface.models.exceptions.robot_exceptions import (
RobotTelemetryException,
)
from robot_interface.telemetry.payloads import CloudHealthPayload
from datetime import datetime


class MqttClientInterface(metaclass=ABCMeta):
Expand Down Expand Up @@ -61,17 +63,23 @@ def __init__(
self.retain: bool = retain

def run(self, isar_id: str, robot_name: str) -> None:
self.cloud_healt_topic: str = f"isar/{isar_id}/cloud_health"
topic: str

while True:
try:
payload: str = self.telemetry_method(
isar_id=isar_id, robot_name=robot_name
)
topic = self.topic
except RobotTelemetryException:
continue
payload: Type[CloudHealthPayload] = CloudHealthPayload(
isar_id, robot_name, datetime.utcnow()
)
topic = self.cloud_healt_topic

self.publish(topic=topic, payload=payload, qos=self.qos, retain=self.retain)

self.publish(
topic=self.topic, payload=payload, qos=self.qos, retain=self.retain
)
time.sleep(self.interval)

def publish(
Expand Down
7 changes: 7 additions & 0 deletions src/robot_interface/telemetry/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ class TelemetryPayload:
timestamp: datetime


@dataclass
class CloudHealthPayload:
isar_id: str
robot_name: str
timestamp: datetime


@dataclass
class TelemetryPosePayload(TelemetryPayload):
pose: Pose
Expand Down

0 comments on commit b0ae76f

Please sign in to comment.