ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

petermp's profile - activity

2018-08-08 01:58:25 -0500 marked best answer Can a subscriber and publisher co-exist in a single nodelet?

I have a need to implement a nodelet that subscribes for messages from a topic, process them and then publish to another topic.

Can this be done using a single nodelet?


Edit: I tried the below demo, but see only publishing msgs. Sub's callback are not invoked.

#include <chrono>
#include <iostream>
#include <memory>

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

using namespace std::chrono_literals;

namespace composition
{

// Create a Talker "component" that subclasses the generic rclcpp::Node base class.
// Components get built into shared libraries and as such do not write their own main functions.
// The process using the component's shared library will instantiate the class as a ROS node.
Peter::Peter()
: Node("peter"), count_(0)
{
  // Create a publisher of "std_mgs/String" messages on the "chatter" topic.
  pub_ = create_publisher<std_msgs::msg::String>("chatter");

  // Use a timer to schedule periodic message publishing.
  timer_ = create_wall_timer(1s, std::bind(&Peter::on_timer, this));

  // Create a callback function for when messages are received.
  // Variations of this function also exist using, for example, UniquePtr for zero-copy transport.
  auto callback =
    [this](const typename std_msgs::msg::String::SharedPtr msg) -> void
    {
      RCLCPP_INFO(this->get_logger(), "I heard: [%s]", msg->data.c_str())
      std::flush(std::cout);
    };

  // Create a subscription to the "chatter" topic which can be matched with one or more
  // compatible ROS publishers.
  // Note that not all publishers on the same topic with the same type will be compatible:
  // they must have compatible Quality of Service policies.
  auto sub_ = create_subscription<std_msgs::msg::String>("chatter", callback);
}

void Peter::on_timer()
{
  auto msg = std::make_shared<std_msgs::msg::String>();
  msg->data = "Peter is here: " + std::to_string(++count_);
  RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", msg->data.c_str())
  std::flush(std::cout);

  // Put the message into a queue to be processed by the middleware.
  // This call is non-blocking.
  pub_->publish(msg);
}

}  // namespace composition

#include "class_loader/class_loader_register_macro.h"

// Register the component with class_loader.
// This acts as a sort of entry point, allowing the component to be discoverable when its library
// is being loaded into a running process.
CLASS_LOADER_REGISTER_CLASS(composition::Peter, rclcpp::Node)
2018-05-07 19:02:15 -0500 received badge  Popular Question (source)
2018-05-04 13:13:46 -0500 received badge  Enthusiast
2018-05-03 19:04:02 -0500 commented question receiving messages of previous run

I invoke the rostopic command from a bash file to send the message to the subscribing node. The rostopic command termina

2018-05-03 17:48:08 -0500 commented question receiving messages of previous run

It is a simple example, out of ros tutorial, the app starts and waits for message that triggers a callback. The callback

2018-05-03 15:42:43 -0500 asked a question receiving messages of previous run

receiving messages of previous run Are there anything wrong with my subscribing statement below? ros::Subscriber builde

2018-04-09 00:22:34 -0500 received badge  Famous Question (source)
2018-04-03 04:32:26 -0500 answered a question How to adjust work thread when load a nodelet from roscpp API?

I found the answer in the file rclcpp/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp, which defines the cl

2018-04-03 04:10:15 -0500 commented question How to adjust work thread when load a nodelet from roscpp API?

I am in search of the same answer :) Hope someone will pay attention to your question with a helpful tip.

2018-03-28 12:14:42 -0500 commented question Can a subscriber and publisher co-exist in a single nodelet?

Thanks. I am new to the forum and apparently made some edit mistakes. I am able to get the code working and confirm th

2018-03-28 04:38:59 -0500 received badge  Notable Question (source)
2018-03-27 20:26:22 -0500 received badge  Popular Question (source)
2018-03-27 16:26:11 -0500 answered a question Can a subscriber and publisher co-exist in a single nodelet?

include <chrono> include <iostream> include <memory> include "rclcpp/rclcpp.hpp" include "std_msgs

2018-03-27 16:25:25 -0500 commented answer Can a subscriber and publisher co-exist in a single nodelet?

I tried the below demo, but see only publishing msgs. Sub's callback are not invoked.

2018-03-27 15:50:24 -0500 answered a question Can a subscriber and publisher co-exist in a single nodelet?

include "composition/peter_component.hpp" I did as in the demo code below, but the subscriber's callback is not invoked

2018-03-27 13:51:53 -0500 asked a question Can subscriber and publisher be used in the same nodelet

Can subscriber and publisher be used in the same nodelet I need to implement a nodelet receiving messages, process it an

2018-03-27 13:33:02 -0500 asked a question Using pubisher and subscriber in the same nodelet

Using pubisher and subscriber in the same nodelet I wonder if I can implement a nodelet that subscribes to one topic and

2018-03-27 13:33:01 -0500 asked a question Can a subscriber and publisher co-exist in a single nodelet?

Can a subscriber and publisher co-exist in a single nodelet? I have a need to implement a nodelet that subscribes for me