Failed to build - Part 3

Hi,

I have trouble to understand and fix this issue when I build my package. It seems that I have a problem with the action client class that I have coded.

Does anyone can guide me this please ? Below the codes.

Error code when building:

/home/user/ros2_ws/src/wall_following_pkg/src/actionClientRecordOdom.cpp:51:38: error: no match for 'operator=' (operand types are 'rclcpp_action::Client<custom_interfaces::action::OdomRecord>::GoalResponseCallback' {aka 'std::function<void(std::shared_future<std::shared_ptr<rclcpp_action::ClientGoalHandle<custom_interfaces::action::OdomRecord> > >)>'} and 'std::_Bind_helper<false, void (ActionClientOdomRecorder::*)(const std::shared_ptr<rclcpp_action::ClientGoalHandle<custom_interfaces::action::OdomRecord> >&), ActionClientOdomRecorder*, const std::_Placeholder<1>&>::type' {aka 'std::_Bind<void (ActionClientOdomRecorder::*(ActionClientOdomRecorder*, std::_Placeholder<1>))(const std::shared_ptr<rclcpp_action::ClientGoalHandle<custom_interfaces::action::OdomRecord> >&)>'})
   51 |                 std::placeholders::_1);

cpp of the action client class:

#include "actionClientRecordOdom.hpp"

using OdomRecord = custom_interfaces::action::OdomRecord;
using GoalHandleOdom = rclcpp_action::ClientGoalHandle<OdomRecord>;

ActionClientOdomRecorder::ActionClientOdomRecorder(
    const rclcpp::NodeOptions &node_options)
    : Node("action_client_record_odom_node", node_options), goal_done_(false),
      send_goal_activate_(false) {
  this->client_ptr_ = rclcpp_action::create_client<OdomRecord>(
      this->get_node_base_interface(), this->get_node_graph_interface(),
      this->get_node_logging_interface(), this->get_node_waitables_interface(),
      "odom_record");

  this->timer_ = this->create_wall_timer(
      std::chrono::milliseconds(100),
      std::bind(&ActionClientOdomRecorder::send_goal, this));
}

void ActionClientOdomRecorder::activate_send_goal() {
  send_goal_activate_ = true;
}

void ActionClientOdomRecorder::send_goal() {
  using namespace std::placeholders;

  this->goal_done_ = false;
  if (!send_goal_activate_) {
    return;
  }

  if (!this->client_ptr_) {
    RCLCPP_ERROR(this->get_logger(), "Action client not initialized");
  }

  if (!this->client_ptr_->wait_for_action_server(std::chrono::seconds(10))) {
    RCLCPP_ERROR(this->get_logger(),
                 "Action server not available after waiting");
    this->goal_done_ = true;
    return;
  }

  auto goal_msg = OdomRecord::Goal();

  RCLCPP_INFO(this->get_logger(), "Sending goal");

  auto send_goal_options = rclcpp_action::Client<OdomRecord>::SendGoalOptions();

  send_goal_options.goal_response_callback =
      std::bind(&ActionClientOdomRecorder::goal_response_callback, this,
                std::placeholders::_1);

  send_goal_options.feedback_callback =
      std::bind(&ActionClientOdomRecorder::feedback_callback, this,
                std::placeholders::_1, std::placeholders::_2);

  send_goal_options.result_callback = std::bind(
      &ActionClientOdomRecorder::result_callback, this, std::placeholders::_1);

  auto goal_handle_future =
      this->client_ptr_->async_send_goal(goal_msg, send_goal_options);
}

void ActionClientOdomRecorder::goal_response_callback(
    const GoalHandleOdom::SharedPtr &goal_handle) {
  if (!goal_handle) {
    RCLCPP_ERROR(this->get_logger(), "Goal was rejected by server");
  } else {
    RCLCPP_INFO(this->get_logger(),
                "Goal accepted by server, waiting for result");
  }
}

void ActionClientOdomRecorder::feedback_callback(
    GoalHandleOdom::SharedPtr,
    const std::shared_ptr<const OdomRecord::Feedback> feedback) {
  RCLCPP_INFO(this->get_logger(), "Feedback received: %d",
              feedback->current_total);
}

void ActionClientOdomRecorder::result_callback(
    const GoalHandleOdom::WrappedResult &result) {
  this->goal_done_ = true;
  switch (result.code) {
  case rclcpp_action::ResultCode::SUCCEEDED:
    break;
  case rclcpp_action::ResultCode::ABORTED:
    RCLCPP_ERROR(this->get_logger(), "Goal was aborted");
    return;
  case rclcpp_action::ResultCode::CANCELED:
    RCLCPP_ERROR(this->get_logger(), "Goal was canceled");
    return;
  default:
    RCLCPP_ERROR(this->get_logger(), "Unknown result code");
    return;
  }

  RCLCPP_INFO(this->get_logger(), "Result received odom size: %d",
              result.result->list_of_odoms.size());
}

its hpp:


