Skip to content

Commit

Permalink
Merge pull request #27 from ru2saig/humble-devel
Browse files Browse the repository at this point in the history
My go at a procedural implementation example of subscriber node
  • Loading branch information
fmrico authored Oct 24, 2023
2 parents 704ff71 + 139a0ee commit 1d3f450
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions br2_basics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ set(dependencies
add_executable(publisher src/publisher.cpp)
ament_target_dependencies(publisher ${dependencies})

add_executable(subscriber src/subscriber.cpp)
ament_target_dependencies(subscriber ${dependencies})

add_executable(publisher_class src/publisher_class.cpp)
ament_target_dependencies(publisher_class ${dependencies})

Expand All @@ -34,6 +37,7 @@ ament_target_dependencies(param_reader ${dependencies})
install(TARGETS
publisher
publisher_class
subscriber
subscriber_class
executors
logger
Expand Down
33 changes: 33 additions & 0 deletions br2_basics/src/subscriber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2023 Nidhish Chadive (ru2saig)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int32.hpp"

void callback(const std_msgs::msg::Int32::SharedPtr msg)
{
RCLCPP_INFO(rclcpp::get_logger("subscriber"), "Hello %d", msg->data);
}

int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
auto node = rclcpp::Node::make_shared("subscriber_node");
auto subscriber = node->create_subscription<std_msgs::msg::Int32>("int_topic", 10, &callback);

rclcpp::spin(node);

rclcpp::shutdown();
return 0;
}

0 comments on commit 1d3f450

Please sign in to comment.