Skip to content

Commit 261716e

Browse files
RTT measurements are now reported per-robot (UBC-Thunderbots#3422)
* wip * add the rest of the changes * Removed my personal comments (weren't necessary) * added files * applied andrew's changes * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 8c20dd1 commit 261716e

5 files changed

Lines changed: 51 additions & 16 deletions

File tree

src/proto/robot_statistic.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ syntax = "proto3";
33
message RobotStatistic
44
{
55
double round_trip_time_seconds = 1;
6+
uint32 robot_id = 2;
67
}

src/software/thunderscope/robot_communication.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,22 @@ def __enter__(self) -> Self:
288288

289289
return self
290290

291+
def __receive_robot_status(self, robot_status: Message) -> None:
292+
"""Forwards the given robot status to the full system along with the round-trip time
293+
294+
:param robot_status: RobotStatus to forward to fullsystem
295+
"""
296+
round_trip_time_seconds = time.time() - (
297+
robot_status.adjusted_time_sent.epoch_timestamp_seconds
298+
)
299+
robot_statistic = RobotStatistic(
300+
robot_id=robot_status.robot_id,
301+
round_trip_time_seconds=round_trip_time_seconds,
302+
)
303+
304+
self.__forward_to_proto_unix_io(RobotStatus, robot_status)
305+
self.__forward_to_proto_unix_io(RobotStatistic, robot_statistic)
306+
291307
def __exit__(self, type, value, traceback) -> None:
292308
"""Exit RobotCommunication context manager
293309

src/software/thunderscope/robot_diagnostics/robot_info.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,21 @@ def create_vision_pattern(
292292

293293
return pixmap
294294

295-
def update(self, robot_status: RobotStatus, round_trip_time: RobotStatistic):
295+
def update(self, robot_status: RobotStatus, robot_statistic: RobotStatistic):
296296
"""Receives parts of a RobotStatus message
297297
298298
Saves the current time as the last robot status time
299299
Sets the robot UI as connected and updates the UI
300300
Then sets a timer callback to disconnect the robot if needed
301301
302302
:param robot_status: The robot status message for this robot
303-
:param round_trip_time: The round trip time proto for this robot's message
303+
:param robot_statistic: The round trip time proto for this robot's message
304304
"""
305305
self.time_of_last_robot_status = time.time()
306306

307307
self.robot_model.setPixmap(self.color_vision_pattern)
308308

309-
self.__update_ui(robot_status, round_trip_time)
309+
self.__update_ui(robot_status, robot_statistic)
310310

311311
QtCore.QTimer.singleShot(int(DISCONNECT_DURATION_MS), self.disconnect_robot)
312312

@@ -338,7 +338,7 @@ def __update_stop_primitive(self, is_running: bool) -> None:
338338
)
339339

340340
def __update_ui(
341-
self, robot_status: RobotStatus, round_trip_time: RobotStatistic
341+
self, robot_status: RobotStatus, robot_statistic: RobotStatistic
342342
) -> None:
343343
"""Receives important sections of RobotStatus proto for this robot and updates widget with alerts
344344
Checks for
@@ -349,13 +349,13 @@ def __update_ui(
349349
- If the robot is stopped or running
350350
351351
:param robot_status: The robot status message for this robot
352-
:param round_trip_time: The round trip time message for this robot
352+
:param robot_statistic: The round trip time message for this robot
353353
"""
354354
motor_status = robot_status.motor_status
355355
power_status = robot_status.power_status
356356
network_status = robot_status.network_status
357357
primitive_executor_status = robot_status.primitive_executor_status
358-
rtt_time_seconds = round_trip_time.round_trip_time_seconds
358+
rtt_time_seconds = robot_statistic.round_trip_time_seconds
359359

360360
self.__update_stop_primitive(primitive_executor_status.running_primitive)
361361

src/software/thunderscope/robot_diagnostics/robot_view.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,21 @@ def robot_status_expand(self) -> None:
6262
self.robot_status.toggle_visibility()
6363

6464
def update(
65-
self, robot_status: RobotStatus, round_trip_time: RobotStatistic
65+
self, robot_status: RobotStatus, robot_statistic: RobotStatistic
6666
) -> None:
6767
"""Updates the Robot View Components with the new robot status message
6868
Updates the robot info widget and, if initialized, the robot status widget as well
6969
7070
:param robot_status: the new message data to update the widget with
71-
:param round_trip_time: robot statistic proto to update with new metrics
71+
:param robot_statistic : robot statistic proto to update with new metrics
7272
"""
73-
self.robot_info.update(robot_status, round_trip_time)
74-
if self.robot_status:
75-
self.robot_status.update(robot_status)
73+
if robot_status is not None:
74+
self.robot_info.update(robot_status, robot_statistic)
75+
if self.robot_status:
76+
self.robot_status.update(robot_status)
77+
78+
if robot_statistic is not None:
79+
self.robot_info.update_rtt(robot_statistic)
7680

7781

7882
class RobotView(QScrollArea):
@@ -93,7 +97,7 @@ def __init__(self, available_control_modes: list[IndividualRobotMode]) -> None:
9397
super().__init__()
9498

9599
self.robot_status_buffer = ThreadSafeBuffer(10, RobotStatus)
96-
self.round_trip_time_buffer = ThreadSafeBuffer(10, RobotStatistic)
100+
self.robot_statistic_buffer = ThreadSafeBuffer(10, RobotStatistic)
97101

98102
self.layout = QVBoxLayout()
99103

@@ -121,11 +125,25 @@ def refresh(self) -> None:
121125
until the buffer is empty
122126
"""
123127
robot_status = self.robot_status_buffer.get(block=False, return_cached=False)
124-
round_trip_time = self.round_trip_time_buffer.get(
128+
robot_statistic = self.robot_statistic_buffer.get(
125129
block=False, return_cached=False
126130
)
127131

128-
if robot_status is not None and round_trip_time is not None:
132+
if (
133+
robot_status is not None
134+
and robot_statistic is not None
135+
and robot_status.robot_id == robot_statistic.robot_id
136+
): # if both pieces of data are available
129137
self.robot_view_widgets[robot_status.robot_id].update(
130-
robot_status, round_trip_time
138+
robot_status=robot_status, robot_statistic=robot_statistic
131139
)
140+
else:
141+
if robot_status is not None:
142+
self.robot_view_widgets[robot_status.robot_id].update(
143+
robot_status,
144+
robot_statistic=None,
145+
)
146+
if robot_statistic is not None:
147+
self.robot_view_widgets[robot_statistic.robot_id].update(
148+
robot_status=None, robot_statistic=robot_statistic
149+
)

src/software/thunderscope/widget_setup_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def setup_robot_view(
320320
"""
321321
robot_view = RobotView(available_control_modes)
322322
proto_unix_io.register_observer(RobotStatus, robot_view.robot_status_buffer)
323-
proto_unix_io.register_observer(RobotStatistic, robot_view.round_trip_time_buffer)
323+
proto_unix_io.register_observer(RobotStatistic, robot_view.robot_statistic_buffer)
324324
return robot_view
325325

326326

0 commit comments

Comments
 (0)