From e68d1f723f4f48821963df11c0cc6147636cbcb6 Mon Sep 17 00:00:00 2001 From: Michael Jeronimo Date: Mon, 18 Apr 2022 14:04:49 -0700 Subject: [PATCH] Fix fixed-size Array visualization (#81) * Fix fixed-size Array visualization Don't assume that has_maximum_size means that a maximum_size field exists on the object. In the case of an Array object, has_maximum_size is True, but there is no 'maximum_size' field, only 'size'. Fixes: #77 Signed-off-by: Michael Jeronimo * Update src/rqt_plot/plot_widget.py Co-authored-by: Chris Lalancette Co-authored-by: Chris Lalancette --- src/rqt_plot/plot_widget.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rqt_plot/plot_widget.py b/src/rqt_plot/plot_widget.py index 189c9b9..a064512 100644 --- a/src/rqt_plot/plot_widget.py +++ b/src/rqt_plot/plot_widget.py @@ -122,12 +122,16 @@ def get_plot_fields(node, topic_name): if is_array_or_sequence: if not has_index: - return [], base_error_msg + f'{name} is a nested type but not index provided' + return [], base_error_msg + f'{name} is a nested type but no index provided' + if current_type.has_maximum_size(): - if index >= current_type.maximum_size: + # has_maximum_size() doesn't necessarily mean that the object has a 'maximum_size' field. The meaning + # appears to be that the object is bounded in its size and has either a 'maximum_size' or 'size' field. + size = current_type.maximum_size if hasattr(current_type, 'maximum_size') else current_type.size + if index >= size: return [], ( base_error_msg + - f"index '{index}' out of bounds, maximum size is {current_type.maximum_size}") + f"index '{index}' out of bounds, maximum size is {size}") current_type = current_type.value_type elif has_index: return [], base_error_msg + "{name} is not an array or sequence"