Skip to content

Commit 1d38575

Browse files
committed
everything works
1 parent f069f17 commit 1d38575

18 files changed

+188
-462
lines changed

deep_core/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ find_package(ament_cmake REQUIRED)
2828
find_package(rclcpp REQUIRED)
2929
find_package(rclcpp_lifecycle REQUIRED)
3030
find_package(pluginlib REQUIRED)
31+
find_package(bondcpp REQUIRED)
3132

3233
set(include_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)
3334

@@ -46,6 +47,7 @@ target_link_libraries(${DEEP_CORE_LIB}
4647
rclcpp::rclcpp
4748
rclcpp_lifecycle::rclcpp_lifecycle
4849
pluginlib::pluginlib
50+
bondcpp::bondcpp
4951
)
5052

5153
install(TARGETS
@@ -69,7 +71,8 @@ if(BUILD_TESTING)
6971
find_package(deep_test REQUIRED)
7072

7173
add_deep_test(test_deep_core test/test_deep_core.cpp
72-
LIBRARIES ${DEEP_CORE_LIB}
74+
LIBRARIES
75+
${DEEP_CORE_LIB}
7376
)
7477

7578
endif()

deep_core/include/deep_core/deep_node_base.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string>
2020
#include <vector>
2121

22+
#include <bondcpp/bond.hpp>
2223
#include <pluginlib/class_list_macros.hpp>
2324
#include <pluginlib/class_loader.hpp>
2425
#include <rclcpp_lifecycle/lifecycle_node.hpp>
@@ -191,8 +192,15 @@ class DeepNodeBase : public rclcpp_lifecycle::LifecycleNode
191192
std::string current_plugin_name_;
192193
std::filesystem::path current_model_path_;
193194

195+
// Bond support
196+
std::unique_ptr<bond::Bond> bond_;
197+
bool bond_enabled_;
198+
double bond_timeout_;
199+
double bond_heartbeat_period_;
200+
194201
// ROS parameters
195202
void declare_parameters();
203+
void setup_bond();
196204
};
197205

198206
} // namespace deep_ros

deep_core/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<depend>rclcpp</depend>
1212
<depend>rclcpp_lifecycle</depend>
1313
<depend>pluginlib</depend>
14+
<depend>bondcpp</depend>
1415

1516
<test_depend>deep_test</test_depend>
1617

deep_core/src/deep_node_base.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@ void DeepNodeBase::declare_parameters()
3535
{
3636
declare_parameter("Backend.plugin", "");
3737
declare_parameter("model_path", "");
38+
39+
// Bond parameters
40+
declare_parameter("Bond.enable", false);
41+
declare_parameter("Bond.bond_timeout", 4.0);
42+
declare_parameter("Bond.bond_heartbeat_period", 0.1);
3843
}
3944

