From 4c78a9ce67f9d653f375148077b172c8c8ac5bf8 Mon Sep 17 00:00:00 2001 From: Haiwei L Date: Thu, 25 Jul 2024 00:29:47 +0100 Subject: [PATCH] Reformat --- .../lasr_person_following/person_following.py | 6 +- .../src/carry_my_luggage/state_machine.py | 18 ++- .../gpsr/src/gpsr/states/object_comparison.py | 123 +++++++++++++++++- .../receptionist/states/speech_recovery.py | 36 +++-- 4 files changed, 162 insertions(+), 21 deletions(-) diff --git a/common/navigation/lasr_person_following/src/lasr_person_following/person_following.py b/common/navigation/lasr_person_following/src/lasr_person_following/person_following.py index 06f3a278..208ee368 100644 --- a/common/navigation/lasr_person_following/src/lasr_person_following/person_following.py +++ b/common/navigation/lasr_person_following/src/lasr_person_following/person_following.py @@ -350,7 +350,11 @@ def _check_finished(self) -> bool: ) transcription = self._transcribe_speech_client.get_result().sequence - return "yes" in transcription.lower() or "arrived" in transcription.lower() or "arrive" in transcription.lower() + return ( + "yes" in transcription.lower() + or "arrived" in transcription.lower() + or "arrive" in transcription.lower() + ) return True def _get_pose_on_path( diff --git a/tasks/carry_my_luggage/src/carry_my_luggage/state_machine.py b/tasks/carry_my_luggage/src/carry_my_luggage/state_machine.py index a04048e5..8669c160 100644 --- a/tasks/carry_my_luggage/src/carry_my_luggage/state_machine.py +++ b/tasks/carry_my_luggage/src/carry_my_luggage/state_machine.py @@ -193,11 +193,19 @@ def wait_cb(ud, msg): def start_pose_cb(ud): try: - ud.start_pose = rospy.wait_for_message("/robot_pose", PoseWithCovarianceStamped, timeout=rospy.Duration(5.0)).pose.pose + ud.start_pose = rospy.wait_for_message( + "/robot_pose", + PoseWithCovarianceStamped, + timeout=rospy.Duration(5.0), + ).pose.pose except rospy.ROSException: rospy.logerr("Failed to get robot pose") - ud.start_pose = Pose(position=Point(0., 0., 0.0), orientation=Quaternion(0., 0., 0., 1.)) + ud.start_pose = Pose( + position=Point(0.0, 0.0, 0.0), + orientation=Quaternion(0.0, 0.0, 0.0, 1.0), + ) return "succeeded" + smach.StateMachine.add( "GET_START_LOCATION", smach.CBState( @@ -205,7 +213,7 @@ def start_pose_cb(ud): outcomes=["succeeded"], output_keys=["start_pose"], ), - transitions={"succeeded": "SAY_STEP"} + transitions={"succeeded": "SAY_STEP"}, ) smach.StateMachine.add( @@ -261,8 +269,8 @@ def start_pose_cb(ud): ) smach.StateMachine.add( - "GO_TO_START", # todo: instead, get the start position within the state machine, and return to it at the end + "GO_TO_START", # todo: instead, get the start position within the state machine, and return to it at the end GoToLocation(), - remapping={"location" : "start_pose"}, + remapping={"location": "start_pose"}, transitions={"succeeded": "succeeded", "failed": "succeeded"}, ) diff --git a/tasks/gpsr/src/gpsr/states/object_comparison.py b/tasks/gpsr/src/gpsr/states/object_comparison.py index 4b82afe1..e5fdc376 100755 --- a/tasks/gpsr/src/gpsr/states/object_comparison.py +++ b/tasks/gpsr/src/gpsr/states/object_comparison.py @@ -19,16 +19,133 @@ class ObjectComparison(smach.StateMachine): # TODO: fill this in - _smallest_list: List[str] = ["dishwasher_tab", "candle", "strawberry", "tictac", "plum", "lemon", "pear", "peach", "orange", "apple", "sponges", "fork", "knife", "spoon", "banana", "dubbelfris", "cola", "ice_tea", "fanta", "milk", "pea_soup", "sausages", "cup", "stroopwafel", "soap", "curry", "water", "crisps", "liquorice", "candy", "hagelslag", "pancake_mix", "mayonaise", "bowl", "plate", "washcloth", "pringles", "big_coke" ] + _smallest_list: List[str] = [ + "dishwasher_tab", + "candle", + "strawberry", + "tictac", + "plum", + "lemon", + "pear", + "peach", + "orange", + "apple", + "sponges", + "fork", + "knife", + "spoon", + "banana", + "dubbelfris", + "cola", + "ice_tea", + "fanta", + "milk", + "pea_soup", + "sausages", + "cup", + "stroopwafel", + "soap", + "curry", + "water", + "crisps", + "liquorice", + "candy", + "hagelslag", + "pancake_mix", + "mayonaise", + "bowl", + "plate", + "washcloth", + "pringles", + "big_coke", + ] _biggest_list: List[str] = reversed(_smallest_list) _largest_list: List[str] = _biggest_list - _heaviest_list: List[str] = ["big_coke", "pea_soup", "milk", "mayonaise", "cola", "ice_tea", "fanta", "dubbelfris", "water", "pancake_mix", "curry", "soap", "sausages", "apple", "orange", "peach", "pear", "lemon", "plum", "banana", "stroopwafel", "cup", "bowl", "plate", "washcloth", "sponges", "pringles", "crisps", "hagelslag", "liquorice", "candy", "knife", "fork", "spoon", "candle", "strawberry", "tictac", "dishwasher_tab"] + _heaviest_list: List[str] = [ + "big_coke", + "pea_soup", + "milk", + "mayonaise", + "cola", + "ice_tea", + "fanta", + "dubbelfris", + "water", + "pancake_mix", + "curry", + "soap", + "sausages", + "apple", + "orange", + "peach", + "pear", + "lemon", + "plum", + "banana", + "stroopwafel", + "cup", + "bowl", + "plate", + "washcloth", + "sponges", + "pringles", + "crisps", + "hagelslag", + "liquorice", + "candy", + "knife", + "fork", + "spoon", + "candle", + "strawberry", + "tictac", + "dishwasher_tab", + ] _lightest_list: List[str] = reversed(_heaviest_list) - _thinnest_list: List[str] = ["knife", "fork", "spoon", "candle", "strawberry", "tictac", "dishwasher_tab", "liquorice", "candy", "crisps", "stroopwafel", "soap", "sponges", "washcloth", "plate", "bowl", "cup", "pancake_mix", "hagelslag", "curry", "mayonaise", "pea_soup", "sausages", "milk", "water", "dubbelfris", "cola", "ice_tea", "fanta", "big_coke", "apple", "orange", "peach", "pear", "lemon", "plum", "banana", "pringles"] + _thinnest_list: List[str] = [ + "knife", + "fork", + "spoon", + "candle", + "strawberry", + "tictac", + "dishwasher_tab", + "liquorice", + "candy", + "crisps", + "stroopwafel", + "soap", + "sponges", + "washcloth", + "plate", + "bowl", + "cup", + "pancake_mix", + "hagelslag", + "curry", + "mayonaise", + "pea_soup", + "sausages", + "milk", + "water", + "dubbelfris", + "cola", + "ice_tea", + "fanta", + "big_coke", + "apple", + "orange", + "peach", + "pear", + "lemon", + "plum", + "banana", + "pringles", + ] _query: Literal[ "biggest", "largest", "smallest", "heaviest", "lightest", "thinnest" diff --git a/tasks/receptionist/src/receptionist/states/speech_recovery.py b/tasks/receptionist/src/receptionist/states/speech_recovery.py index 478be81c..3fdf91cd 100644 --- a/tasks/receptionist/src/receptionist/states/speech_recovery.py +++ b/tasks/receptionist/src/receptionist/states/speech_recovery.py @@ -18,7 +18,7 @@ def __init__( last_resort: bool, input_type: str = "", ): - """Recover the correct name and / or drink by parsing the transcription. + """Recover the correct name and / or drink by parsing the transcription. Args: guest_id (str): ID of the guest (identifying the guest) @@ -26,7 +26,7 @@ def __init__( input_type (str, optional): The type of information to try and extract useful information (drink or name) """ - + smach.State.__init__( self, outcomes=["succeeded", "failed"], @@ -186,8 +186,8 @@ def _handle_name(self, sentence_list: List[str], last_resort: bool) -> str: return self._handle_closest_spelt(sentence_list, self._available_names) def _handle_drink(self, sentence_list: List[str], last_resort: bool) -> str: - """Attempt to recover the drink in the transcription. For phrases containing two words, try to infer the - second word in the phrase. If this fails, attempt to recover the drink via spelling, then pronounciation. + """Attempt to recover the drink in the transcription. For phrases containing two words, try to infer the + second word in the phrase. If this fails, attempt to recover the drink via spelling, then pronounciation. Enter last resort if necessary and recover the closest spelt drink. Args: @@ -233,9 +233,14 @@ def _handle_drink(self, sentence_list: List[str], last_resort: bool) -> str: sentence_list.append(closest_spelt) return self._infer_second_drink(sentence_list) - def _handle_similar_spelt(self, sentence_list: List[str], available_words: List[str], distance_threshold: int) -> str: - """Recover any word by spelling that has a similarity lower than the specified threshold - when comparing each word in the sentence list to the list of available words. + def _handle_similar_spelt( + self, + sentence_list: List[str], + available_words: List[str], + distance_threshold: int, + ) -> str: + """Recover any word by spelling that has a similarity lower than the specified threshold + when comparing each word in the sentence list to the list of available words. Args: sentence_list (List[str]): Transcription split up as a list of strings. @@ -254,9 +259,14 @@ def _handle_similar_spelt(self, sentence_list: List[str], available_words: List[ return available_word return "unknown" - def _handle_similar_sound(self, sentence_list: List[str], available_words: List[str], distance_threshold: int) -> str: - """Recover any word by pronounciation that has a similarity lower than the specified threshold - when comparing each word in the sentence list to the list of available words. + def _handle_similar_sound( + self, + sentence_list: List[str], + available_words: List[str], + distance_threshold: int, + ) -> str: + """Recover any word by pronounciation that has a similarity lower than the specified threshold + when comparing each word in the sentence list to the list of available words. Args: sentence_list (List[str]): Transcription split up as a list of strings. @@ -292,8 +302,10 @@ def _infer_second_drink(self, sentence_list: List[str]) -> str: return self._double_drinks_dict[input_word] return "unknown" - def _handle_closest_spelt(self, sentence_list: List[str], choices: List[str]) -> str: - """Get the closest spelt word from the list of choices (drinks or names) + def _handle_closest_spelt( + self, sentence_list: List[str], choices: List[str] + ) -> str: + """Get the closest spelt word from the list of choices (drinks or names) in the sentence list (transcription). Args: