-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Autumn60 <[email protected]>
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(simple_int_subscriber) | ||
|
||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
endif() | ||
|
||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
find_package(ament_cmake_auto REQUIRED) | ||
ament_auto_find_build_dependencies() | ||
|
||
ament_auto_add_library(simple_int_subscriber SHARED | ||
src/simple_int_subscriber.cpp | ||
) | ||
|
||
rclcpp_components_register_node(simple_int_subscriber | ||
PLUGIN "simple_int_subscriber::SimpleIntSubscriber" | ||
EXECUTABLE simple_int_subscriber_node | ||
) | ||
|
||
if(BUILD_TESTING) | ||
find_package(ament_lint_auto REQUIRED) | ||
ament_lint_auto_find_test_dependencies() | ||
endif() | ||
|
||
ament_auto_package(INSTALL_TO_SHARE | ||
launch | ||
) |
28 changes: 28 additions & 0 deletions
28
src/sample/simple_int_subscriber/include/simple_int_subscriber/simple_int_subscriber.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef SIMPLE_INT_SUBSCRIBER__SIMPLE_INT_SUBSCRIBER_HPP_ | ||
#define SIMPLE_INT_SUBSCRIBER__SIMPLE_INT_SUBSCRIBER_HPP_ | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <std_msgs/msg/int32.hpp> | ||
|
||
namespace simple_int_subscriber | ||
{ | ||
|
||
using Int32 = std_msgs::msg::Int32; | ||
|
||
using Int32Subscription = rclcpp::Subscription<Int32>; | ||
|
||
class SimpleIntSubscriber : public rclcpp::Node | ||
{ | ||
public: | ||
explicit SimpleIntSubscriber(const rclcpp::NodeOptions & options); | ||
|
||
private: | ||
void callback(const Int32::SharedPtr msg); | ||
|
||
Int32Subscription::SharedPtr sub_; | ||
}; | ||
|
||
} // namespace simple_int_subscriber | ||
|
||
#endif // SIMPLE_INT_SUBSCRIBER__SIMPLE_INT_SUBSCRIBER_HPP_ |
7 changes: 7 additions & 0 deletions
7
src/sample/simple_int_subscriber/launch/simple_int_subscriber.launch.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<launch> | ||
<arg name="topic" default="/sample/int"/> | ||
|
||
<node pkg="simple_int_subscriber" name="simple_int_subscriber" exec="simple_int_subscriber_node" output="screen"> | ||
<remap from="~/input/int" to="$(var topic)"/> | ||
</node> | ||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>simple_int_subscriber</name> | ||
<version>0.0.0</version> | ||
<description>The simple_int_subscriber package</description> | ||
<maintainer email="[email protected]">Akiro Harada</maintainer> | ||
|
||
<license>Apache 2</license> | ||
|
||
<buildtool_depend>ament_cmake_auto</buildtool_depend> | ||
|
||
<depend>rclcpp</depend> | ||
<depend>rclcpp_components</depend> | ||
<depend>std_msgs</depend> | ||
<test_depend>ament_lint_auto</test_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
24 changes: 24 additions & 0 deletions
24
src/sample/simple_int_subscriber/src/simple_int_subscriber.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "simple_int_subscriber/simple_int_subscriber.hpp" | ||
|
||
namespace simple_int_subscriber | ||
{ | ||
|
||
SimpleIntSubscriber::SimpleIntSubscriber(const rclcpp::NodeOptions & options) | ||
: Node("simple_int_subscriber", options) | ||
{ | ||
// Declare Subscribers | ||
{ | ||
sub_ = this->create_subscription<Int32>( | ||
"~/input/int", 1, [this](const Int32::SharedPtr msg) { this->callback(msg); }); | ||
} | ||
} | ||
|
||
void SimpleIntSubscriber::callback(const Int32::SharedPtr msg) | ||
{ | ||
std::cout << "Received: '" << msg->data << "'" << std::endl; | ||
} | ||
|
||
} // namespace simple_int_subscriber | ||
|
||
#include "rclcpp_components/register_node_macro.hpp" | ||
RCLCPP_COMPONENTS_REGISTER_NODE(simple_int_subscriber::SimpleIntSubscriber) |