Skip to content

Commit

Permalink
feat(ROS1): fix roslaunch_list and rosnode_kill tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobRoyce committed Oct 7, 2024
1 parent 1b14bd7 commit 1853f8f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 37 deletions.
13 changes: 3 additions & 10 deletions demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,9 @@ DEVELOPMENT=${DEVELOPMENT:-false}

# Enable X11 forwarding based on OS
case "$(uname)" in
Linux)
echo "Enabling X11 forwarding for Linux..."
export DISPLAY=:0
xhost +local:docker
;;
Darwin)
echo "Enabling X11 forwarding for macOS..."
ip=$(ifconfig en0 | awk '$1=="inet" {print $2}')
export DISPLAY=$ip:0
xhost + $ip
Linux*|Darwin*)
echo "Enabling X11 forwarding..."
xhost +
;;
MINGW*|CYGWIN*|MSYS*)
echo "Enabling X11 forwarding for Windows..."
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"langchain-community==0.2.12",
"langchain-core==0.2.34",
"langchain-openai==0.1.22",
"langchain-ollama",
"langchain-ollama==0.1.3",
"pydantic",
"pyinputplus",
"azure-identity",
Expand Down
67 changes: 42 additions & 25 deletions src/rosa/tools/ros1.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,43 +738,60 @@ def roslaunch(package: str, launch_file: str) -> str:


@tool
def roslaunch_list(package: str) -> dict:
"""Returns a list of available ROS launch files in a package.
def roslaunch_list(packages: List[str]) -> dict:
"""Returns a list of available ROS launch files in the specified packages.
:param package: The name of the ROS package to list launch files for.
:param packages: A list of ROS package names to list launch files for.
"""
try:
rospack = rospkg.RosPack()
directory = rospack.get_path(package)
launch = os.path.join(directory, "launch")

launch_files = []
results = {}
errors = []

# Get all files in the launch directory
if os.path.exists(launch):
launch_files = [
f for f in os.listdir(launch) if os.path.isfile(os.path.join(launch, f))
]
rospack = rospkg.RosPack()
for package in packages:
try:
directory = rospack.get_path(package)
launch = os.path.join(directory, "launch")

launch_files = []

# Get all files in the launch directory
if os.path.exists(launch):
launch_files = [
f
for f in os.listdir(launch)
if os.path.isfile(os.path.join(launch, f))
]

results[package] = {
"directory": directory,
"total": len(launch_files),
"launch_files": launch_files,
}
except Exception as e:
errors.append(
f"Failed to get ROS launch files for package '{package}': {e}"
)

if not results:
return {
"package": package,
"directory": directory,
"total": len(launch_files),
"launch_files": launch_files,
"error": "Failed to get ROS launch files for all specified packages.",
"details": errors,
}

except Exception as e:
return {"error": f"Failed to get ROS launch files in package '{package}': {e}"}
return {"results": results, "errors": errors}


@tool
def rosnode_kill(node: str) -> str:
def rosnode_kill(node_names: List[str]) -> dict:
"""Kills a specific ROS node.
:param node: The name of the ROS node to kill.
:param node_names: A list of node names to kill.
"""
if not node_names or len(node_names) == 0:
return {"error": "Please provide the name(s) of the ROS node to kill."}

try:
os.system(f"rosnode kill {node}")
return f"Killed ROS node '{node}'."
successes, failures = rosnode.kill_nodes(node_names)
return dict(successesfully_killed=successes, failed_to_kill=failures)
except Exception as e:
return f"Failed to kill ROS node '{node}': {e}"
return {"error": f"Failed to kill ROS node(s): {e}"}
3 changes: 2 additions & 1 deletion src/turtle_agent/scripts/turtle_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
from prompts import get_prompts


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


Expand Down

0 comments on commit 1853f8f

Please sign in to comment.