Skip to content

Commit 09206e5

Browse files
committed
feat: added verification if required services , toipcs and actions are available
1 parent abfa97e commit 09206e5

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

src/rai_extensions/rai_open_set_vision/rai_open_set_vision/services/grounded_sam.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
class GSamService(Node):
3535
def __init__(self):
3636
super().__init__(node_name=GSAM_NODE_NAME, parameter_overrides=[])
37-
self.srv = self.create_service(
38-
RAIGroundedSam, GSAM_SERVICE_NAME, self.segment_callback
39-
)
4037

4138
self.declare_parameter("weights_path", "")
4239
try:
@@ -49,6 +46,10 @@ def __init__(self):
4946
self.get_logger().error("Could not load model")
5047
raise Exception("Could not load model")
5148

49+
self.srv = self.create_service(
50+
RAIGroundedSam, GSAM_SERVICE_NAME, self.segment_callback
51+
)
52+
5253
def _init_weight_path(self):
5354
try:
5455
found_path = get_package_share_directory("rai_open_set_vision")

src/rai_extensions/rai_open_set_vision/rai_open_set_vision/services/grounding_dino.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ class GDRequest(TypedDict):
4343
class GDinoService(Node):
4444
def __init__(self):
4545
super().__init__(node_name=GDINO_NODE_NAME, parameter_overrides=[])
46-
self.srv = self.create_service(
47-
RAIGroundingDino, GDINO_SERVICE_NAME, self.classify_callback
48-
)
46+
4947
self.declare_parameter("weights_path", "")
5048
try:
5149
weight_path = self.get_parameter("weights_path").value
@@ -57,6 +55,10 @@ def __init__(self):
5755
self.get_logger().error("Could not load model")
5856
raise Exception("Could not load model")
5957

58+
self.srv = self.create_service(
59+
RAIGroundingDino, GDINO_SERVICE_NAME, self.classify_callback
60+
)
61+
6062
def _init_weight_path(self) -> Path:
6163
try:
6264
found_path = get_package_share_directory("rai_open_set_vision")

src/rai_sim/rai_sim/o3de/o3de_bridge.py

+41-5
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
import subprocess
1919
import time
2020
from pathlib import Path
21-
from typing import Any, Dict, Optional
21+
from typing import Any, Dict, List, Optional
2222

23-
from geometry_msgs.msg import PoseStamped
23+
import yaml
24+
from geometry_msgs.msg import Point, Pose, PoseStamped, Quaternion
2425
from std_msgs.msg import Header
26+
from tf2_geometry_msgs import do_transform_pose
2527

26-
import yaml
27-
from geometry_msgs.msg import Point, Pose, Quaternion
2828
from rai.communication.ros2.connectors import ROS2ARIConnector, ROS2ARIMessage
29-
from tf2_geometry_msgs import do_transform_pose
3029
from rai.utils.ros_async import get_future_result
3130
from rai_interfaces.srv import ManipulatorMoveTo
3231
from rai_sim.simulation_bridge import (
@@ -44,6 +43,9 @@
4443
class O3DExROS2SimulationConfig(SimulationConfig):
4544
binary_path: Path
4645
robotic_stack_command: str
46+
required_services: List[str]
47+
required_topics: List[str]
48+
required_actions: List[str]
4749

4850
@classmethod
4951
def load_config(
@@ -203,6 +205,35 @@ def get_scene_state(self) -> SceneState:
203205
)
204206
return SceneState(entities=entities)
205207

208+
def _is_robotic_stack_ready(
209+
self, simulation_config: O3DExROS2SimulationConfig
210+
) -> bool:
211+
retries = 0
212+
while retries < 30:
213+
topics = self.connector.get_topics_names_and_types()
214+
services = self.connector.node.get_service_names_and_types()
215+
topics_names = [tp[0] for tp in topics]
216+
service_names = [srv[0] for srv in services]
217+
self.logger.debug(
218+
f"required services: {simulation_config.required_services}"
219+
)
220+
self.logger.debug(f"required topics: {simulation_config.required_topics}")
221+
self.logger.debug(f"required actions: {simulation_config.required_actions}")
222+
# NOTE actions will be listed in services and topics
223+
if (
224+
all(srv in service_names for srv in simulation_config.required_services)
225+
and all(tp in topics_names for tp in simulation_config.required_topics)
226+
and all(
227+
ac in service_names for ac in simulation_config.required_actions
228+
)
229+
):
230+
self.logger.debug("All required services are available.")
231+
return True
232+
233+
time.sleep(5)
234+
retries += 1
235+
return False
236+
206237
def setup_scene(self, simulation_config: O3DExROS2SimulationConfig):
207238
if self.current_binary_path != simulation_config.binary_path:
208239
if self.current_sim_process:
@@ -215,6 +246,11 @@ def setup_scene(self, simulation_config: O3DExROS2SimulationConfig):
215246
while self.spawned_entities:
216247
self._despawn_entity(self.spawned_entities[0])
217248

249+
if not self._is_robotic_stack_ready(simulation_config=simulation_config):
250+
raise RuntimeError(
251+
"Not all required services, topics and actions are available"
252+
)
253+
218254
for entity in simulation_config.entities:
219255
self._spawn_entity(entity)
220256

0 commit comments

Comments
 (0)