Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: O3DE test benchmark #426

Merged
merged 55 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
9b3c256
refactor(partial): refactor openset tools to rai2.0 ros2ariconnector api
maciejmajek Feb 13, 2025
b1ba1cf
refactor: finalize with simplifications
maciejmajek Feb 13, 2025
647b14d
fix: missing argument, missing client
maciejmajek Feb 13, 2025
47edd91
workaround: don't remove subscription due to rclpy issue
boczekbartek Feb 13, 2025
6a9431e
replace ros2 future waiting with more robust callback based mechanism
boczekbartek Feb 13, 2025
7c6e84c
remove waiting from launch
boczekbartek Feb 13, 2025
0ba2d3f
fix order in connector shutdown
boczekbartek Feb 13, 2025
3d6ad0c
refactor: cleanup manipulation launchfile
boczekbartek Feb 13, 2025
b8eba34
chore: pre-commit
boczekbartek Feb 13, 2025
a678996
feat: benchmark class models
MagdalenaKotynia Feb 6, 2025
d9db9bd
feat: benchmark class models
MagdalenaKotynia Feb 6, 2025
5a4467e
adjust to new tools
jmatejcz Feb 13, 2025
aca52dd
Remove psutil conflicting __del__ method from o3de connector
boczekbartek Feb 13, 2025
51cc62a
stream langgraph agent
boczekbartek Feb 13, 2025
e69626c
extent output of tool runner
boczekbartek Feb 13, 2025
5ef20f2
enable all scenarios in the benchmark
boczekbartek Feb 13, 2025
a8525c8
feat: added client to arm manipulator to move arm between scenarios
jmatejcz Feb 17, 2025
00c64ef
feat: add GrabCarrot and RedCubes Tasks
jmatejcz Feb 19, 2025
4ed8ef1
refactor: getting initial and current objects positions separatly
jmatejcz Feb 19, 2025
3d0b192
style: added license
jmatejcz Feb 19, 2025
6765d5a
chore: delete old code
jmatejcz Feb 19, 2025
65878aa
reafactor: refactored red cube metric
jmatejcz Feb 19, 2025
a27ac37
refactor: refactored carrot metric
jmatejcz Feb 19, 2025
694cad3
feat: add entities mismatch exception
jmatejcz Feb 19, 2025
6300784
feat: add logger to task
jmatejcz Feb 19, 2025
580a0ee
feat: add counting time of scenario execution
jmatejcz Feb 19, 2025
695b163
chore: add readme, delete imgui file
jmatejcz Feb 20, 2025
1fa7dff
feat: moved configs to separate folder
jmatejcz Feb 20, 2025
29ec6e9
feat: benchmark takes bridge as arg
jmatejcz Feb 20, 2025
0c99911
chore: ignore o3de config
jmatejcz Feb 20, 2025
492acea
style: add notes to task and todos to scenario
jmatejcz Feb 20, 2025
71337e7
refactor: adjust to naming of Bridges changes
jmatejcz Feb 20, 2025
ceef23a
fix: adjust args passing in calculate_results
jmatejcz Feb 20, 2025
afe9112
style: moved tasks to separate folder, moved o3de benchmark to rai_be…
jmatejcz Feb 20, 2025
a8eac92
feat: add validation if scene is suitable for task
jmatejcz Feb 20, 2025
c1b4c75
feat: add way to automatically create scenarios
jmatejcz Feb 20, 2025
6017193
feat: variables in score calculations rename to better suit purpouse
jmatejcz Feb 20, 2025
7695a9a
feat: add storing results
jmatejcz Feb 20, 2025
e1d76d1
chore: add license
jmatejcz Feb 20, 2025
6fe1ab3
partially fixed getting position bug
jmatejcz Feb 20, 2025
323f3ed
fix: move tf_listener to constructor in ROS2ARIConnector
jmatejcz Feb 21, 2025
23374f5
fix: fix calculations with adjacent objects in Tasks
jmatejcz Feb 21, 2025
829617a
feat: add counting number of tool calls
jmatejcz Feb 21, 2025
a4b9760
chore: delete o3de config, remove from gitignore
jmatejcz Feb 21, 2025
84d922a
fix: update pyproject toml to include rai bench
jmatejcz Feb 21, 2025
abfa97e
formatting changes
jmatejcz Feb 24, 2025
09206e5
feat: added verification if required services , toipcs and actions ar…
jmatejcz Feb 24, 2025
4f11d20
refactor: funtions naming, typing and rotation of arm change
jmatejcz Feb 24, 2025
285817b
style: change of formatting
jmatejcz Feb 24, 2025
82ed909
docs: extended readme
jmatejcz Feb 25, 2025
458f882
fix: fix of wrong generic classes typing
MagdalenaKotynia Feb 25, 2025
b38d82d
style: delete unsed genric
jmatejcz Feb 25, 2025
fd19905
refactor: parametrized number of retries in checking robotic stack
jmatejcz Feb 25, 2025
16ae42a
style: add logs about how many scenarios left
jmatejcz Feb 25, 2025
2172967
feat: add dumping results to file
jmatejcz Feb 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,5 @@ logs/

