From 76742927b5e92caa35e20b6aec5a29618f190571 Mon Sep 17 00:00:00 2001 From: Joe Dong Date: Tue, 22 Aug 2023 21:11:59 +0800 Subject: [PATCH] use rclcpp componet --- orbbec_camera/CMakeLists.txt | 87 ++++++++------------- orbbec_camera/src/main.cpp | 13 --- orbbec_camera/src/ob_camera_node_driver.cpp | 3 + 3 files changed, 35 insertions(+), 68 deletions(-) delete mode 100644 orbbec_camera/src/main.cpp diff --git a/orbbec_camera/CMakeLists.txt b/orbbec_camera/CMakeLists.txt index 7a6bd4f9..bea1c898 100644 --- a/orbbec_camera/CMakeLists.txt +++ b/orbbec_camera/CMakeLists.txt @@ -67,13 +67,14 @@ add_library(${PROJECT_NAME} SHARED src/ros_service.cpp src/synced_imu_publisher.cpp src/utils.cpp - ) +) set(dependencies ament_index_cpp builtin_interfaces cv_bridge camera_info_manager + rclcpp_components Eigen3 image_transport image_publisher @@ -87,11 +88,11 @@ set(dependencies tf2_msgs tf2_ros tf2_sensor_msgs - ) +) ament_target_dependencies(${PROJECT_NAME} ${dependencies} - ) +) target_include_directories(${PROJECT_NAME} PUBLIC $ @@ -100,7 +101,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${ORBBEC_INCLUDE_DIR} ${OpenCV_INCLUDED_DIRS} ${GLOG_INCLUDED_DIRS} - ) +) target_link_libraries(${PROJECT_NAME} @@ -110,38 +111,16 @@ target_link_libraries(${PROJECT_NAME} ${GLOG_LIBRARIES} -lOrbbecSDK -L${ORBBEC_LIBS} - ) +) -add_executable(${PROJECT_NAME}_node - src/main.cpp - ) +rclcpp_components_register_node(${PROJECT_NAME} + PLUGIN "orbbec_camera::OBCameraNodeDriver" + EXECUTABLE orbbec_camera_node +) -target_include_directories(${PROJECT_NAME}_node PUBLIC - $ - $ - $ - ${ORBBEC_INCLUDE_DIR} - ${OpenCV_INCLUDED_DIRS} - ${GLOG_INCLUDED_DIRS} - ) - - -target_link_libraries(${PROJECT_NAME}_node - ${ORBBEC_SDK_LIBRARIES} - ${OpenCV_LIBS} - Eigen3::Eigen - ${GLOG_LIBRARIES} - -lOrbbecSDK - -L${ORBBEC_LIBS} - ${PROJECT_NAME} - ) - -ament_target_dependencies(${PROJECT_NAME}_node - ${dependencies} - ) add_executable(list_devices_node src/list_devices_node.cpp - ) +) target_include_directories(list_devices_node PUBLIC $ @@ -150,7 +129,7 @@ target_include_directories(list_devices_node PUBLIC ${ORBBEC_INCLUDE_DIR} ${OpenCV_INCLUDED_DIRS} ${GLOG_INCLUDED_DIRS} - ) +) target_link_libraries(list_devices_node @@ -161,15 +140,15 @@ target_link_libraries(list_devices_node -lOrbbecSDK -L${ORBBEC_LIBS} ${PROJECT_NAME} - ) +) ament_target_dependencies(list_devices_node ${dependencies} - ) +) add_executable(ob_cleanup_shm_node src/ob_cleanup_shm.cpp - ) +) target_include_directories(ob_cleanup_shm_node PUBLIC $ @@ -178,7 +157,7 @@ target_include_directories(ob_cleanup_shm_node PUBLIC ${ORBBEC_INCLUDE_DIR} ${OpenCV_INCLUDED_DIRS} ${GLOG_INCLUDED_DIRS} - ) +) target_link_libraries(ob_cleanup_shm_node @@ -189,15 +168,15 @@ target_link_libraries(ob_cleanup_shm_node -lOrbbecSDK -L${ORBBEC_LIBS} ${PROJECT_NAME} - ) +) ament_target_dependencies(ob_cleanup_shm_node ${dependencies} - ) +) add_executable(list_depth_work_mode_node src/list_depth_work_mode.cpp - ) +) target_include_directories(list_depth_work_mode_node PUBLIC $ @@ -206,7 +185,7 @@ target_include_directories(list_depth_work_mode_node PUBLIC ${ORBBEC_INCLUDE_DIR} ${OpenCV_INCLUDED_DIRS} ${GLOG_INCLUDED_DIRS} - ) +) target_link_libraries(list_depth_work_mode_node ${ORBBEC_SDK_LIBRARIES} @@ -216,15 +195,15 @@ target_link_libraries(list_depth_work_mode_node -lOrbbecSDK -L${ORBBEC_LIBS} ${PROJECT_NAME} - ) +) ament_target_dependencies(list_depth_work_mode_node ${dependencies} - ) +) add_executable(list_camera_profile_mode_node src/list_camera_profile.cpp - ) +) target_include_directories(list_camera_profile_mode_node PUBLIC $ @@ -233,7 +212,7 @@ target_include_directories(list_camera_profile_mode_node PUBLIC ${ORBBEC_INCLUDE_DIR} ${OpenCV_INCLUDED_DIRS} ${GLOG_INCLUDED_DIRS} - ) +) target_link_libraries(list_camera_profile_mode_node ${ORBBEC_SDK_LIBRARIES} @@ -243,16 +222,16 @@ target_link_libraries(list_camera_profile_mode_node -lOrbbecSDK -L${ORBBEC_LIBS} ${PROJECT_NAME} - ) +) ament_target_dependencies(list_depth_work_mode_node ${dependencies} - ) +) install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin - ) +) install( DIRECTORY include/ @@ -262,33 +241,31 @@ install( install(DIRECTORY launch DESTINATION share/${PROJECT_NAME}/ - ) +) install(DIRECTORY config DESTINATION share/${PROJECT_NAME}/ - ) +) install(DIRECTORY ${ORBBEC_INCLUDE_DIR} DESTINATION include - ) +) install(DIRECTORY ${ORBBEC_LIBS}/ DESTINATION lib/ FILES_MATCHING PATTERN "*.so" PATTERN "*.so.*" - ) - +) install(TARGETS list_devices_node ob_cleanup_shm_node list_depth_work_mode_node list_camera_profile_mode_node - ${PROJECT_NAME}_node DESTINATION lib/${PROJECT_NAME}/ - ) +) if (BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() diff --git a/orbbec_camera/src/main.cpp b/orbbec_camera/src/main.cpp deleted file mode 100644 index b336fe73..00000000 --- a/orbbec_camera/src/main.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include - -int main(int argc, char** argv) { - rclcpp::init(argc, argv); - rclcpp::NodeOptions options; - using namespace orbbec_camera; - auto node = std::make_shared(options); - rclcpp::spin(node); - rclcpp::shutdown(); - return 0; -} diff --git a/orbbec_camera/src/ob_camera_node_driver.cpp b/orbbec_camera/src/ob_camera_node_driver.cpp index 9e1b4875..97343ce9 100644 --- a/orbbec_camera/src/ob_camera_node_driver.cpp +++ b/orbbec_camera/src/ob_camera_node_driver.cpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace orbbec_camera { OBCameraNodeDriver::OBCameraNodeDriver(const rclcpp::NodeOptions &node_options) @@ -406,3 +407,5 @@ void OBCameraNodeDriver::startDevice(const std::shared_ptr &list initializeDevice(device); } } // namespace orbbec_camera + +RCLCPP_COMPONENTS_REGISTER_NODE(orbbec_camera::OBCameraNodeDriver) \ No newline at end of file