Skip to content

Commit 55c083b

Browse files
authored
refactor: micro changes (#537)
1 parent e308a55 commit 55c083b

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ markers = [
7474
]
7575
addopts = "-m 'not billable and not ci_only' --ignore=src"
7676
log_cli = true
77-
log_cli_level = "DEBUG"
77+
log_cli_level = "INFO"

src/rai_core/rai/communication/base_connector.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(self, callback_max_workers: int = 4):
8282
def _generate_handle(self) -> str:
8383
return str(uuid4())
8484

85-
def send_message(self, message: T, target: str, **kwargs: Any) -> None:
85+
def send_message(self, message: T, target: str, **kwargs: Optional[Any]) -> None:
8686
"""Implements publish pattern.
8787
8888
Sends a message to one or more subscribers. The target parameter
@@ -93,7 +93,9 @@ def send_message(self, message: T, target: str, **kwargs: Any) -> None:
9393
"""
9494
raise NotImplementedError("This method should be implemented by the subclass.")
9595

96-
def receive_message(self, source: str, timeout_sec: float, **kwargs: Any) -> T:
96+
def receive_message(
97+
self, source: str, timeout_sec: float, **kwargs: Optional[Any]
98+
) -> T:
9799
"""Implements subscribe pattern.
98100
99101
Receives a message from a publisher. The source parameter
@@ -109,7 +111,7 @@ def register_callback(
109111
source: str,
110112
callback: Callable[[T | Any], None],
111113
raw: bool = False,
112-
**kwargs: Any,
114+
**kwargs: Optional[Any],
113115
) -> str:
114116
"""Implements register callback.
115117
@@ -173,7 +175,7 @@ def general_callback_preprocessor(self, message: Any) -> T:
173175
raise NotImplementedError("This method should be implemented by the subclass.")
174176

175177
def service_call(
176-
self, message: T, target: str, timeout_sec: float, **kwargs: Any
178+
self, message: T, target: str, timeout_sec: float, **kwargs: Optional[Any]
177179
) -> BaseMessage:
178180
"""Implements request-response pattern.
179181
@@ -190,7 +192,7 @@ def create_service(
190192
service_name: str,
191193
on_request: Callable,
192194
on_done: Optional[Callable] = None,
193-
**kwargs: Any,
195+
**kwargs: Optional[Any],
194196
) -> str:
195197
"""Sets up a service endpoint for handling requests.
196198
@@ -207,7 +209,7 @@ def create_action(
207209
self,
208210
action_name: str,
209211
generate_feedback_callback: Callable,
210-
**kwargs: Any,
212+
**kwargs: Optional[Any],
211213
) -> str:
212214
"""Sets up an action endpoint for long-running operations.
213215
@@ -227,7 +229,7 @@ def start_action(
227229
on_feedback: Callable,
228230
on_done: Callable,
229231
timeout_sec: float,
230-
**kwargs: Any,
232+
**kwargs: Optional[Any],
231233
) -> str:
232234
"""Initiates a long-running operation with feedback.
233235
@@ -240,7 +242,7 @@ def start_action(
240242
"""
241243
raise NotImplementedError("This method should be implemented by the subclass.")
242244

243-
def terminate_action(self, action_handle: str, **kwargs: Any) -> Any:
245+
def terminate_action(self, action_handle: str, **kwargs: Optional[Any]) -> Any:
244246
"""Cancels an ongoing action.
245247
246248
Stops the execution of a previously started action.

src/rai_core/rai/communication/ros2/connectors/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def __init__(
9999
destroy_subscribers: bool = False,
100100
):
101101
super().__init__()
102+
103+
if not rclpy.ok():
104+
rclpy.init()
105+
self.logger.warning(
106+
"Auto-initializing ROS2, but manual initialization is recommended. "
107+
"For better control and predictability, call rclpy.init() or ROS2Context before creating this connector."
108+
)
109+
102110
self._node = Node(node_name)
103111
self._topic_api = ROS2TopicAPI(self._node, destroy_subscribers)
104112
self._service_api = ROS2ServiceAPI(self._node)

src/rai_core/rai/tools/ros2/generic/actions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828

2929
internal_action_id_mapping: Dict[str, str] = {}
3030
action_results_store: Dict[str, Any] = {}
31-
action_results_store_lock: Lock = Lock()
31+
action_results_store_lock: Any = Lock()
3232
action_feedbacks_store: Dict[str, List[Any]] = defaultdict(list)
33-
action_feedbacks_store_lock: Lock = Lock()
33+
action_feedbacks_store_lock: Any = Lock()
3434

3535

3636
def get_internal_action_id_mapping():
@@ -60,13 +60,13 @@ class ROS2ActionToolkit(BaseROS2Toolkit):
6060
action_results_store: Dict[str, Any] = Field(
6161
default_factory=get_action_results_store
6262
)
63-
action_results_store_lock: Lock = Field(
63+
action_results_store_lock: Any = Field(
6464
default_factory=get_action_results_store_lock
6565
)
6666
action_feedbacks_store: Dict[str, List[Any]] = Field(
6767
default_factory=get_action_feedbacks_store
6868
)
69-
action_feedbacks_store_lock: Lock = Field(
69+
action_feedbacks_store_lock: Any = Field(
7070
default_factory=get_action_feedbacks_store_lock
7171
)
7272

@@ -194,7 +194,7 @@ class GetROS2ActionFeedbackTool(BaseROS2Tool):
194194
action_feedbacks_store: Dict[str, List[Any]] = Field(
195195
default_factory=get_action_feedbacks_store
196196
)
197-
action_feedbacks_store_lock: Lock = Field(
197+
action_feedbacks_store_lock: Any = Field(
198198
default_factory=get_action_feedbacks_store_lock
199199
)
200200
internal_action_id_mapping: Dict[str, str] = Field(
@@ -223,7 +223,7 @@ class GetROS2ActionResultTool(BaseTool):
223223
action_results_store: Dict[str, Any] = Field(
224224
default_factory=get_action_results_store
225225
)
226-
action_results_store_lock: Lock = Field(
226+
action_results_store_lock: Any = Field(
227227
default_factory=get_action_results_store_lock
228228
)
229229
internal_action_id_mapping: Dict[str, str] = Field(

0 commit comments

Comments
 (0)