From 5255199a01dea0b5ce8cade4c224956d2d7fd332 Mon Sep 17 00:00:00 2001 From: MEIP-users Date: Wed, 22 Dec 2021 16:43:06 +0900 Subject: [PATCH 1/2] mix_msgs pubsub app added(support array) --- .gitignore | 4 ++ .../float_location_msgs/msg/FloatLocation | 3 -- .../CMakeLists.txt | 4 +- custom_msgs/mix_msgs/msg/Mix.msg | 4 ++ .../package.xml | 2 +- .../src/pub_node.cpp | 45 ----------------- .../src/sub_node.cpp | 34 ------------- mros2_echoback_health/src/pub_node.cpp | 2 +- .../CMakeLists.txt | 10 ++-- .../launch/launch_pubsub.py | 6 +-- .../package.xml | 8 ++-- mros2_echoback_mix/src/pub_node.cpp | 48 +++++++++++++++++++ mros2_echoback_mix/src/sub_node.cpp | 34 +++++++++++++ 13 files changed, 106 insertions(+), 98 deletions(-) create mode 100644 .gitignore delete mode 100644 custom_msgs/float_location_msgs/msg/FloatLocation rename custom_msgs/{float_location_msgs => mix_msgs}/CMakeLists.txt (94%) create mode 100644 custom_msgs/mix_msgs/msg/Mix.msg rename custom_msgs/{float_location_msgs => mix_msgs}/package.xml (95%) delete mode 100644 mros2_echoback_float_location/src/pub_node.cpp delete mode 100644 mros2_echoback_float_location/src/sub_node.cpp rename {mros2_echoback_float_location => mros2_echoback_mix}/CMakeLists.txt (87%) rename {mros2_echoback_float_location => mros2_echoback_mix}/launch/launch_pubsub.py (82%) rename {mros2_echoback_float_location => mros2_echoback_mix}/package.xml (80%) create mode 100644 mros2_echoback_mix/src/pub_node.cpp create mode 100644 mros2_echoback_mix/src/sub_node.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2afc7a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +log/ +.vscode/ +build/ +install/ \ No newline at end of file diff --git a/custom_msgs/float_location_msgs/msg/FloatLocation b/custom_msgs/float_location_msgs/msg/FloatLocation deleted file mode 100644 index 0fb5429..0000000 --- a/custom_msgs/float_location_msgs/msg/FloatLocation +++ /dev/null @@ -1,3 +0,0 @@ -float32 x -float32 y -float32 z \ No newline at end of file diff --git a/custom_msgs/float_location_msgs/CMakeLists.txt b/custom_msgs/mix_msgs/CMakeLists.txt similarity index 94% rename from custom_msgs/float_location_msgs/CMakeLists.txt rename to custom_msgs/mix_msgs/CMakeLists.txt index 40c46f9..d3d4416 100644 --- a/custom_msgs/float_location_msgs/CMakeLists.txt +++ b/custom_msgs/mix_msgs/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -project(float_location_msgs) +project(mix_msgs) # Default to C99 if(NOT CMAKE_C_STANDARD) @@ -20,7 +20,7 @@ find_package(ament_cmake REQUIRED) find_package(rosidl_default_generators REQUIRED) rosidl_generate_interfaces(${PROJECT_NAME} - "msg/FloatLocation.msg" + "msg/Mix.msg" ) if(BUILD_TESTING) diff --git a/custom_msgs/mix_msgs/msg/Mix.msg b/custom_msgs/mix_msgs/msg/Mix.msg new file mode 100644 index 0000000..1b8f5db --- /dev/null +++ b/custom_msgs/mix_msgs/msg/Mix.msg @@ -0,0 +1,4 @@ +string name +uint16 height +float32 weight +uint32[] array \ No newline at end of file diff --git a/custom_msgs/float_location_msgs/package.xml b/custom_msgs/mix_msgs/package.xml similarity index 95% rename from custom_msgs/float_location_msgs/package.xml rename to custom_msgs/mix_msgs/package.xml index 57aceb4..8ebe014 100644 --- a/custom_msgs/float_location_msgs/package.xml +++ b/custom_msgs/mix_msgs/package.xml @@ -1,7 +1,7 @@ - float_location_msgs + mix_msgs 0.0.0 TODO: Package description uden diff --git a/mros2_echoback_float_location/src/pub_node.cpp b/mros2_echoback_float_location/src/pub_node.cpp deleted file mode 100644 index 4192938..0000000 --- a/mros2_echoback_float_location/src/pub_node.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -#include - -#include "rclcpp/rclcpp.hpp" -#include "float_location_msgs/msg/float_location.hpp" - -using namespace std::chrono_literals; - -/* This example creates a subclass of Node and uses std::bind() to register a -* member function as a callback from the timer. */ - -class Publisher : public rclcpp::Node -{ -public: - Publisher() - : Node("pub_mros2"), count_(0) - { - publisher_ = this->create_publisher("to_stm", 10); - timer_ = this->create_wall_timer(1000ms, std::bind(&Publisher::timer_callback, this)); - } - -private: - void timer_callback() - { - auto message = float_location_msgs::msg::FloatLocation(); - message.x = count_++/10.0; - message.y = 2*count_++/10.0; - message.z = 3*count_++/10.0; - RCLCPP_INFO(this->get_logger(), "Publishing msg: { x: %f, y: %f, z: %f }", message.x,message.y, message.z); - publisher_->publish(message); - } - rclcpp::TimerBase::SharedPtr timer_; - rclcpp::Publisher::SharedPtr publisher_; - size_t count_; -}; - -int main(int argc, char *argv[]) -{ - rclcpp::init(argc, argv); - rclcpp::spin(std::make_shared()); - rclcpp::shutdown(); - return 0; -} diff --git a/mros2_echoback_float_location/src/sub_node.cpp b/mros2_echoback_float_location/src/sub_node.cpp deleted file mode 100644 index 0c21ebf..0000000 --- a/mros2_echoback_float_location/src/sub_node.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include -#include - -#include "rclcpp/rclcpp.hpp" -#include "float_location_msgs/msg/float_location.hpp" - -using std::placeholders::_1; - -class Subscriber : public rclcpp::Node -{ -public: - Subscriber() : Node("mros2_sub") - { - subscriber_ = this->create_subscription("to_linux", rclcpp::QoS(10).best_effort(), std::bind(&Subscriber::topic_callback, this, _1)); - } - -private: - void topic_callback(const float_location_msgs::msg::FloatLocation::SharedPtr message) const - { - RCLCPP_INFO(this->get_logger(), "Subscribed msg: { x: %f, y: %f, z: %f }", message->x,message->y, message->z); - } - rclcpp::Subscription::SharedPtr subscriber_; -}; - - -int main(int argc, char *argv[]) -{ - rclcpp::init(argc, argv); - rclcpp::spin(std::make_shared()); - rclcpp::shutdown(); - return 0; -} \ No newline at end of file diff --git a/mros2_echoback_health/src/pub_node.cpp b/mros2_echoback_health/src/pub_node.cpp index 8b7df0c..50c8039 100644 --- a/mros2_echoback_health/src/pub_node.cpp +++ b/mros2_echoback_health/src/pub_node.cpp @@ -25,7 +25,7 @@ class Publisher : public rclcpp::Node void timer_callback() { auto message = health_msgs::msg::Health(); - message.name = "Hi"; + message.name = std::to_string(count_++); message.height = 170; message.weight = 63.5; RCLCPP_INFO(this->get_logger(), "Publishing msg: { name: '%s', height: %u cm, weight: %f kg }", message.name.c_str(), message.height, message.weight); diff --git a/mros2_echoback_float_location/CMakeLists.txt b/mros2_echoback_mix/CMakeLists.txt similarity index 87% rename from mros2_echoback_float_location/CMakeLists.txt rename to mros2_echoback_mix/CMakeLists.txt index 4b7171a..f61e790 100644 --- a/mros2_echoback_float_location/CMakeLists.txt +++ b/mros2_echoback_mix/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -project(mros2_echoback_float_location) +project(mros2_echoback_mix) # Default to C99 @@ -19,16 +19,16 @@ endif() # find dependencies find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) -find_package(float_location_msgs REQUIRED) +find_package(mix_msgs REQUIRED) # uncomment the following section in order to fill in # further dependencies manually. # find_package( REQUIRED) add_executable(pub_node src/pub_node.cpp) -ament_target_dependencies(pub_node rclcpp float_location_msgs) +ament_target_dependencies(pub_node rclcpp mix_msgs) add_executable(sub_node src/sub_node.cpp) -ament_target_dependencies(sub_node rclcpp float_location_msgs) +ament_target_dependencies(sub_node rclcpp mix_msgs) target_include_directories(pub_node PUBLIC $ @@ -59,4 +59,4 @@ if(BUILD_TESTING) ament_lint_auto_find_test_dependencies() endif() -ament_package() +ament_package() \ No newline at end of file diff --git a/mros2_echoback_float_location/launch/launch_pubsub.py b/mros2_echoback_mix/launch/launch_pubsub.py similarity index 82% rename from mros2_echoback_float_location/launch/launch_pubsub.py rename to mros2_echoback_mix/launch/launch_pubsub.py index 974491e..dc56c29 100644 --- a/mros2_echoback_float_location/launch/launch_pubsub.py +++ b/mros2_echoback_mix/launch/launch_pubsub.py @@ -5,17 +5,17 @@ def generate_launch_description(): return LaunchDescription([ Node( - package='mros2_echoback_float_location', + package='mros2_echoback_mix', node_executable='pub_node', node_name='pub_mros2', prefix=['stdbuf -o L'], output="screen" ), Node( - package='mros2_echoback_float_location', + package='mros2_echoback_mix', node_executable='sub_node', node_name='mros2_sub', prefix=['stdbuf -o L'], output="screen" ) - ]) + ]) \ No newline at end of file diff --git a/mros2_echoback_float_location/package.xml b/mros2_echoback_mix/package.xml similarity index 80% rename from mros2_echoback_float_location/package.xml rename to mros2_echoback_mix/package.xml index 7349b49..2a71f50 100644 --- a/mros2_echoback_float_location/package.xml +++ b/mros2_echoback_mix/package.xml @@ -1,7 +1,7 @@ - mros2_echoback_float_location + mros2_echoback_mix 0.0.0 TODO: Package description uden @@ -9,13 +9,13 @@ ament_cmake rclcpp -float_location_msgs +mix_msgs rclcpp -float_location_msgs +mix_msgs ament_lint_auto ament_lint_common ament_cmake - + \ No newline at end of file diff --git a/mros2_echoback_mix/src/pub_node.cpp b/mros2_echoback_mix/src/pub_node.cpp new file mode 100644 index 0000000..dbc0ccb --- /dev/null +++ b/mros2_echoback_mix/src/pub_node.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +#include "rclcpp/rclcpp.hpp" +#include "mix_msgs/msg/mix.hpp" + +using namespace std::chrono_literals; + +/* This example creates a subclass of Node and uses std::bind() to register a +* member function as a callback from the timer. */ + +class Publisher : public rclcpp::Node +{ +public: + Publisher() + : Node("pub_mros2"), count_(0) + { + publisher_ = this->create_publisher("to_stm", 10); + timer_ = this->create_wall_timer(1000ms, std::bind(&Publisher::timer_callback, this)); + } + +private: + void timer_callback() + { + auto message = mix_msgs::msg::Mix(); + message.name = std::to_string(count_++); + message.height = 170; + message.weight = 63.5; + message.array.push_back(count_); + message.array.push_back(count_+1); + message.array.push_back(count_+2); + RCLCPP_INFO(this->get_logger(), "Publishing msg: { name: '%s', height: %u cm, weight: %f kg, array: {%u,%u,%u} }", message.name.c_str(), message.height, message.weight, message.array[0], message.array[1], message.array[2]); + publisher_->publish(message); + } + rclcpp::TimerBase::SharedPtr timer_; + rclcpp::Publisher::SharedPtr publisher_; + size_t count_; +}; + +int main(int argc, char * argv[]) +{ + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +} diff --git a/mros2_echoback_mix/src/sub_node.cpp b/mros2_echoback_mix/src/sub_node.cpp new file mode 100644 index 0000000..7f9ee5c --- /dev/null +++ b/mros2_echoback_mix/src/sub_node.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#include "rclcpp/rclcpp.hpp" +#include "mix_msgs/msg/mix.hpp" + +using std::placeholders::_1; + +class Subscriber : public rclcpp::Node +{ +public: + Subscriber() : Node("mros2_sub") + { + subscriber_ = this->create_subscription("to_linux", rclcpp::QoS(10).best_effort(), std::bind(&Subscriber::topic_callback, this, _1)); + } + +private: + void topic_callback(const mix_msgs::msg::Mix::SharedPtr message) const + { + RCLCPP_INFO(this->get_logger(), "Subscribed msg: { name: '%s', height: %d cm, weight: %f kg, array: {%u,%u,%u} }", message->name.c_str(), message->height, message->weight, message->array[0], message->array[1], message->array[2]); + } + rclcpp::Subscription::SharedPtr subscriber_; +}; + + +int main(int argc, char *argv[]) +{ + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +} \ No newline at end of file From 12474b7a5e04bb747794c82e4d29c2642aa9eab0 Mon Sep 17 00:00:00 2001 From: MEIP-users Date: Thu, 23 Dec 2021 00:20:35 +0900 Subject: [PATCH 2/2] vector3 app added --- custom_msgs/geometry_msgs/CMakeLists.txt | 37 +++++++++++ custom_msgs/geometry_msgs/msg/Vector3.msg | 3 + custom_msgs/geometry_msgs/package.xml | 23 +++++++ custom_msgs/mix_msgs/msg/Mix.msg | 2 +- mros2_echoback_vector3/CMakeLists.txt | 62 +++++++++++++++++++ .../launch/launch_pubsub.py | 21 +++++++ mros2_echoback_vector3/package.xml | 21 +++++++ mros2_echoback_vector3/src/pub_node.cpp | 45 ++++++++++++++ mros2_echoback_vector3/src/sub_node.cpp | 34 ++++++++++ 9 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 custom_msgs/geometry_msgs/CMakeLists.txt create mode 100644 custom_msgs/geometry_msgs/msg/Vector3.msg create mode 100644 custom_msgs/geometry_msgs/package.xml create mode 100644 mros2_echoback_vector3/CMakeLists.txt create mode 100644 mros2_echoback_vector3/launch/launch_pubsub.py create mode 100644 mros2_echoback_vector3/package.xml create mode 100644 mros2_echoback_vector3/src/pub_node.cpp create mode 100644 mros2_echoback_vector3/src/sub_node.cpp diff --git a/custom_msgs/geometry_msgs/CMakeLists.txt b/custom_msgs/geometry_msgs/CMakeLists.txt new file mode 100644 index 0000000..351ceb2 --- /dev/null +++ b/custom_msgs/geometry_msgs/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.5) +project(geometry_msgs) + +# Default to C99 +if(NOT CMAKE_C_STANDARD) + set(CMAKE_C_STANDARD 99) +endif() + +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(rosidl_default_generators REQUIRED) + +rosidl_generate_interfaces(${PROJECT_NAME} + "msg/Vector3.msg" +) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + # the following line skips the linter which checks for copyrights + # uncomment the line when a copyright and license is not present in all source files + #set(ament_cmake_copyright_FOUND TRUE) + # the following line skips cpplint (only works in a git repo) + # uncomment the line when this package is not in a git repo + #set(ament_cmake_cpplint_FOUND TRUE) + ament_lint_auto_find_test_dependencies() +endif() + +ament_package() \ No newline at end of file diff --git a/custom_msgs/geometry_msgs/msg/Vector3.msg b/custom_msgs/geometry_msgs/msg/Vector3.msg new file mode 100644 index 0000000..681257d --- /dev/null +++ b/custom_msgs/geometry_msgs/msg/Vector3.msg @@ -0,0 +1,3 @@ +float64 x +float64 y +float64 z \ No newline at end of file diff --git a/custom_msgs/geometry_msgs/package.xml b/custom_msgs/geometry_msgs/package.xml new file mode 100644 index 0000000..4ba5e75 --- /dev/null +++ b/custom_msgs/geometry_msgs/package.xml @@ -0,0 +1,23 @@ + + + + geometry_msgs + 0.0.0 + TODO: Package description + uden + TODO: License declaration + + ament_cmake + + rosidl_default_generators + rosidl_default_runtime + + rosidl_interface_packages + + ament_lint_auto + ament_lint_common + + + ament_cmake + + \ No newline at end of file diff --git a/custom_msgs/mix_msgs/msg/Mix.msg b/custom_msgs/mix_msgs/msg/Mix.msg index 1b8f5db..4e55741 100644 --- a/custom_msgs/mix_msgs/msg/Mix.msg +++ b/custom_msgs/mix_msgs/msg/Mix.msg @@ -1,4 +1,4 @@ string name uint16 height float32 weight -uint32[] array \ No newline at end of file +uint16[] array \ No newline at end of file diff --git a/mros2_echoback_vector3/CMakeLists.txt b/mros2_echoback_vector3/CMakeLists.txt new file mode 100644 index 0000000..fa1c53b --- /dev/null +++ b/mros2_echoback_vector3/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required(VERSION 3.5) +project(mros2_echoback_vector3) + + +# Default to C99 +if(NOT CMAKE_C_STANDARD) + set(CMAKE_C_STANDARD 99) +endif() + +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(rclcpp REQUIRED) +find_package(geometry_msgs REQUIRED) +# uncomment the following section in order to fill in +# further dependencies manually. +# find_package( REQUIRED) + +add_executable(pub_node src/pub_node.cpp) +ament_target_dependencies(pub_node rclcpp geometry_msgs) + +add_executable(sub_node src/sub_node.cpp) +ament_target_dependencies(sub_node rclcpp geometry_msgs) + +target_include_directories(pub_node PUBLIC + $ + $) + +target_include_directories(sub_node PUBLIC + $ + $) + +install(TARGETS pub_node + DESTINATION lib/${PROJECT_NAME}) +install(TARGETS sub_node + 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 + # uncomment the line when a copyright and license is not present in all source files + #set(ament_cmake_copyright_FOUND TRUE) + # the following line skips cpplint (only works in a git repo) + # uncomment the line when this package is not in a git repo + #set(ament_cmake_cpplint_FOUND TRUE) + ament_lint_auto_find_test_dependencies() +endif() + +ament_package() \ No newline at end of file diff --git a/mros2_echoback_vector3/launch/launch_pubsub.py b/mros2_echoback_vector3/launch/launch_pubsub.py new file mode 100644 index 0000000..8bbf203 --- /dev/null +++ b/mros2_echoback_vector3/launch/launch_pubsub.py @@ -0,0 +1,21 @@ +from launch import LaunchDescription +from launch_ros.actions import Node + +# Note: `node_`, `prefix` and `output` will be removed on Foxy +def generate_launch_description(): + return LaunchDescription([ + Node( + package='mros2_echoback_vector3', + node_executable='pub_node', + node_name='pub_mros2', + prefix=['stdbuf -o L'], + output="screen" + ), + Node( + package='mros2_echoback_vector3', + node_executable='sub_node', + node_name='mros2_sub', + prefix=['stdbuf -o L'], + output="screen" + ) + ]) \ No newline at end of file diff --git a/mros2_echoback_vector3/package.xml b/mros2_echoback_vector3/package.xml new file mode 100644 index 0000000..cb043c9 --- /dev/null +++ b/mros2_echoback_vector3/package.xml @@ -0,0 +1,21 @@ + + + + mros2_echoback_vector3 + 0.0.0 + TODO: Package description + uden + TODO: License declaration + + ament_cmake +rclcpp +geometry_msgs +rclcpp +geometry_msgs + ament_lint_auto + ament_lint_common + + + ament_cmake + + \ No newline at end of file diff --git a/mros2_echoback_vector3/src/pub_node.cpp b/mros2_echoback_vector3/src/pub_node.cpp new file mode 100644 index 0000000..a662f62 --- /dev/null +++ b/mros2_echoback_vector3/src/pub_node.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +#include "rclcpp/rclcpp.hpp" +#include "geometry_msgs/msg/vector3.hpp" + +using namespace std::chrono_literals; + +/* This example creates a subclass of Node and uses std::bind() to register a +* member function as a callback from the timer. */ + +class Publisher : public rclcpp::Node +{ +public: + Publisher() + : Node("pub_mros2"), count_(0) + { + publisher_ = this->create_publisher("to_stm", 10); + timer_ = this->create_wall_timer(1000ms, std::bind(&Publisher::timer_callback, this)); + } + +private: + void timer_callback() + { + auto message = geometry_msgs::msg::Vector3(); + message.x = count_++/10.0; + message.y = 2*count_++/10.0; + message.z = 3*count_++/10.0; + RCLCPP_INFO(this->get_logger(), "Publishing msg: { x: %f, y: %f, z: %f }", message.x,message.y, message.z); + publisher_->publish(message); + } + rclcpp::TimerBase::SharedPtr timer_; + rclcpp::Publisher::SharedPtr publisher_; + size_t count_; +}; + +int main(int argc, char *argv[]) +{ + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +} \ No newline at end of file diff --git a/mros2_echoback_vector3/src/sub_node.cpp b/mros2_echoback_vector3/src/sub_node.cpp new file mode 100644 index 0000000..d40cf44 --- /dev/null +++ b/mros2_echoback_vector3/src/sub_node.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#include "rclcpp/rclcpp.hpp" +#include "geometry_msgs/msg/vector3.hpp" + +using std::placeholders::_1; + +class Subscriber : public rclcpp::Node +{ +public: + Subscriber() : Node("mros2_sub") + { + subscriber_ = this->create_subscription("to_linux", rclcpp::QoS(10).best_effort(), std::bind(&Subscriber::topic_callback, this, _1)); + } + +private: + void topic_callback(const geometry_msgs::msg::Vector3::SharedPtr message) const + { + RCLCPP_INFO(this->get_logger(), "Subscribed msg: { x: %f, y: %f, z: %f }", message->x,message->y, message->z); + } + rclcpp::Subscription::SharedPtr subscriber_; +}; + + +int main(int argc, char *argv[]) +{ + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +} \ No newline at end of file