Cannot build the dynamixel hardware interface in ros2_control course

I followed the ros2 control course and tried to use the dynamixel hardware interface in my own labtop and this error was come. I’m not familiar with C++ so If someone know what should I fix, please tell me. Basically, I just copy and paste the code from the code to my pkg. I use ros2 foxy and DynamixelSDK and also workbench were also cloned from foxy-devel branch. In the terminal inside the Construct, nothing error.

In file included from /home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:7:
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/include/dynamixel_hardware_interface/dynamixel_hardware_interface.hpp:44:3: error: ‘CallbackReturn’ does not name a type
   44 |   CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override;
      |   ^~~~~~~~~~~~~~
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/include/dynamixel_hardware_interface/dynamixel_hardware_interface.hpp:50:3: error: ‘CallbackReturn’ does not name a type
   50 |   CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;
      |   ^~~~~~~~~~~~~~
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/include/dynamixel_hardware_interface/dynamixel_hardware_interface.hpp:52:3: error: ‘CallbackReturn’ does not name a type
   52 |   CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;
      |   ^~~~~~~~~~~~~~
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:27:1: error: ‘CallbackReturn’ does not name a type
   27 | CallbackReturn DynamixelHardware::on_init(const hardware_interface::HardwareInfo & info)
      | ^~~~~~~~~~~~~~
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘virtual std::vector<hardware_interface::StateInterface> dynamixel_hardware::DynamixelHardware::export_state_interfaces()’:
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:157:24: error: ‘info_’ was not declared in this scope
  157 |   for (uint i = 0; i < info_.joints.size(); i++) {
      |                        ^~~~~
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘virtual std::vector<hardware_interface::CommandInterface> dynamixel_hardware::DynamixelHardware::export_command_interfaces()’:
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:173:24: error: ‘info_’ was not declared in this scope
  173 |   for (uint i = 0; i < info_.joints.size(); i++) {
      |                        ^~~~~
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: At global scope:
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:183:1: error: ‘CallbackReturn’ does not name a type
  183 | CallbackReturn DynamixelHardware::on_activate(const rclcpp_lifecycle::State & previous_state)
      | ^~~~~~~~~~~~~~
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:200:1: error: ‘CallbackReturn’ does not name a type
  200 | CallbackReturn DynamixelHardware::on_deactivate(const rclcpp_lifecycle::State & previous_state)
      | ^~~~~~~~~~~~~~
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘virtual hardware_interface::return_type dynamixel_hardware::DynamixelHardware::read()’:
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:212:28: error: ‘info_’ was not declared in this scope
  212 |   std::vector<uint8_t> ids(info_.joints.size(), 0);
      |                            ^~~~~
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘virtual hardware_interface::return_type dynamixel_hardware::DynamixelHardware::write()’:
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:265:28: error: ‘info_’ was not declared in this scope
  265 |   std::vector<uint8_t> ids(info_.joints.size(), 0);
      |                            ^~~~~
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘hardware_interface::return_type dynamixel_hardware::DynamixelHardware::enable_torque(bool)’:
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:310:26: error: ‘info_’ was not declared in this scope
  310 |     for (uint i = 0; i < info_.joints.size(); ++i) {
      |                          ^~~~~
/home/tharit/ros2_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:319:26: error: ‘info_’ was not declared in this scope
  319 |     for (uint i = 0; i < info_.joints.size(); ++i) {
      |                          ^~~~~
make[2]: *** [CMakeFiles/dynamixel_hardware_interface.dir/build.make:63: CMakeFiles/dynamixel_hardware_interface.dir/src/dynamixel_hardware_interface.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/dynamixel_hardware_interface.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed   <<< dynamixel_hardware_interface [1.83s, exited with code 2]

Summary: 12 packages finished [2.98s]
  1 package failed: dynamixel_hardware_interface
  1 package had stderr output: dynamixel_hardware_interface

Here is the .cpp code

#include <algorithm>
#include <array>
#include <string>
#include <limits>
#include <vector>

#include "dynamixel_hardware_interface/dynamixel_hardware_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_type_values.hpp"
#include "rclcpp/rclcpp.hpp"

namespace dynamixel_hardware
{
constexpr const char * kDynamixelHardware = "DynamixelHardware";
constexpr uint8_t kGoalPositionIndex = 0;
constexpr uint8_t kGoalVelocityIndex = 1;
constexpr uint8_t kPresentPositionVelocityCurrentIndex = 0;
constexpr const char * kGoalPositionItem = "Goal_Position";
constexpr const char * kGoalVelocityItem = "Goal_Velocity";
constexpr const char * kMovingSpeedItem = "Moving_Speed";
constexpr const char * kPresentPositionItem = "Present_Position";
constexpr const char * kPresentVelocityItem = "Present_Velocity";
constexpr const char * kPresentSpeedItem = "Present_Speed";
constexpr const char * kPresentCurrentItem = "Present_Current";
constexpr const char * kPresentLoadItem = "Present_Load";

CallbackReturn DynamixelHardware::on_init(const hardware_interface::HardwareInfo & info)
{
  RCLCPP_DEBUG(rclcpp::get_logger(kDynamixelHardware), "configure");
  if (hardware_interface::SystemInterface::on_init(info) != CallbackReturn::SUCCESS)
  {
    return CallbackReturn::ERROR;
  }

  joints_.resize(info_.joints.size(), Joint());
  joint_ids_.resize(info_.joints.size(), 0);

  for (uint i = 0; i < info_.joints.size(); i++) {
    joint_ids_[i] = std::stoi(info_.joints[i].parameters.at("id"));
    joints_[i].state.position = std::numeric_limits<double>::quiet_NaN();
    joints_[i].state.velocity = std::numeric_limits<double>::quiet_NaN();
    joints_[i].state.effort = std::numeric_limits<double>::quiet_NaN();
    joints_[i].command.position = std::numeric_limits<double>::quiet_NaN();
    joints_[i].command.velocity = std::numeric_limits<double>::quiet_NaN();
    joints_[i].command.effort = std::numeric_limits<double>::quiet_NaN();
    RCLCPP_INFO(rclcpp::get_logger(kDynamixelHardware), "joint_id %d: %d", i, joint_ids_[i]);
  }

  if (
    info_.hardware_parameters.find("use_dummy") != info_.hardware_parameters.end() &&
    info_.hardware_parameters.at("use_dummy") == "true") {
    use_dummy_ = true;
    RCLCPP_INFO(rclcpp::get_logger(kDynamixelHardware), "dummy mode");
    return CallbackReturn::SUCCESS;
  }

  auto usb_port = info_.hardware_parameters.at("usb_port");
  auto baud_rate = std::stoi(info_.hardware_parameters.at("baud_rate"));
  const char * log = nullptr;

  RCLCPP_INFO(rclcpp::get_logger(kDynamixelHardware), "usb_port: %s", usb_port.c_str());
  RCLCPP_INFO(rclcpp::get_logger(kDynamixelHardware), "baud_rate: %d", baud_rate);

  if (!dynamixel_workbench_.init(usb_port.c_str(), baud_rate, &log)) {
    RCLCPP_FATAL(rclcpp::get_logger(kDynamixelHardware), "%s", log);
    return CallbackReturn::ERROR;
  }

  for (uint i = 0; i < info_.joints.size(); ++i) {
    uint16_t model_number = 0;
    if (!dynamixel_workbench_.ping(joint_ids_[i], &model_number, &log)) {
      RCLCPP_FATAL(rclcpp::get_logger(kDynamixelHardware), "%s", log);
      return CallbackReturn::ERROR;
    }
  }

  enable_torque(false);
  set_control_mode(ControlMode::Position, true);
  enable_torque(true);

  const ControlItem * goal_position =
    dynamixel_workbench_.getItemInfo(joint_ids_[0], kGoalPositionItem);
  if (goal_position == nullptr) {
    return CallbackReturn::ERROR;
  }

  const ControlItem * goal_velocity =
    dynamixel_workbench_.getItemInfo(joint_ids_[0], kGoalVelocityItem);
  if (goal_velocity == nullptr) {
    goal_velocity = dynamixel_workbench_.getItemInfo(joint_ids_[0], kMovingSpeedItem);
  }
  if (goal_velocity == nullptr) {
    return CallbackReturn::ERROR;
  }

  const ControlItem * present_position =
    dynamixel_workbench_.getItemInfo(joint_ids_[0], kPresentPositionItem);
  if (present_position == nullptr) {
    return CallbackReturn::ERROR;
  }

  const ControlItem * present_velocity =
    dynamixel_workbench_.getItemInfo(joint_ids_[0], kPresentVelocityItem);
  if (present_velocity == nullptr) {
    present_velocity = dynamixel_workbench_.getItemInfo(joint_ids_[0], kPresentSpeedItem);
  }
  if (present_velocity == nullptr) {
    return CallbackReturn::ERROR;
  }

  const ControlItem * present_current =
    dynamixel_workbench_.getItemInfo(joint_ids_[0], kPresentCurrentItem);
  if (present_current == nullptr) {
    present_current = dynamixel_workbench_.getItemInfo(joint_ids_[0], kPresentLoadItem);
  }
  if (present_current == nullptr) {
    return CallbackReturn::ERROR;
  }

  control_items_[kGoalPositionItem] = goal_position;
  control_items_[kGoalVelocityItem] = goal_velocity;
  control_items_[kPresentPositionItem] = present_position;
  control_items_[kPresentVelocityItem] = present_velocity;
  control_items_[kPresentCurrentItem] = present_current;

  if (!dynamixel_workbench_.addSyncWriteHandler(
        control_items_[kGoalPositionItem]->address, control_items_[kGoalPositionItem]->data_length,
        &log)) {
    RCLCPP_FATAL(rclcpp::get_logger(kDynamixelHardware), "%s", log);
    return CallbackReturn::ERROR;
  }

  if (!dynamixel_workbench_.addSyncWriteHandler(
        control_items_[kGoalVelocityItem]->address, control_items_[kGoalVelocityItem]->data_length,
        &log)) {
    RCLCPP_FATAL(rclcpp::get_logger(kDynamixelHardware), "%s", log);
    return CallbackReturn::ERROR;
  }

  uint16_t start_address = std::min(
    control_items_[kPresentPositionItem]->address, control_items_[kPresentCurrentItem]->address);
  uint16_t read_length = control_items_[kPresentPositionItem]->data_length +
                         control_items_[kPresentVelocityItem]->data_length +
                         control_items_[kPresentCurrentItem]->data_length + 2;
  if (!dynamixel_workbench_.addSyncReadHandler(start_address, read_length, &log)) {
    RCLCPP_FATAL(rclcpp::get_logger(kDynamixelHardware), "%s", log);
    return CallbackReturn::ERROR;
  }

  return CallbackReturn::SUCCESS;
}

std::vector<hardware_interface::StateInterface> DynamixelHardware::export_state_interfaces()
{
  RCLCPP_DEBUG(rclcpp::get_logger(kDynamixelHardware), "export_state_interfaces");
  std::vector<hardware_interface::StateInterface> state_interfaces;
  for (uint i = 0; i < info_.joints.size(); i++) {
    state_interfaces.emplace_back(hardware_interface::StateInterface(
      info_.joints[i].name, hardware_interface::HW_IF_POSITION, &joints_[i].state.position));
    state_interfaces.emplace_back(hardware_interface::StateInterface(
      info_.joints[i].name, hardware_interface::HW_IF_VELOCITY, &joints_[i].state.velocity));
    state_interfaces.emplace_back(hardware_interface::StateInterface(
      info_.joints[i].name, hardware_interface::HW_IF_EFFORT, &joints_[i].state.effort));
  }

  return state_interfaces;
}

std::vector<hardware_interface::CommandInterface> DynamixelHardware::export_command_interfaces()
{
  RCLCPP_DEBUG(rclcpp::get_logger(kDynamixelHardware), "export_command_interfaces");
  std::vector<hardware_interface::CommandInterface> command_interfaces;
  for (uint i = 0; i < info_.joints.size(); i++) {
    command_interfaces.emplace_back(hardware_interface::CommandInterface(
      info_.joints[i].name, hardware_interface::HW_IF_POSITION, &joints_[i].command.position));
    command_interfaces.emplace_back(hardware_interface::CommandInterface(
      info_.joints[i].name, hardware_interface::HW_IF_VELOCITY, &joints_[i].command.velocity));
  }

  return command_interfaces;
}

CallbackReturn DynamixelHardware::on_activate(const rclcpp_lifecycle::State & previous_state)
{
  RCLCPP_DEBUG(rclcpp::get_logger(kDynamixelHardware), "start");
  for (uint i = 0; i < joints_.size(); i++) {
    if (use_dummy_ && std::isnan(joints_[i].state.position)) {
      joints_[i].state.position = 0.0;
      joints_[i].state.velocity = 0.0;
      joints_[i].state.effort = 0.0;
    }
  }
  read();
  reset_command();
  write();

  return CallbackReturn::SUCCESS;
}

CallbackReturn DynamixelHardware::on_deactivate(const rclcpp_lifecycle::State & previous_state)
{
  RCLCPP_DEBUG(rclcpp::get_logger(kDynamixelHardware), "stop");
  return CallbackReturn::SUCCESS;
}

return_type DynamixelHardware::read()
{
  if (use_dummy_) {
    return return_type::OK;
  }

  std::vector<uint8_t> ids(info_.joints.size(), 0);
  std::vector<int32_t> positions(info_.joints.size(), 0);
  std::vector<int32_t> velocities(info_.joints.size(), 0);
  std::vector<int32_t> currents(info_.joints.size(), 0);

  std::copy(joint_ids_.begin(), joint_ids_.end(), ids.begin());
  const char * log = nullptr;

  if (!dynamixel_workbench_.syncRead(
        kPresentPositionVelocityCurrentIndex, ids.data(), ids.size(), &log)) {
    RCLCPP_ERROR(rclcpp::get_logger(kDynamixelHardware), "%s", log);
  }

  if (!dynamixel_workbench_.getSyncReadData(
        kPresentPositionVelocityCurrentIndex, ids.data(), ids.size(),
        control_items_[kPresentCurrentItem]->address,
        control_items_[kPresentCurrentItem]->data_length, currents.data(), &log)) {
    RCLCPP_ERROR(rclcpp::get_logger(kDynamixelHardware), "%s", log);
  }

  if (!dynamixel_workbench_.getSyncReadData(
        kPresentPositionVelocityCurrentIndex, ids.data(), ids.size(),
        control_items_[kPresentVelocityItem]->address,
        control_items_[kPresentVelocityItem]->data_length, velocities.data(), &log)) {
    RCLCPP_ERROR(rclcpp::get_logger(kDynamixelHardware), "%s", log);
  }

  if (!dynamixel_workbench_.getSyncReadData(
        kPresentPositionVelocityCurrentIndex, ids.data(), ids.size(),
        control_items_[kPresentPositionItem]->address,
        control_items_[kPresentPositionItem]->data_length, positions.data(), &log)) {
    RCLCPP_ERROR(rclcpp::get_logger(kDynamixelHardware), "%s", log);
  }

  for (uint i = 0; i < ids.size(); i++) {
    joints_[i].state.position = dynamixel_workbench_.convertValue2Radian(ids[i], positions[i]);
    joints_[i].state.velocity = dynamixel_workbench_.convertValue2Velocity(ids[i], velocities[i]);
    joints_[i].state.effort = dynamixel_workbench_.convertValue2Current(currents[i]);
  }

  return return_type::OK;
}

return_type DynamixelHardware::write()
{
  if (use_dummy_) {
    for (auto & joint : joints_) {
      joint.state.position = joint.command.position;
    }

    return return_type::OK;
  }

  std::vector<uint8_t> ids(info_.joints.size(), 0);
  std::vector<int32_t> commands(info_.joints.size(), 0);

  std::copy(joint_ids_.begin(), joint_ids_.end(), ids.begin());
  const char * log = nullptr;

  if (std::any_of(
        joints_.cbegin(), joints_.cend(), [](auto j) { return j.command.velocity != 0.0; })) {
    // Velocity control
    set_control_mode(ControlMode::Velocity);
    for (uint i = 0; i < ids.size(); i++) {
      commands[i] = dynamixel_workbench_.convertVelocity2Value(
        ids[i], static_cast<float>(joints_[i].command.velocity));
    }
    if (!dynamixel_workbench_.syncWrite(
          kGoalVelocityIndex, ids.data(), ids.size(), commands.data(), 1, &log)) {
      RCLCPP_ERROR(rclcpp::get_logger(kDynamixelHardware), "%s", log);
    }
    return return_type::OK;
  } else if (std::any_of(
               joints_.cbegin(), joints_.cend(), [](auto j) { return j.command.effort != 0.0; })) {
    // Effort control
    RCLCPP_ERROR(rclcpp::get_logger(kDynamixelHardware), "Effort control is not implemented");
    return return_type::ERROR;
  }

  // Position control
  set_control_mode(ControlMode::Position);
  for (uint i = 0; i < ids.size(); i++) {
    commands[i] = dynamixel_workbench_.convertRadian2Value(
      ids[i], static_cast<float>(joints_[i].command.position));
  }
  if (!dynamixel_workbench_.syncWrite(
        kGoalPositionIndex, ids.data(), ids.size(), commands.data(), 1, &log)) {
    RCLCPP_ERROR(rclcpp::get_logger(kDynamixelHardware), "%s", log);
  }

  return return_type::OK;
}

return_type DynamixelHardware::enable_torque(const bool enabled)
{
  const char * log = nullptr;

  if (enabled && !torque_enabled_) {
    for (uint i = 0; i < info_.joints.size(); ++i) {
      if (!dynamixel_workbench_.torqueOn(joint_ids_[i], &log)) {
        RCLCPP_FATAL(rclcpp::get_logger(kDynamixelHardware), "%s", log);
        return return_type::ERROR;
      }
    }
    reset_command();
    RCLCPP_INFO(rclcpp::get_logger(kDynamixelHardware), "Torque enabled");
  } else if (!enabled && torque_enabled_) {
    for (uint i = 0; i < info_.joints.size(); ++i) {
      if (!dynamixel_workbench_.torqueOff(joint_ids_[i], &log)) {
        RCLCPP_FATAL(rclcpp::get_logger(kDynamixelHardware), "%s", log);
        return return_type::ERROR;
      }
    }
    RCLCPP_INFO(rclcpp::get_logger(kDynamixelHardware), "Torque disabled");
  }

  torque_enabled_ = enabled;
  return return_type::OK;
}

return_type DynamixelHardware::set_control_mode(const ControlMode & mode, const bool force_set)
{
  const char * log = nullptr;

  if (mode == ControlMode::Velocity && (force_set || control_mode_ != ControlMode::Velocity)) {
    bool torque_enabled = torque_enabled_;
    if (torque_enabled) {
      enable_torque(false);
    }

    for (uint i = 0; i < joint_ids_.size(); ++i) {
      if (!dynamixel_workbench_.setVelocityControlMode(joint_ids_[i], &log)) {
        RCLCPP_FATAL(rclcpp::get_logger(kDynamixelHardware), "%s", log);
        return return_type::ERROR;
      }
    }
    RCLCPP_INFO(rclcpp::get_logger(kDynamixelHardware), "Velocity control");
    control_mode_ = ControlMode::Velocity;

    if (torque_enabled) {
      enable_torque(true);
    }
  } else if (
    mode == ControlMode::Position && (force_set || control_mode_ != ControlMode::Position)) {
    bool torque_enabled = torque_enabled_;
    if (torque_enabled) {
      enable_torque(false);
    }

    for (uint i = 0; i < joint_ids_.size(); ++i) {
      if (!dynamixel_workbench_.setPositionControlMode(joint_ids_[i], &log)) {
        RCLCPP_FATAL(rclcpp::get_logger(kDynamixelHardware), "%s", log);
        return return_type::ERROR;
      }
    }
    RCLCPP_INFO(rclcpp::get_logger(kDynamixelHardware), "Position control");
    control_mode_ = ControlMode::Position;

    if (torque_enabled) {
      enable_torque(true);
    }
  } else if (control_mode_ != ControlMode::Velocity && control_mode_ != ControlMode::Position) {
    RCLCPP_FATAL(
      rclcpp::get_logger(kDynamixelHardware), "Only position/velocity control are implemented");
    return return_type::ERROR;
  }

  return return_type::OK;
}

return_type DynamixelHardware::reset_command()
{
  for (uint i = 0; i < joints_.size(); i++) {
    joints_[i].command.position = joints_[i].state.position;
    joints_[i].command.velocity = 0.0;
    joints_[i].command.effort = 0.0;
  }

  return return_type::OK;
}

}  // namespace dynamixel_hardware 

#include "pluginlib/class_list_macros.hpp"

PLUGINLIB_EXPORT_CLASS(dynamixel_hardware::DynamixelHardware, hardware_interface::SystemInterface)

Hello @pbnpama ,

The course has been developed and tested on a specific environment (for instance, this course is in ROS2 Galactic). So, trying it outside the course environment might not work directly. Unfortunately, it’s impossible for us to provide support for each specific local environment (every student has a different local environment). If you are working in ROS2 Foxy, make sure that all the packages/code you are trying to build is compatible with this distribution. If you copy/pasted code from the course, it might not be directly compatible.

Thank you for your answer, I also think that the distro is the main problem. I’ve tried to edit some part but still error.

Currently, the error is solved by define the CallbackReturn in the .hpp file.

#ifndef DYNAMIXEL_HARDWARE__DYNAMIXEL_HARDWARE_HPP_
#define DYNAMIXEL_HARDWARE__DYNAMIXEL_HARDWARE_HPP_

#include <vector>
#include <map>

#include <hardware_interface/handle.hpp>
#include <hardware_interface/hardware_info.hpp>
#include <hardware_interface/system_interface.hpp>
#include <rclcpp_lifecycle/state.hpp> 
#include "rclcpp/macros.hpp"

#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
#include "rclcpp_lifecycle/lifecycle_publisher.hpp"

#include <dynamixel_workbench_toolbox/dynamixel_workbench.h>

using hardware_interface::return_type;

using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;

namespace dynamixel_hardware {
struct JointValue {
  double position{0.0};
  double velocity{0.0};
  double effort{0.0};
};

struct Joint {
  JointValue state{};
  JointValue command{};
};

enum class ControlMode {
  Position,
  Velocity,
  Torque,
  Currrent,
  ExtendedPosition,
  MultiTurn,
  CurrentBasedPosition,
  PWM,
};

class DynamixelHardware : public hardware_interface::SystemInterface {
public:
  RCLCPP_SHARED_PTR_DEFINITIONS(DynamixelHardware)

  CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override;

  std::vector<hardware_interface::StateInterface> export_state_interfaces() override;

  std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;

  CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;

  CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;

  return_type read() override;

  return_type write() override;

private:
  return_type enable_torque(const bool enabled);
  return_type set_control_mode(const ControlMode & mode, const bool force_set = false);
  return_type reset_command();

  DynamixelWorkbench dynamixel_workbench_;
  std::map<const char * const, const ControlItem *> control_items_;
  std::vector<Joint> joints_;
  std::vector<uint8_t> joint_ids_;
  bool torque_enabled_{false};
  ControlMode control_mode_{ControlMode::Position};
  bool use_dummy_{false};
};
}  // namespace dynamixel_hardware

#endif  // DYNAMIXEL_HARDWARE__DYNAMIXEL_HARDWARE_HPP_

By this the error about override came. So I just delete overrride specifier now the error is here

/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:30:44: error: ‘on_init’ is not a member of ‘hardware_interface::SystemInterface’
   30 |   if (hardware_interface::SystemInterface::on_init(info) != CallbackReturn::SUCCESS)
      |                                            ^~~~~~~
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:35:18: error: ‘info_’ was not declared in this scope; did you mean ‘info’?
   35 |   joints_.resize(info_.joints.size(), Joint());
      |                  ^~~~~
      |                  info
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘virtual std::vector<hardware_interface::StateInterface> dynamixel_hardware::DynamixelHardware::export_state_interfaces()’:
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:157:24: error: ‘info_’ was not declared in this scope
  157 |   for (uint i = 0; i < info_.joints.size(); i++) {
      |                        ^~~~~
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘virtual std::vector<hardware_interface::CommandInterface> dynamixel_hardware::DynamixelHardware::export_command_interfaces()’:
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:173:24: error: ‘info_’ was not declared in this scope
  173 |   for (uint i = 0; i < info_.joints.size(); i++) {
      |                        ^~~~~
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘CallbackReturn dynamixel_hardware::DynamixelHardware::on_activate(const rclcpp_lifecycle::State&)’:
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:183:79: warning: unused parameter ‘previous_state’ [-Wunused-parameter]
  183 | CallbackReturn DynamixelHardware::on_activate(const rclcpp_lifecycle::State & previous_state)
      |                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘CallbackReturn dynamixel_hardware::DynamixelHardware::on_deactivate(const rclcpp_lifecycle::State&)’:
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:200:81: warning: unused parameter ‘previous_state’ [-Wunused-parameter]
  200 | CallbackReturn DynamixelHardware::on_deactivate(const rclcpp_lifecycle::State & previous_state)
      |                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘virtual hardware_interface::return_type dynamixel_hardware::DynamixelHardware::read()’:
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:212:28: error: ‘info_’ was not declared in this scope
  212 |   std::vector<uint8_t> ids(info_.joints.size(), 0);
      |                            ^~~~~
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘virtual hardware_interface::return_type dynamixel_hardware::DynamixelHardware::write()’:
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:265:28: error: ‘info_’ was not declared in this scope
  265 |   std::vector<uint8_t> ids(info_.joints.size(), 0);
      |                            ^~~~~
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp: In member function ‘hardware_interface::return_type dynamixel_hardware::DynamixelHardware::enable_torque(bool)’:
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:310:26: error: ‘info_’ was not declared in this scope
  310 |     for (uint i = 0; i < info_.joints.size(); ++i) {
      |                          ^~~~~
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:319:26: error: ‘info_’ was not declared in this scope
  319 |     for (uint i = 0; i < info_.joints.size(); ++i) {
      |                          ^~~~~
In file included from /opt/ros/foxy/include/class_loader/class_loader_core.hpp:57,
                 from /opt/ros/foxy/include/class_loader/class_loader.hpp:55,
                 from /opt/ros/foxy/include/pluginlib/class_list_macros.hpp:40,
                 from /home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:395:
/opt/ros/foxy/include/class_loader/meta_object.hpp: In instantiation of ‘B* class_loader::impl::MetaObject<C, B>::create() const [with C = dynamixel_hardware::DynamixelHardware; B = hardware_interface::SystemInterface]’:
/opt/ros/foxy/include/class_loader/meta_object.hpp:216:7:   required from here
/opt/ros/foxy/include/class_loader/meta_object.hpp:218:12: error: invalid new-expression of abstract class type ‘dynamixel_hardware::DynamixelHardware’
  218 |     return new C;
      |            ^~~~~
In file included from /home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:7:
/home/tharit/moonbot_ws/src/dynamixel_hardware_interface/include/dynamixel_hardware_interface/dynamixel_hardware_interface.hpp:45:7: note:   because the following virtual functions are pure within ‘dynamixel_hardware::DynamixelHardware’:
   45 | class DynamixelHardware : public hardware_interface::SystemInterface {
      |       ^~~~~~~~~~~~~~~~~
In file included from /home/tharit/moonbot_ws/src/dynamixel_hardware_interface/include/dynamixel_hardware_interface/dynamixel_hardware_interface.hpp:9,
                 from /home/tharit/moonbot_ws/src/dynamixel_hardware_interface/src/dynamixel_hardware_interface.cpp:7:
/opt/ros/foxy/include/hardware_interface/system_interface.hpp:48:23: note: 	‘virtual hardware_interface::return_type hardware_interface::SystemInterface::configure(const hardware_interface::HardwareInfo&)’
   48 |   virtual return_type configure(const HardwareInfo & system_info) = 0;
      |                       ^~~~~~~~~
/opt/ros/foxy/include/hardware_interface/system_interface.hpp:116:23: note: 	‘virtual hardware_interface::return_type hardware_interface::SystemInterface::start()’
  116 |   virtual return_type start() = 0;
      |                       ^~~~~
/opt/ros/foxy/include/hardware_interface/system_interface.hpp:122:23: note: 	‘virtual hardware_interface::return_type hardware_interface::SystemInterface::stop()’
  122 |   virtual return_type stop() = 0;
      |                       ^~~~
/opt/ros/foxy/include/hardware_interface/system_interface.hpp:128:23: note: 	‘virtual std::string hardware_interface::SystemInterface::get_name() const’
  128 |   virtual std::string get_name() const = 0;
      |                       ^~~~~~~~
/opt/ros/foxy/include/hardware_interface/system_interface.hpp:134:18: note: 	‘virtual hardware_interface::status hardware_interface::SystemInterface::get_status() const’
  134 |   virtual status get_status() const = 0;
      |                  ^~~~~~~~~~
make[2]: *** [CMakeFiles/dynamixel_hardware_interface.dir/build.make:63: CMakeFiles/dynamixel_hardware_interface.dir/src/dynamixel_hardware_interface.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/dynamixel_hardware_interface.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed   <<< dynamixel_hardware_interface [1.90s, exited with code 2]

Summary: 12 packages finished [2.63s]
  1 package failed: dynamixel_hardware_interface
  1 package had stderr output: dynamixel_hardware_interface

I’m not sure that should I change info_ to info or not.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.