【问题标题】:ROS-actions issue in boost::bindboost::bind 中的 ROS 操作问题
【发布时间】:2022-07-21 17:27:39
【问题描述】:

这里是 ROS 新手。我正在编写一个简单的服务器-客户端 ROS 代码来使用操作计算数字的阶乘。教程总是显示斐波那契示例,但我想编写一个简单的代码而不使用任何类(出于学习目的)。为此,我正在关注教程:http://wiki.ros.org/actionlib

action_server.cpp 文件:

#include<iostream>
#include<ros/ros.h>
#include<std_msgs/String.h>
#include<actionlib/server/simple_action_server.h>
#include"actions_basics/NumAction.h"

void callbackfunction(actions_basics::NumActionGoalConstPtr& goal, actionlib::SimpleActionServer<actions_basics::NumAction>* action_server){
    ros::Rate r(2);
    bool success = true;

    actions_basics::NumActionFeedback feedback;
    actions_basics::NumActionResult result;

    ROS_INFO_STREAM("Executing operation on server");
    int temp = 1;
    for (auto i = 2; i < goal->goal.num; i++) {
        temp = temp*i;
        feedback.feedback.current_num = temp;
        action_server->publishFeedback(feedback.feedback);
        r.sleep();
    }
    if (success) {
        result.result.factorial_num = feedback.feedback.current_num;
        ROS_INFO_STREAM("Succeeded");
        action_server->setSucceeded(result.result);
    }

}

int main(int argc, char** argv){
    ros::init(argc, argv, "action_server");
    ros::NodeHandle nodehandle;
    actionlib::SimpleActionServer<actions_basics::NumAction> action_server(nodehandle, "num_server", boost::bind(&callbackfunction, boost::placeholders::_1, &action_server), false);
    action_server.start();
    ros::spin();

    return 0;
}

Num.action 文件:

#goal definition
int32 num
---
#result definition
int32 factorial_num
---
#feedback definition
int32 current_num

但是我收到一个错误invalid initialization of reference of type ‘boost::shared_ptr&lt;const actions_basics::NumActionGoal_&lt;std::allocator&lt;void&gt; &gt; &gt;&amp;’ from expression of type ‘const boost::shared_ptr&lt;const actions_basics::NumGoal_&lt;std::allocator&lt;void&gt; &gt; &gt;’

我在 CMakeLists.txt 中添加了 Boost 所需的 find_package、include_directories 等。 请帮忙!

【问题讨论】:

    标签: c++ action ros


    【解决方案1】:

    您应该使用actions_basics::NumGoalConstPtr&amp; goal 而不是actions_basics::NumActionGoalConstPtr&amp; goal 作为回调函数中的操作数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-16
      • 2012-05-26
      • 2012-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多