IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> ROS学习-8 自定义动作编程的大坑 -> 正文阅读

[人工智能]ROS学习-8 自定义动作编程的大坑

想要实现如下功能:(假装实现,主要是为了练习action编程)

客户端发给服务器一个坐标

服务器控制机器人前往坐标

相关信息打印出来(这个比较随便)

action文件

#goal
uint32  x 
#uint32 y
---
#result
uint32 b
---
#feedback
uint32 c

客户端

#include <ros/ros.h>
#include<actionlib/client/simple_action_client.h>
#include"homework/workAction.h"

typedef actionlib::SimpleActionClient<homework::workAction> Client;

void  activeCb()
{
    ROS_INFO("I am Client : server  active just now");
}

void feedbackCb(const homework::workFeedbackConstPtr& fback)
{
    ROS_INFO("I am Client : server has complete %d ",fback->c);
}

void doneCb(const actionlib::SimpleClientGoalState& state, 
        const homework::workResultConstPtr& result)
{
    ROS_INFO("I am Client : it's done");
    ros::shutdown();
}

int main(int argc,char** argv)
{
    ros::init(argc,argv,"jzmoveclient");


//Client 是typedef出来的,Client 是个类型,然后client是个对象,后面跟着() 是构造函数
    Client client("jzmove",true);
    
    ROS_INFO("I am Client : I am waiting for server");
    client.waitForServer();

    ROS_INFO("I am Client : Action server started ,send goal ");
    homework::workGoal goal;
    goal.x=3;
    goal.y = 5;

    client.sendGoal(goal,   &doneCb,&activeCb,&feedbackCb);// &doneCb,&activeCb,&feedbackCb 这三个函数固定这个名字,不要改动


//猜想:activeCb是以服务端进入回调函数为信号的

 //   as->setSucceeded();是doneCb的信号

 
    ros::spin();

    return 0;
}

服务端

#include <ros/ros.h>
#include<actionlib/server/simple_action_server.h>
#include "homework/workAction.h"

typedef actionlib::SimpleActionServer<homework::workAction> Server;

void shuchu(const homework::workGoalConstPtr& goal, Server* as) //const 功能包::文件名GoalConstPtr
{
    ros::Rate r(1);
    ROS_INFO("I am Server : I know the goal  X: %d   Y: %d ",goal->x,goal->y);

    //动作客户端要发布一个目标点,,, 服务器需要让假想的机器人运动到那个点
    //并且动作服务器要定时返回feedback

    homework::workFeedback feedback;

    for(int i =0;i<=10;i++)
    {
        feedback.c = i*10;
      //  ROS_INFO("have move %d  ", i*10);
        as->publishFeedback(feedback);
        r.sleep();
    }

    ROS_INFO("I am Server : (%d   %d ) had arraved",goal->x,goal->y);

    as->setSucceeded();

}


int main(int argc,char** argv)
{
    ros::init(argc , argv,"jzmoveserver");

    ros::NodeHandle n;

    Server server(n,"jzmove",boost::bind(&shuchu, _1 ,&server) ,false);
//   Server  server(n,"do_dish",boost::bind(&execute, _1 , &server ) , false);

    //服务器开始运行
    server.start();

    //循环等待
    ros::spin();

    return 0;
}

大坑:注意这里的客户端的

client.sendGoal(goal, &doneCb,&activeCb,&feedbackCb);

// &doneCb,&activeCb,&feedbackCb 这三个函数固定这个名字,不要改动,顺序也不要动

如果改动会报错(编译错误)

[ 98%] Built target jzmoveserver
In file included from /usr/include/boost/function/detail/maybe_include.hpp:13:0,
                 from /usr/include/boost/function/detail/function_iterate.hpp:14,
                 from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:47,
                 from /usr/include/boost/function.hpp:64,
                 from /opt/ros/melodic/include/ros/forwards.h:40,
                 from /opt/ros/melodic/include/ros/common.h:37,
                 from /opt/ros/melodic/include/ros/ros.h:43,
                 from /home/xrh/ROStest/src/homework/src/jzmoveclient.cpp:1:
