Skip to content

Commit 1853f8f

Browse files
committed
feat(ROS1): fix roslaunch_list and rosnode_kill tools.
1 parent 1b14bd7 commit 1853f8f

File tree

4 files changed

+48
-37
lines changed

4 files changed

+48
-37
lines changed

demo.sh

+3-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,9 @@ DEVELOPMENT=${DEVELOPMENT:-false}
2727

2828
# Enable X11 forwarding based on OS
2929
case "$(uname)" in
30-
Linux)
31-
echo "Enabling X11 forwarding for Linux..."
32-
export DISPLAY=:0
33-
xhost +local:docker
34-
;;
35-
Darwin)
36-
echo "Enabling X11 forwarding for macOS..."
37-
ip=$(ifconfig en0 | awk '$1=="inet" {print $2}')
38-
export DISPLAY=$ip:0
39-
xhost + $ip
30+
Linux*|Darwin*)
31+
echo "Enabling X11 forwarding..."
32+
xhost +
4033
;;
4134
MINGW*|CYGWIN*|MSYS*)
4235
echo "Enabling X11 forwarding for Windows..."

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dependencies = [
2929
"langchain-community==0.2.12",
3030
"langchain-core==0.2.34",
3131
"langchain-openai==0.1.22",
32-
"langchain-ollama",
32+
"langchain-ollama==0.1.3",
3333
"pydantic",
3434
"pyinputplus",
3535
"azure-identity",

src/rosa/tools/ros1.py

+42-25
Original file line numberDiff line numberDiff line change
@@ -738,43 +738,60 @@ def roslaunch(package: str, launch_file: str) -> str:
738738

739739

740740
@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.
743743
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.
745745
"""
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 = []
752748

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+
)
758774

775+
if not results:
759776
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,
764779
}
765780

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}
768782

769783

770784
@tool
771-
def rosnode_kill(node: str) -> str:
785+
def rosnode_kill(node_names: List[str]) -> dict:
772786
"""Kills a specific ROS node.
773787
774-
:param node: The name of the ROS node to kill.
788+
:param node_names: A list of node names to kill.
775789
"""
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+
776793
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)
779796
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}"}

src/turtle_agent/scripts/turtle_agent.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
from prompts import get_prompts
3636

3737

38+
# Typical method for defining tools in ROSA
3839
@tool
3940
def cool_turtle_tool():
40-
"""A cool turtle tool."""
41+
"""A cool turtle tool that doesn't really do anything."""
4142
return "This is a cool turtle tool! It doesn't do anything, but it's cool."
4243

4344

0 commit comments

Comments
 (0)