src/examples/*-demo
artifact_database.pkl

imgui.ini
12 changes: 6 additions & 6 deletions examples/agriculture-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
import argparse

import rclpy
from rclpy.action import ActionClient
from rclpy.callback_groups import ReentrantCallbackGroup
from rclpy.executors import MultiThreadedExecutor
from rclpy.node import Node
from std_srvs.srv import Trigger

from rai.node import RaiStateBasedLlmNode, describe_ros_image
from rai.tools.ros.native import (
GetCameraImage,
Expand All @@ -24,12 +30,6 @@
Ros2ShowMsgInterfaceTool,
)
from rai.tools.time import WaitForSecondsTool
from rclpy.action import ActionClient
from rclpy.callback_groups import ReentrantCallbackGroup
from rclpy.executors import MultiThreadedExecutor
from rclpy.node import Node
from std_srvs.srv import Trigger

from rai_interfaces.action import Task


Expand Down
1 change: 1 addition & 0 deletions examples/manipulation-demo-streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import streamlit as st
from langchain_core.messages import AIMessage, HumanMessage, ToolMessage

from rai.agents.integrations.streamlit import get_streamlit_cb, streamlit_invoke
from rai.messages import HumanMultimodalMessage

Expand Down
49 changes: 5 additions & 44 deletions examples/manipulation-demo.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import rclpy
from launch import LaunchContext, LaunchDescription
from launch import LaunchDescription
from launch.actions import (
DeclareLaunchArgument,
ExecuteProcess,
IncludeLaunchDescription,
OpaqueFunction,
RegisterEventHandler,
)
from launch.event_handlers import OnExecutionComplete, OnProcessStart
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from rclpy.qos import QoSProfile, ReliabilityPolicy
from rosgraph_msgs.msg import Clock


def generate_launch_description():
Expand All @@ -46,21 +40,6 @@ def generate_launch_description():
output="screen",
)

def wait_for_clock_message(context: LaunchContext, *args, **kwargs):
rclpy.init()
node = rclpy.create_node("wait_for_game_launcher")
node.create_subscription(
Clock,
"/clock",
lambda msg: rclpy.shutdown(),
QoSProfile(depth=1, reliability=ReliabilityPolicy.BEST_EFFORT),
)
rclpy.spin(node)
return None

# Game launcher will start publishing the clock message after loading the simulation
wait_for_game_launcher = OpaqueFunction(function=wait_for_clock_message)

launch_moveit = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[
Expand All @@ -72,7 +51,7 @@ def wait_for_clock_message(context: LaunchContext, *args, **kwargs):
launch_robotic_manipulation = Node(
package="robotic_manipulation",
executable="robotic_manipulation",
name="robotic_manipulation_node",
# name="robotic_manipulation_node",
output="screen",
parameters=[
{"use_sim_time": True},
Expand All @@ -90,28 +69,10 @@ def wait_for_clock_message(context: LaunchContext, *args, **kwargs):

return LaunchDescription(
[
# Include the game_launcher argument
game_launcher_arg,
# Launch the game launcher and wait for it to load
launch_game_launcher,
RegisterEventHandler(
event_handler=OnProcessStart(
target_action=launch_game_launcher,
on_start=[
wait_for_game_launcher,
],
)
),
# Launch the MoveIt node after loading the simulation
RegisterEventHandler(
event_handler=OnExecutionComplete(
target_action=wait_for_game_launcher,
on_completion=[
launch_openset,
launch_moveit,
launch_robotic_manipulation,
],
)
),
launch_openset,
launch_moveit,
launch_robotic_manipulation,
]
)
21 changes: 11 additions & 10 deletions examples/manipulation-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,38 @@
# See the License for the specific language goveself.rning permissions and
# limitations under the License.

import threading

import rclpy
import rclpy.qos
from langchain_core.messages import HumanMessage
from rai_open_set_vision.tools import GetGrabbingPointTool

from rai.agents.conversational_agent import create_conversational_agent
from rai.node import RaiBaseNode
from rai.communication.ros2.connectors import ROS2ARIConnector
from rai.tools.ros.manipulation import GetObjectPositionsTool, MoveToPointTool
from rai.tools.ros.native import GetCameraImage, Ros2GetTopicsNamesAndTypesTool
from rai.tools.ros2.topics import GetROS2ImageTool, GetROS2TopicsNamesAndTypesTool
from rai.utils.model_initialization import get_llm_model


def create_agent():
rclpy.init()
node = RaiBaseNode(node_name="manipulation_demo")
connector = ROS2ARIConnector()
node = connector.node
node.declare_parameter("conversion_ratio", 1.0)

threading.Thread(target=node.spin).start()

tools = [
GetObjectPositionsTool(
node=node,
connector=connector,
target_frame="panda_link0",
source_frame="RGBDCamera5",
camera_topic="/color_image5",
depth_topic="/depth_image5",
camera_info_topic="/color_camera_info5",
get_grabbing_point_tool=GetGrabbingPointTool(connector=connector),
),
MoveToPointTool(node=node, manipulator_frame="panda_link0"),
GetCameraImage(node=node),
Ros2GetTopicsNamesAndTypesTool(node=node),
MoveToPointTool(connector=connector, manipulator_frame="panda_link0"),
GetROS2ImageTool(connector=connector),
GetROS2TopicsNamesAndTypesTool(connector=connector),
]

llm = get_llm_model(model_type="complex_model", streaming=True)
Expand Down
3 changes: 2 additions & 1 deletion examples/rosbot-xl-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import rclpy
import rclpy.executors
import rclpy.logging
from rai_open_set_vision.tools import GetDetectionTool, GetDistanceToObjectsTool

from rai.node import RaiStateBasedLlmNode
from rai.tools.ros.native import (
GetMsgFromTopic,
Expand All @@ -33,7 +35,6 @@
Ros2RunActionAsync,
)
from rai.tools.time import WaitForSecondsTool
from rai_open_set_vision.tools import GetDetectionTool, GetDistanceToObjectsTool

p = argparse.ArgumentParser()
p.add_argument("--allowlist", type=Path, required=False, default=None)
Expand Down
4 changes: 2 additions & 2 deletions examples/taxi-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_core.messages import BaseMessage, HumanMessage
from langchain_core.tools import tool
from std_msgs.msg import String

from rai.agents.conversational_agent import create_conversational_agent
from rai.tools.ros.cli import Ros2ServiceTool
from rai.tools.ros.native import Ros2PubMessageTool
from rai.utils.model_initialization import get_llm_model, get_tracing_callbacks
from std_msgs.msg import String

from rai_hmi.api import GenericVoiceNode, split_message

system_prompt = """
Expand Down
15 changes: 14 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rai = {path = "src/rai_core", develop = true}
rai_asr = {path = "src/rai_asr", develop = true}
rai_tts = {path = "src/rai_tts", develop = true}
rai_sim = {path = "src/rai_sim", develop = true}
rai_bench = {path = "src/rai_bench", develop = true}

langchain-core = "^0.3"
langchain = "*"
Expand All @@ -30,7 +31,6 @@ requests = "^2.32.2"
pre-commit = "^3.7.0"
openai = "^1.23.3"
coloredlogs = "^15.0.1"
opencv-python = "^4.9.0.80"
markdown = "^3.6"
boto3 = "^1.34.98"
tqdm = "^4.66.4"
Expand Down Expand Up @@ -62,6 +62,7 @@ pytest-timeout = "^2.3.1"
tomli-w = "^1.1.0"
faster-whisper = "^1.1.1"
pydub = "^0.25.1"
opencv-python = "^4.11.0.86"
[tool.poetry.group.dev.dependencies]
ipykernel = "^6.29.4"

Expand Down
3 changes: 3 additions & 0 deletions setup_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ esac

export PYTHONPATH
PYTHONPATH="$(dirname "$(dirname "$(poetry run which python)")")/lib/python$(poetry run python --version | awk '{print $2}' | cut -d. -f1,2)/site-packages:$PYTHONPATH"
PYTHONPATH="src/rai_core:$PYTHONPATH"
PYTHONPATH="src/rai_asr:$PYTHONPATH"
PYTHONPATH="src/rai_tts:$PYTHONPATH"
1 change: 1 addition & 0 deletions src/examples/turtlebot4/turtlebot_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import rclpy.qos
import rclpy.subscription
import rclpy.task

from rai.node import RaiStateBasedLlmNode
from rai.tools.ros.native import (
GetCameraImage,
Expand Down
60 changes: 60 additions & 0 deletions src/rai_bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## RAI Benchmark

## Description

The RAI Bench is a package including benchmarks and providing frame for creating new benchmarks

## Frame Components

Frame components can be found in `src/rai_bench/rai_bench/benchmark_model.py`

- `Task` - abstract class for creating specific task. It introduces helper funtions that make it easier to calculate metrics/scores. Your custom tasks must implement a prompt got agent to do, a way to calculate a result and a validation if given scene config suits the task.
-
- `Scenario` - class defined by a Scene and Task. Can be created manually like:

```python

```

- `Benchmark` - class responsible for running and logging scenarios.

### O3DE TEST BENCHMARK

O3DE Test Benchmark (src/rai_bench/rai_bench/o3de_test_bench/), contains 2 Tasks(tasks/) - GrabCarrotTask and PlaceCubesTask (these tasks implement calculating scores) and 4 scene_configs(configs/) for O3DE robotic arm simulation.

Both tasks calculate score, taking into consideration 4 values:

- initially_misplaced_now_correct - when the object which was in the incorrect place at the start, is in a correct place at the end
- initially_misplaced_still_incorrect - when the object which was in the incorrect place at the start, is in a incorrect place at the end
- initially_correct_still_correct - when the object which was in the correct place at the start, is in a correct place at the end
- initially_correct_now_incorrect - when the object which was in the correct place at the start, is in a incorrect place at the end

The result is a value between 0 and 1, calculated like (initially_misplaced_now_correct + initially_correct_still_correct) / number_of_initial_objects.
This score is calculated at the beggining and at the end of each scenario.

### Example usage

Example of how to load scenes, define scenarios and run benchmark can be found in `src/rai_bench/rai_bench/benchmark_main.py`

Scenarios can be loaded manually like:

```python
one_carrot_simulation_config = O3DExROS2SimulationConfig.load_config(
base_config_path=Path("path_to_scene.yaml"),
connector_config_path=Path("path_to_o3de_config.yaml"),
)

Scenario(task=GrabCarrotTask(logger=some_logger), simulation_config=one_carrot_simulation_config)
```

or automatically like:

```python
scenarios = Benchmark.create_scenarios(
tasks=tasks, simulation_configs=simulations_configs
)
```

which will result in list of scenarios with combination of every possible task and scene(task decides if scene config is suitable for it).

Both approaches can be found in `main.py`
17 changes: 17 additions & 0 deletions src/rai_bench/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "rai-bench"
version = "0.1.0"
description = ""
authors = ["jmatejcz <[email protected]>"]
readme = "README.md"

packages = [
{ include = "rai_bench", from = "." },
]
[tool.poetry.dependencies]
python = "^3.10"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Loading