/usr/include/boost/function/function_template.hpp: In instantiation of ‘static void boost::detail::function::void_function_invoker0<FunctionPtr, R>::invoke(boost::detail::function::function_buffer&) [with FunctionPtr = void (*)(const boost::shared_ptr<const homework::workFeedback_<std::allocator<void> > >&); R = void]’:
/usr/include/boost/function/function_template.hpp:925:38:   required from ‘void boost::function0<R>::assign_to(Functor) [with Functor = void (*)(const boost::shared_ptr<const homework::workFeedback_<std::allocator<void> > >&); R = void]’
/usr/include/boost/function/function_template.hpp:716:7:   required from ‘boost::function0<R>::function0(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = void (*)(const boost::shared_ptr<const homework::workFeedback_<std::allocator<void> > >&); R = void; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/usr/include/boost/function/function_template.hpp:1061:16:   required from ‘boost::function<R()>::function(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = void (*)(const boost::shared_ptr<const homework::workFeedback_<std::allocator<void> > >&); R = void; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/home/xrh/ROStest/src/homework/src/jzmoveclient.cpp:40:58:   required from here
/usr/include/boost/function/function_template.hpp:118:11: error: too few arguments to function
           BOOST_FUNCTION_RETURN(f(BOOST_FUNCTION_ARGS));
           ^
In file included from /usr/include/boost/function/detail/maybe_include.hpp:18:0,
                 from /usr/include/boost/function/detail/function_iterate.hpp:14,
                 from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:52,
                 from /usr/include/boost/function.hpp:64,
                 from /opt/ros/melodic/include/ros/forwards.h:40,
                 from /opt/ros/melodic/include/ros/common.h:37,
                 from /opt/ros/melodic/include/ros/ros.h:43,
                 from /home/xrh/ROStest/src/homework/src/jzmoveclient.cpp:1:
/usr/include/boost/function/function_template.hpp: In instantiation of ‘static void boost::detail::function::void_function_invoker1<FunctionPtr, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionPtr = void (*)(); R = void; T0 = const boost::shared_ptr<const homework::workFeedback_<std::allocator<void> > >&]’:
/usr/include/boost/function/function_template.hpp:925:38:   required from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = void (*)(); R = void; T0 = const boost::shared_ptr<const homework::workFeedback_<std::allocator<void> > >&]’
/usr/include/boost/function/function_template.hpp:716:7:   required from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = void (*)(); R = void; T0 = const boost::shared_ptr<const homework::workFeedback_<std::allocator<void> > >&; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/usr/include/boost/function/function_template.hpp:1061:16:   required from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type) [with Functor = void (*)(); R = void; T0 = const boost::shared_ptr<const homework::workFeedback_<std::allocator<void> > >&; typename boost::enable_if_c<(! boost::is_integral<Functor>::value), int>::type = int]’
/home/xrh/ROStest/src/homework/src/jzmoveclient.cpp:40:58:   required from here
/usr/include/boost/function/function_template.hpp:118:11: error: too many arguments to function
           BOOST_FUNCTION_RETURN(f(BOOST_FUNCTION_ARGS));
           ^
homework/CMakeFiles/jzmoveclient.dir/build.make:62: recipe for target 'homework/CMakeFiles/jzmoveclient.dir/src/jzmoveclient.cpp.o' failed
make[2]: *** [homework/CMakeFiles/jzmoveclient.dir/src/jzmoveclient.cpp.o] Error 1
CMakeFiles/Makefile2:2277: recipe for target 'homework/CMakeFiles/jzmoveclient.dir/all' failed
make[1]: *** [homework/CMakeFiles/jzmoveclient.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j16 -l16" failed

把三个函数码好了之后就编译成功了

执行一下自己编写的launch文件,虽然很简单,但是成就感满满。

把执行进程的 情况分析一下:

?

  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2022-02-28 15:28:52  更:2022-02-28 15:34:50 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/26 17:25:39-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码