Robotics StackExchange | Archived questions

[ROS2] Subscriber in hardware_interface plugin

Configuration:

Hi, I am trying to create a hardwareinterface plugin for ros2control. I want to create a publisher to write() and a subscriber to read(). I am running into issues setting up the subscriber. The code is given below.

DiffDriveSystemHardware::DiffDriveSystemHardware() : Node("hardware_interface_publisher")
{
    publisher_[0] = this->create_publisher<std_msgs::msg::Float32>("/right_velocity_command", 10);
    publisher_[1] = this->create_publisher<std_msgs::msg::Float32>("/left_velocity_command", 10);

auto rightCB = [this](const std_msgs::msg::Float32::SharedPtr state) -> void
{ RCLCPP_INFO(rclcpp::get_logger("DiffDriveSystemHardware"), "Right Callback %f", state->data); };
subscription_[0] = this->create_subscription<std_msgs::msg::Float32>(
    "/right_position_state", 0, rightCB);
RCLCPP_INFO(rclcpp::get_logger("DiffDriveSystemHardware"), "Added Right Callback");

auto leftCB = [this](const std_msgs::msg::Float32::SharedPtr state) -> void
{ RCLCPP_INFO(rclcpp::get_logger("DiffDriveSystemHardware"), "Left Callback", state); };
subscription_[1] = this->create_subscription<std_msgs::msg::Float32>(
    "/left_position_state", 0, leftCB);
RCLCPP_INFO(rclcpp::get_logger("DiffDriveSystemHardware"), "Added Left Callback");
}

The publisher works fine, but the callback of the subscriber does not get called. Am I missing something? Any help is appreciated Thank you.

Asked by Ammar Albakri on 2023-02-01 02:30:20 UTC

Comments

Answers