[ROS2] Subscriber in hardware_interface plugin

asked 2023-02-01 01:30:20 -0500

Ammar Albakri gravatar image

Configuration:

  • ROS Distro: Foxy
  • OS Version: Ubuntu 20.0

Hi, I am trying to create a hardware_interface plugin for ros2_control. 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.

edit retag flag offensive close merge delete