#include <inttypes.h>
#include <iostream>
#include <memory>
#include <string>

#include "custom_interfaces/action/odom_record.hpp"
#include "geometry_msgs/msg/detail/point32__struct.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_action/rclcpp_action.hpp"

using OdomRecord = custom_interfaces::action::OdomRecord;
using GoalHandleOdom = rclcpp_action::ClientGoalHandle<OdomRecord>;

class ActionClientOdomRecorder : public rclcpp::Node {
public:
  ActionClientOdomRecorder(
      const rclcpp::NodeOptions &options = rclcpp::NodeOptions());
  void send_goal();
  bool is_goal_done() const { return this->goal_done_; };
  void activate_send_goal();

private:
  rclcpp_action::Client<OdomRecord>::SharedPtr client_ptr_;
  rclcpp::TimerBase::SharedPtr timer_;
  bool goal_done_;
  bool send_goal_activate_;
  void goal_response_callback(const GoalHandleOdom::SharedPtr &goal_handle);
  void
  feedback_callback(GoalHandleOdom::SharedPtr,
                    const std::shared_ptr<const OdomRecord::Feedback> feedback);

  void result_callback(const GoalHandleOdom::WrappedResult &result);
};

My CMake:

cmake_minimum_required(VERSION 3.5)
project(wall_following_pkg)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(custom_interfaces REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(geometry_msgs REQUIRED)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  #set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  #set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()

include_directories(include)

add_executable(main_node src/ExploreWorld.cpp src/MoveRobot.cpp src/ScanSubscriber.cpp src/ServiceFindWall.cpp src/ServiceFindWallClient.cpp src/actionClientRecordOdom.cpp)
ament_target_dependencies(main_node custom_interfaces rclcpp std_msgs sensor_msgs rclcpp_action geometry_msgs)
 
add_executable(action_server_record_odom_node src/actionServerRecordOdom.cpp)
ament_target_dependencies(action_server_record_odom_node rclcpp rclcpp_action custom_interfaces geometry_msgs nav_msgs)
 
install(TARGETS
	main_node
	action_server_record_odom_node
   DESTINATION lib/${PROJECT_NAME}
 )

# Install launch files.
install(DIRECTORY
  launch
  DESTINATION share/${PROJECT_NAME}/
)

and my package.xml:

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>wall_following_pkg</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="adrien_luthy@hotmail.com">user</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>rclcpp</depend>
  <depend>std_msgs</depend>
  <depend>nav_msgs</depend>
  <depend>sensor_msgs</depend>
  <depend>std_srvs</depend>
  <depend>custom_interfaces</depend>
  <depend>rclcpp_action</depend>
  <depend>geometry_msgs</depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

Hi @adluthi ,

You are getting this error because there was a major syntax change after ROS2 Foxy / Galactic for C++ Action Client Goal Response Callback function.

You are probably trying to run a ROS2 Foxy / Galactic version action client code on a ROS2 Humble / Iron (and later) version configuration.

Refer below to see the differences in the goal_response_callback() function definition.

I hope this solves your issue.



ROS2 Foxy and Galactic:
---------------------------------------
ROS2 Foxy: ROS2 Foxy Action Client in C++

void goal_response_callback(std::shared_future<GoalHandleMsg::SharedPtr> future)
{
  auto goal_handle = future.get();
  if (!goal_handle) {
    RCLCPP_ERROR(
      this->get_logger(), "Goal was rejected by server");
  } else {
    RCLCPP_INFO(
      this->get_logger(), "Goal accepted by server, waiting for result");
  }
}

ROS2 Galactic: ROS2 Galactic Action Client in C++

void goal_response_callback(std::shared_future<GoalHandleMsg::SharedPtr> future)
{
  auto goal_handle = future.get();
  if (!goal_handle) {
    RCLCPP_ERROR(
      this->get_logger(), "Goal was rejected by server");
  } else {
    RCLCPP_INFO(
      this->get_logger(), "Goal accepted by server, waiting for result");
  }
}


ROS2 Humble and Iron (and above):
-----------------------------------------------------
ROS2 Humble: ROS2 Humble Action Client in C++

void goal_response_callback(const GoalHandleMsg::SharedPtr & goal_handle)
{
  if (!goal_handle) {
    RCLCPP_ERROR(
      this->get_logger(), "Goal was rejected by server");
  } else {
    RCLCPP_INFO(
      this->get_logger(), "Goal accepted by server, waiting for result");
  }
}

ROS2 Iron: ROS2 Iron Action Client in C++

void goal_response_callback(const GoalHandleMsg::SharedPtr & goal_handle)
{
  if (!goal_handle) {
    RCLCPP_ERROR(
      this->get_logger(), "Goal was rejected by server");
  } else {
    RCLCPP_INFO(
      this->get_logger(), "Goal accepted by server, waiting for result");
  }
}


NOTE: The code-snippets posted above are slightly modified versions of the same code-snippets taken from above-referenced source(s).

Regards,
Girish

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