Skip to content

Commit

Permalink
add param type_check
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil-Singhal-06 committed Oct 15, 2024
1 parent 80d5489 commit 35ff68b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
4 changes: 4 additions & 0 deletions docs/libraries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,10 @@ Check the latency of the specified topic (in system time). If the check with ``c
- ``string``
-
- Class of message type, only required when 'wait_for_first_message' is set to false (e.g. ``std_msgs.msg.String``)
* - ``type_check``
- ``bool``
- ``true``
- If False, the action will not verify that the topic type matches the specified type.


``bag_play()``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@

class AssertTopicLatency(BaseAction):

def __init__(self, topic_name: str, topic_type: str, wait_for_first_message: bool):
def __init__(self, topic_name: str, topic_type: str, wait_for_first_message: bool, type_check: bool):
super().__init__()
self.topic_name = topic_name
self.topic_type = topic_type
self.type_check = type_check
self.latency = None
self.comparison_operator_feedback = None
self.comparison_operator = None
Expand Down Expand Up @@ -112,32 +113,36 @@ def update(self) -> py_trees.common.Status:
return result

def check_topic(self):
if self.wait_for_first_message:
available_topics = self.node.get_topic_names_and_types()
for name, topic_type in available_topics:
if name == self.topic_name:
topic_type = topic_type[0].replace('/', '.')
if self.topic_type:
if self.topic_type == topic_type:
self.call_subscriber()
self.is_topic = True
return True
else:
return False # Invalid topic or type speficied.
else:
self.topic_type = topic_type
self.call_subscriber()
self.is_topic = True # 'topic_type' is not specified, the process will continue with the found one
return True
# Topic not available wait....
return True
else:
result = True
if not self.wait_for_first_message:
if not self.topic_type:
return False # Topic type must be specified. (wait_for_first_message == False)
result = False # Topic type must be specified. (wait_for_first_message == False)
else:
self.call_subscriber()
self.is_topic = True # wait_for_first_message' is set to false, the process will proceed with the specified topic and type
return True
else:
available_topics = self.node.get_topic_names_and_types()
topic_found = False
for name, topic_types in available_topics:
if name == self.topic_name:
topic_found = True
if not topic_types:
result = False
break
current_topic_type = topic_types[0].replace('/', '.')
if not self.topic_type:
self.topic_type = current_topic_type # 'topic_type' is not specified, the process will continue with the found one
self.call_subscriber()
self.is_topic = True
elif self.type_check and self.topic_type != current_topic_type:
result = False
else:
self.call_subscriber()
self.is_topic = True
break
if not topic_found:
pass # Topic not available wait....
return result

def call_subscriber(self):
datatype_in_list = self.topic_type.split(".")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ action assert_topic_latency:
rolling_average_count: int = 1 # the check is done aganist the rolling average over x elements
wait_for_first_message: bool = true # start measuring with the first received message
topic_type: string # class of message type, only required when wait_for_first_message is set to false (e.g. std_msgs.msg.String)
type_check: bool = true # If False, the action will not verify that the topic type matches the specified type.

action bag_play:
# play back a ros bag
Expand Down

0 comments on commit 35ff68b

Please sign in to comment.