@@ -808,7 +808,7 @@ def cleanup():
808
808
):
809
809
prefix = ""
810
810
else :
811
- prefix = response .values [0 ].string_value + "."
811
+ prefix = response .values [0 ].string_value
812
812
813
813
cleanup ()
814
814
return True , prefix
@@ -826,31 +826,33 @@ def __joint_states_callback(self, msg: JointState) -> None:
826
826
if name in self .__articulated_joint_names :
827
827
self .__joint_states [name ] = msg .position [i ]
828
828
829
- def __get_robot_configurations (
829
+ def __get_robot_configurations_within_prefix (
830
830
self ,
831
+ prefix : str ,
832
+ configurations_parameter_names : List [str ],
831
833
rate_hz : float = 10.0 ,
832
834
timeout : Duration = Duration (seconds = 5 ),
833
835
publish_feedback : Optional [Callable [[], None ]] = None ,
834
- include_current_robot_config : bool = True ,
835
836
) -> Tuple [bool , Dict [str , List [float ]]]:
836
837
"""
837
- Get the robot's configurations.
838
+ Get the robot's configurations within a prefix .
838
839
839
840
Parameters
840
841
----------
842
+ prefix: The prefix to add to the parameter name.
843
+ configurations_parameter_names: The names of the parameters that contain robot
844
+ joint configurations that should be contained within the workspace walls.
841
845
rate_hz: The rate at which to call the service.
842
846
timeout: The timeout for the service.
843
847
publish_feedback: If not None, call this function periodically to publish feedback.
844
- include_current_robot_config: Whether to include the current robot configuration.
845
- This can override the value set in the parameter.
846
848
847
849
Returns
848
850
-------
849
851
success: True if successful, False otherwise.
850
852
robot_configurations: A map from the parameter name to the configuration.
851
853
"""
852
- # pylint: disable=too-many-locals, too-many-branches
853
- # A few above is fine
854
+ # pylint: disable=too-many-locals, too-many-arguments
855
+ # One over is fine.
854
856
855
857
# Start the time
856
858
start_time = self .__node .get_clock ().now ()
@@ -859,35 +861,11 @@ def __get_robot_configurations(
859
861
def cleanup ():
860
862
self .__node .destroy_rate (rate )
861
863
862
- # Get the prefix
863
- success , prefix = self .__get_parameter_prefix (
864
- rate_hz , get_remaining_time (self .__node , start_time , timeout )
865
- )
866
- if not success :
867
- self .__node .get_logger ().error ("Failed to get the parameter prefix." )
868
- cleanup ()
869
- return False , {}
870
-
871
- # Wait for the service to be ready
872
- self .__node .get_logger ().info (
873
- "Waiting for the get robot configurations parameter service."
874
- )
875
- while not self .__get_robot_configurations_parameter_service .service_is_ready ():
876
- if not check_ok (self .__node , start_time , timeout ):
877
- self .__node .get_logger ().error (
878
- "Timeout while waiting for the get robot configurations parameter service."
879
- )
880
- cleanup ()
881
- return False , {}
882
- if publish_feedback is not None :
883
- publish_feedback ()
884
- rate .sleep ()
885
-
886
864
# Get the robot configurations
887
865
robot_configurations = {}
888
866
request = GetParameters .Request ()
889
867
request .names = [
890
- prefix + name for name in self . __robot_configurations_parameter_names
868
+ "." . join ([ prefix , name ]) for name in configurations_parameter_names
891
869
]
892
870
self .__node .get_logger ().info (
893
871
f"Getting robot configurations from parameters: { request .names } "
@@ -916,7 +894,7 @@ def cleanup():
916
894
for i , param in enumerate (response .values ):
917
895
if param .type != ParameterType .PARAMETER_DOUBLE_ARRAY :
918
896
continue
919
- robot_configurations [self . __robot_configurations_parameter_names [i ]] = list (
897
+ robot_configurations [configurations_parameter_names [i ]] = list (
920
898
param .double_array_value
921
899
)
922
900
if publish_feedback is not None :
@@ -926,6 +904,96 @@ def cleanup():
926
904
cleanup ()
927
905
return False , {}
928
906
907
+ cleanup ()
908
+ return True , robot_configurations
909
+
910
+ def __get_robot_configurations (
911
+ self ,
912
+ rate_hz : float = 10.0 ,
913
+ timeout : Duration = Duration (seconds = 5 ),
914
+ publish_feedback : Optional [Callable [[], None ]] = None ,
915
+ include_current_robot_config : bool = True ,
916
+ ) -> Tuple [bool , Dict [str , List [float ]]]:
917
+ """
918
+ Get the robot's configurations.
919
+
920
+ Parameters
921
+ ----------
922
+ rate_hz: The rate at which to call the service.
923
+ timeout: The timeout for the service.
924
+ publish_feedback: If not None, call this function periodically to publish feedback.
925
+ include_current_robot_config: Whether to include the current robot configuration.
926
+ This can override the value set in the parameter.
927
+
928
+ Returns
929
+ -------
930
+ success: True if successful, False otherwise.
931
+ robot_configurations: A map from the parameter name to the configuration.
932
+ """
933
+ # pylint: disable=too-many-locals, too-many-branches
934
+ # A few above is fine
935
+
936
+ # Start the time
937
+ start_time = self .__node .get_clock ().now ()
938
+ rate = self .__node .create_rate (rate_hz )
939
+
940
+ def cleanup ():
941
+ self .__node .destroy_rate (rate )
942
+
943
+ # Get the prefix
944
+ success , prefix = self .__get_parameter_prefix (
945
+ rate_hz , get_remaining_time (self .__node , start_time , timeout )
946
+ )
947
+ if not success :
948
+ self .__node .get_logger ().error ("Failed to get the parameter prefix." )
949
+ cleanup ()
950
+ return False , {}
951
+
952
+ # Wait for the service to be ready
953
+ self .__node .get_logger ().info (
954
+ "Waiting for the get robot configurations parameter service."
955
+ )
956
+ while not self .__get_robot_configurations_parameter_service .service_is_ready ():
957
+ if not check_ok (self .__node , start_time , timeout ):
958
+ self .__node .get_logger ().error (
959
+ "Timeout while waiting for the get robot configurations parameter service."
960
+ )
961
+ cleanup ()
962
+ return False , {}
963
+ if publish_feedback is not None :
964
+ publish_feedback ()
965
+ rate .sleep ()
966
+
967
+ # Get the robot configurations
968
+ _ , robot_configurations = self .__get_robot_configurations_within_prefix (
969
+ prefix ,
970
+ self .__robot_configurations_parameter_names ,
971
+ rate_hz ,
972
+ get_remaining_time (self .__node , start_time , timeout ),
973
+ publish_feedback = publish_feedback ,
974
+ )
975
+ remaining_configurations_parameter_names = [
976
+ name
977
+ for name in self .__robot_configurations_parameter_names
978
+ if name not in robot_configurations
979
+ ]
980
+ _ , default_robot_configurations = self .__get_robot_configurations_within_prefix (
981
+ "default" ,
982
+ remaining_configurations_parameter_names ,
983
+ rate_hz ,
984
+ get_remaining_time (self .__node , start_time , timeout ),
985
+ publish_feedback = publish_feedback ,
986
+ )
987
+ robot_configurations .update (default_robot_configurations )
988
+ # If we got some but not all of them, raise an error but continue
989
+ if len (robot_configurations ) != len (
990
+ self .__robot_configurations_parameter_names
991
+ ):
992
+ self .__node .get_logger ().error ("Failed to get robot configurations." )
993
+ if len (robot_configurations ) == 0 :
994
+ cleanup ()
995
+ return False , {}
996
+
929
997
# Add the current joint state
930
998
if (
931
999
self .__workspace_walls_contain_current_robot_config
0 commit comments