|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 | import importlib |
| 16 | +import sys |
| 17 | +from pathlib import Path |
16 | 18 |
|
| 19 | +import rclpy |
17 | 20 | import streamlit as st |
18 | 21 | from langchain_core.messages import AIMessage, HumanMessage, ToolMessage |
| 22 | +from launch import LaunchDescription |
| 23 | +from launch.actions import ( |
| 24 | + IncludeLaunchDescription, |
| 25 | +) |
| 26 | +from launch.launch_description_sources import PythonLaunchDescriptionSource |
| 27 | +from launch_ros.actions import Node |
| 28 | +from launch_ros.substitutions import FindPackageShare |
19 | 29 | from rai.agents.integrations.streamlit import get_streamlit_cb, streamlit_invoke |
| 30 | +from rai.communication.ros2.connectors.ros2_connector import ROS2Connector |
20 | 31 | from rai.messages import HumanMultimodalMessage |
21 | 32 |
|
| 33 | +from rai_bench.manipulation_o3de import get_scenarios |
| 34 | +from rai_bench.manipulation_o3de.benchmark import Scenario |
| 35 | +from rai_sim.o3de.o3de_bridge import ( |
| 36 | + O3DEngineArmManipulationBridge, |
| 37 | + O3DExROS2SimulationConfig, |
| 38 | +) |
| 39 | +from rai_sim.simulation_bridge import SceneConfig |
| 40 | + |
22 | 41 | manipulation_demo = importlib.import_module("manipulation-demo") |
23 | 42 |
|
24 | 43 |
|
| 44 | +def launch_description(): |
| 45 | + launch_moveit = IncludeLaunchDescription( |
| 46 | + PythonLaunchDescriptionSource( |
| 47 | + [ |
| 48 | + "src/examples/rai-manipulation-demo/Project/Examples/panda_moveit_config_demo.launch.py", |
| 49 | + ] |
| 50 | + ) |
| 51 | + ) |
| 52 | + |
| 53 | + launch_robotic_manipulation = Node( |
| 54 | + package="robotic_manipulation", |
| 55 | + executable="robotic_manipulation", |
| 56 | + output="screen", |
| 57 | + parameters=[ |
| 58 | + {"use_sim_time": True}, |
| 59 | + ], |
| 60 | + ) |
| 61 | + |
| 62 | + launch_openset = IncludeLaunchDescription( |
| 63 | + PythonLaunchDescriptionSource( |
| 64 | + [ |
| 65 | + FindPackageShare("rai_bringup"), |
| 66 | + "/launch/openset.launch.py", |
| 67 | + ] |
| 68 | + ), |
| 69 | + ) |
| 70 | + |
| 71 | + return LaunchDescription( |
| 72 | + [ |
| 73 | + launch_openset, |
| 74 | + launch_moveit, |
| 75 | + launch_robotic_manipulation, |
| 76 | + ] |
| 77 | + ) |
| 78 | + |
| 79 | + |
| 80 | +@st.cache_resource |
| 81 | +def init_ros(): |
| 82 | + rclpy.init() |
| 83 | + return "ros" |
| 84 | + |
| 85 | + |
25 | 86 | @st.cache_resource |
26 | 87 | def initialize_graph(): |
27 | 88 | return manipulation_demo.create_agent() |
28 | 89 |
|
29 | 90 |
|
30 | | -def main(): |
| 91 | +@st.cache_resource |
| 92 | +def initialize_o3de(scenario_path: str, o3de_config_path: str): |
| 93 | + simulation_config = O3DExROS2SimulationConfig.load_config( |
| 94 | + config_path=Path(o3de_config_path) |
| 95 | + ) |
| 96 | + scene_config = SceneConfig.load_base_config(Path(scenario_path)) |
| 97 | + scenario = Scenario( |
| 98 | + task=None, |
| 99 | + scene_config=scene_config, |
| 100 | + scene_config_path=scenario_path, |
| 101 | + ) |
| 102 | + o3de = O3DEngineArmManipulationBridge(ROS2Connector()) |
| 103 | + o3de.init_simulation(simulation_config=simulation_config) |
| 104 | + o3de.launch_robotic_stack( |
| 105 | + required_robotic_ros2_interfaces=simulation_config.required_robotic_ros2_interfaces, |
| 106 | + launch_description=launch_description(), |
| 107 | + ) |
| 108 | + o3de.setup_scene(scenario.scene_config) |
| 109 | + |
| 110 | + |
| 111 | +def main(scenario: Scenario, simulation_config: O3DExROS2SimulationConfig): |
31 | 112 | st.set_page_config( |
32 | 113 | page_title="RAI Manipulation Demo", |
33 | 114 | page_icon=":robot:", |
34 | 115 | ) |
35 | 116 | st.title("RAI Manipulation Demo") |
36 | 117 | st.markdown("---") |
37 | | - |
38 | 118 | st.sidebar.header("Tool Calls History") |
39 | 119 |
|
| 120 | + if "ros" not in st.session_state: |
| 121 | + ros = init_ros() |
| 122 | + st.session_state["ros"] = ros |
| 123 | + |
| 124 | + if "o3de" not in st.session_state: |
| 125 | + o3de = initialize_o3de(scenario, simulation_config) |
| 126 | + st.session_state["o3de"] = o3de |
| 127 | + |
40 | 128 | if "graph" not in st.session_state: |
41 | 129 | graph = initialize_graph() |
42 | 130 | st.session_state["graph"] = graph |
@@ -70,4 +158,26 @@ def main(): |
70 | 158 |
|
71 | 159 |
|
72 | 160 | if __name__ == "__main__": |
73 | | - main() |
| 161 | + levels = [ |
| 162 | + "medium", |
| 163 | + "hard", |
| 164 | + "very_hard", |
| 165 | + ] |
| 166 | + scenarios: list[Scenario] = get_scenarios(levels=levels) |
| 167 | + scenario_names = [Path(s.scene_config_path).stem for s in scenarios] |
| 168 | + print(scenario_names) |
| 169 | + |
| 170 | + if len(sys.argv) > 1: |
| 171 | + layout = sys.argv[1] |
| 172 | + if layout not in scenario_names: |
| 173 | + raise ValueError(f"Invalid layout: {layout}. Select from {scenario_names}") |
| 174 | + else: |
| 175 | + layout = "3carrots_1a_1t_2bc_2yc" |
| 176 | + o3de_config_path = ( |
| 177 | + "src/rai_bench/rai_bench/manipulation_o3de/predefined/configs/o3de_config.yaml" |
| 178 | + ) |
| 179 | + |
| 180 | + scenario_idx = scenario_names.index(layout) |
| 181 | + scenario = str(scenarios[scenario_idx].scene_config_path) |
| 182 | + |
| 183 | + main(scenario, o3de_config_path) |
0 commit comments