From 8fd8662e0dd2670074c22bafb821e9a925cfc549 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 24 Apr 2023 12:21:43 +0200 Subject: [PATCH] add launch file --- src/object_detection/CMakeLists.txt | 5 +++++ .../launch/object_detection_launch.py | 15 +++++++++++++++ src/object_detection/src/multiflex_reader.cpp | 8 ++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/object_detection/launch/object_detection_launch.py diff --git a/src/object_detection/CMakeLists.txt b/src/object_detection/CMakeLists.txt index c47c2067..d5009b96 100644 --- a/src/object_detection/CMakeLists.txt +++ b/src/object_detection/CMakeLists.txt @@ -48,6 +48,11 @@ install(TARGETS DESTINATION lib/${PROJECT_NAME} ) +install( + DIRECTORY launch + DESTINATION share/${PROJECT_NAME} +) + if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights diff --git a/src/object_detection/launch/object_detection_launch.py b/src/object_detection/launch/object_detection_launch.py new file mode 100644 index 00000000..862f52b7 --- /dev/null +++ b/src/object_detection/launch/object_detection_launch.py @@ -0,0 +1,15 @@ +from launch import LaunchDescription +from launch_ros.actions import Node + +def generate_launch_description(): + return LaunchDescription([ + Node( + package="object_detection", + executable="multiflex_reader", + name="multiflex_reader", + parameters=[ + {"serial_port": "/dev/ttyACM0"} + ] + ) + + ]) \ No newline at end of file diff --git a/src/object_detection/src/multiflex_reader.cpp b/src/object_detection/src/multiflex_reader.cpp index e07ac8d9..35c370b7 100644 --- a/src/object_detection/src/multiflex_reader.cpp +++ b/src/object_detection/src/multiflex_reader.cpp @@ -21,8 +21,12 @@ public: MultiflexReader() : Node("multiflex_reader") { + rcl_interfaces::msg::ParameterDescriptor serial_port_descriptor = rcl_interfaces::msg::ParameterDescriptor{}; + serial_port_descriptor.description = "Serial port of the USB port that the multiflex PCB is connected to."; + this->declare_parameter("serial_port", "/dev/ttyACM0", serial_port_descriptor); + factory = terabee::ITerarangerFactory::getFactory(); - multiflex = factory->createTerarangerMultiflex("/dev/ttyACM0"); + multiflex = factory->createTerarangerMultiflex(this->get_parameter("serial_port").as_string()); if (!multiflex) { @@ -54,7 +58,7 @@ private: { terabee::DistanceData data = multiflex->getDistance(); auto msg = object_detection::msg::MultiflexReading(); - for (int i = 0; i < data.size(); i++) + for (size_t i = 0; i < data.size(); i++) { msg.distance_data[i] = data.distance[i]; }