4045
CallbackReturn DeepNodeBase::on_configure(const rclcpp_lifecycle::State & state)
4146
{
4247
RCLCPP_INFO(get_logger(), "Configuring DeepNodeBase");
4348

49+
// Setup bond if enabled
50+
setup_bond();
51+
4452
std::string backend_plugin = get_parameter("Backend.plugin").as_string();
4553
if (!backend_plugin.empty()) {
4654
if (!load_plugin(backend_plugin)) {
@@ -63,6 +71,13 @@ CallbackReturn DeepNodeBase::on_configure(const rclcpp_lifecycle::State & state)
6371
CallbackReturn DeepNodeBase::on_activate(const rclcpp_lifecycle::State & state)
6472
{
6573
RCLCPP_INFO(get_logger(), "Activating DeepNodeBase");
74+
75+
// Start bond if enabled
76+
if (bond_enabled_ && bond_) {
77+
bond_->start();
78+
RCLCPP_INFO(get_logger(), "Bond started");
79+
}
80+
6681
return on_activate_impl(state);
6782
}
6883

@@ -75,6 +90,13 @@ CallbackReturn DeepNodeBase::on_deactivate(const rclcpp_lifecycle::State & state
7590
CallbackReturn DeepNodeBase::on_cleanup(const rclcpp_lifecycle::State & state)
7691
{
7792
RCLCPP_INFO(get_logger(), "Cleaning up DeepNodeBase");
93+
94+
// Stop bond if active
95+
if (bond_) {
96+
bond_.reset();
97+
RCLCPP_INFO(get_logger(), "Bond stopped and cleaned up");
98+
}
99+
78100
unload_model();
79101
plugin_.reset();
80102
return on_cleanup_impl(state);
@@ -83,6 +105,13 @@ CallbackReturn DeepNodeBase::on_cleanup(const rclcpp_lifecycle::State & state)
83105
CallbackReturn DeepNodeBase::on_shutdown(const rclcpp_lifecycle::State & state)
84106
{
85107
RCLCPP_INFO(get_logger(), "Shutting down DeepNodeBase");
108+
109+
// Stop bond if active
110+
if (bond_) {
111+
bond_.reset();
112+
RCLCPP_INFO(get_logger(), "Bond stopped and cleaned up");
113+
}
114+
86115
unload_model();
87116
plugin_.reset();
88117
return on_shutdown_impl(state);
@@ -187,4 +216,28 @@ pluginlib::UniquePtr<DeepBackendPlugin> DeepNodeBase::load_plugin_library(const
187216
return plugin_loader_->createUniqueInstance(plugin_name);
188217
}
189218

219+
void DeepNodeBase::setup_bond()
220+
{
221+
bond_enabled_ = get_parameter("Bond.enable").as_bool();
222+
bond_timeout_ = get_parameter("Bond.bond_timeout").as_double();
223+
bond_heartbeat_period_ = get_parameter("Bond.bond_heartbeat_period").as_double();
224+
225+
if (bond_enabled_) {
226+
RCLCPP_INFO(
227+
get_logger(), "Setting up bond with timeout: %.1fs, heartbeat: %.1fs", bond_timeout_, bond_heartbeat_period_);
228+
229+
// Create bond with standard topic name and node name as bond ID
230+
std::string bond_topic = "/bond";
231+
bond_ = std::make_unique<bond::Bond>(bond_topic, get_name(), shared_from_this());
232+
233+
// Configure bond parameters
234+
bond_->setHeartbeatPeriod(bond_heartbeat_period_);
235+
bond_->setHeartbeatTimeout(bond_timeout_);
236+
237+
RCLCPP_INFO(get_logger(), "Bond configured on topic: %s", bond_topic.c_str());
238+
} else {
239+
RCLCPP_INFO(get_logger(), "Bond disabled");
240+
}
241+
}
242+
190243
} // namespace deep_ros

deep_ort_backend_plugin/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ target_include_directories(${DEEP_ORT_LIB} PUBLIC
4848

4949
target_link_libraries(${DEEP_ORT_LIB}
5050
PUBLIC
51-
deep_core::deep_core_lib
5251
pluginlib::pluginlib
5352
rclcpp::rclcpp
5453
PRIVATE
54+
deep_core::deep_core_lib
5555
onnxruntime_vendor::onnxruntime_lib
5656
)
5757

@@ -76,14 +76,21 @@ install(FILES plugins.xml
7676
DESTINATION share/${PROJECT_NAME}
7777
)
7878

79+
# Export plugin description file to ament index
80+
pluginlib_export_plugin_description_file(deep_core plugins.xml)
81+
7982
if(BUILD_TESTING)
8083
find_package(deep_test REQUIRED)
8184

8285
add_deep_test(test_ort_backend test/test_ort_backend.cpp
83-
LIBRARIES ${DEEP_ORT_LIB} onnxruntime_vendor::onnxruntime_lib
86+
LIBRARIES
87+
${DEEP_ORT_LIB}
88+
deep_core::deep_core_lib
89+
onnxruntime_vendor::onnxruntime_lib
8490
)
8591

8692
endif()
8793

8894
ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET)
95+
ament_export_libraries(${DEEP_ORT_LIB})
8996
ament_package()

deep_ort_backend_plugin/package.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@
1717

1818
<export>
1919
<build_type>ament_cmake</build_type>
20-
<pluginlib plugin="${prefix}/plugins.xml"/>
2120
</export>
2221
</package>

deep_sample/CMakeLists.txt

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,49 @@ endif()
2626
find_package(ament_cmake REQUIRED)
2727
find_package(deep_core REQUIRED)
2828
find_package(deep_conversions REQUIRED)
29-
find_package(deep_ort_backend_plugin REQUIRED)
3029
find_package(pluginlib REQUIRED)
3130
find_package(rclcpp REQUIRED)
3231
find_package(rclcpp_lifecycle REQUIRED)
32+
find_package(rclcpp_components REQUIRED)
3333
find_package(sensor_msgs REQUIRED)
3434
find_package(std_msgs REQUIRED)
35+
find_package(bondcpp REQUIRED)
3536

36-
# Sample inference node
37-
add_executable(sample_inference_node
37+
# Sample inference component library
38+
add_library(sample_inference_component SHARED
3839
src/sample_inference_node.cpp
3940
)
4041

41-
target_include_directories(sample_inference_node PUBLIC
42+
target_include_directories(sample_inference_component PUBLIC
4243
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
4344
$<INSTALL_INTERFACE:include>
4445
)
4546

46-
target_link_libraries(sample_inference_node
47-
deep_core::deep_core_lib
48-
deep_conversions::deep_conversions_lib
49-
deep_ort_backend_plugin::deep_ort_backend_plugin_lib
50-
pluginlib::pluginlib
51-
rclcpp::rclcpp
52-
rclcpp_lifecycle::rclcpp_lifecycle
53-
${sensor_msgs_TARGETS}
54-
${std_msgs_TARGETS}
47+
target_link_libraries(sample_inference_component
48+
PUBLIC
49+
pluginlib::pluginlib
50+
rclcpp::rclcpp
51+
rclcpp_lifecycle::rclcpp_lifecycle
52+
rclcpp_components::component
53+
${sensor_msgs_TARGETS}
54+
${std_msgs_TARGETS}
55+
bondcpp::bondcpp
56+
PRIVATE
57+
deep_core::deep_core_lib
58+
deep_conversions::deep_conversions_lib
5559
)
5660

57-
# Install executable
58-
install(TARGETS sample_inference_node
59-
DESTINATION lib/${PROJECT_NAME}
61+
# Register the component and create executable
62+
rclcpp_components_register_node(sample_inference_component
63+
PLUGIN deep_sample::SampleInferenceNode
64+
EXECUTABLE sample_inference_node
65+
)
66+
67+
# Install component library and executable
68+
install(TARGETS sample_inference_component
69+
ARCHIVE DESTINATION lib
70+
LIBRARY DESTINATION lib
71+
RUNTIME DESTINATION bin
6072
)
6173

6274
# Install config and launch files
@@ -65,8 +77,7 @@ install(DIRECTORY config launch models
6577
)
6678

6779
if(BUILD_TESTING)
68-
find_package(ament_lint_auto REQUIRED)
69-
ament_lint_auto_find_test_dependencies()
80+
7081
endif()
7182

7283
ament_package()

deep_sample/config/sample_config.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) 2025-present WATonomous. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Configuration for deep_sample inference node
16+
sample_inference_node:
17+
ros__parameters:
18+
# Backend configuration
19+
Backend:
20+
plugin: "onnxruntime_cpu"
21+
22+
# Bond configuration
23+
Bond:
24+
enable: true
25+
bond_timeout: 4.0
26+
bond_heartbeat_period: 0.1
27+
28+
# Model configuration
29+
model_path: "/workspaces/deep_ros/install/deep_sample/share/deep_sample/models/tiny_model.onnx"
30+
31+
# Topic configuration
32+
input_topic: "/camera/image_raw"
33+
output_topic: "/inference/output"
34+
35+
# Node-specific parameters
36+
use_sim_time: false
37+
log_level: "info"

0 commit comments

Comments
 (0)