@@ -738,43 +738,60 @@ def roslaunch(package: str, launch_file: str) -> str:
738
738
739
739
740
740
@tool
741
- def roslaunch_list (package : str ) -> dict :
742
- """Returns a list of available ROS launch files in a package .
741
+ def roslaunch_list (packages : List [ str ] ) -> dict :
742
+ """Returns a list of available ROS launch files in the specified packages .
743
743
744
- :param package: The name of the ROS package to list launch files for.
744
+ :param packages: A list of ROS package names to list launch files for.
745
745
"""
746
- try :
747
- rospack = rospkg .RosPack ()
748
- directory = rospack .get_path (package )
749
- launch = os .path .join (directory , "launch" )
750
-
751
- launch_files = []
746
+ results = {}
747
+ errors = []
752
748
753
- # Get all files in the launch directory
754
- if os .path .exists (launch ):
755
- launch_files = [
756
- f for f in os .listdir (launch ) if os .path .isfile (os .path .join (launch , f ))
757
- ]
749
+ rospack = rospkg .RosPack ()
750
+ for package in packages :
751
+ try :
752
+ directory = rospack .get_path (package )
753
+ launch = os .path .join (directory , "launch" )
754
+
755
+ launch_files = []
756
+
757
+ # Get all files in the launch directory
758
+ if os .path .exists (launch ):
759
+ launch_files = [
760
+ f
761
+ for f in os .listdir (launch )
762
+ if os .path .isfile (os .path .join (launch , f ))
763
+ ]
764
+
765
+ results [package ] = {
766
+ "directory" : directory ,
767
+ "total" : len (launch_files ),
768
+ "launch_files" : launch_files ,
769
+ }
770
+ except Exception as e :
771
+ errors .append (
772
+ f"Failed to get ROS launch files for package '{ package } ': { e } "
773
+ )
758
774
775
+ if not results :
759
776
return {
760
- "package" : package ,
761
- "directory" : directory ,
762
- "total" : len (launch_files ),
763
- "launch_files" : launch_files ,
777
+ "error" : "Failed to get ROS launch files for all specified packages." ,
778
+ "details" : errors ,
764
779
}
765
780
766
- except Exception as e :
767
- return {"error" : f"Failed to get ROS launch files in package '{ package } ': { e } " }
781
+ return {"results" : results , "errors" : errors }
768
782
769
783
770
784
@tool
771
- def rosnode_kill (node : str ) -> str :
785
+ def rosnode_kill (node_names : List [ str ] ) -> dict :
772
786
"""Kills a specific ROS node.
773
787
774
- :param node: The name of the ROS node to kill.
788
+ :param node_names: A list of node names to kill.
775
789
"""
790
+ if not node_names or len (node_names ) == 0 :
791
+ return {"error" : "Please provide the name(s) of the ROS node to kill." }
792
+
776
793
try :
777
- os . system ( f"rosnode kill { node } " )
778
- return f"Killed ROS node ' { node } '."
794
+ successes , failures = rosnode . kill_nodes ( node_names )
795
+ return dict ( successesfully_killed = successes , failed_to_kill = failures )
779
796
except Exception as e :
780
- return f"Failed to kill ROS node ' { node } ' : { e } "
797
+ return { "error" : f"Failed to kill ROS node(s) : { e } " }
0 commit comments