想要实现如下功能:(假装实现,主要是为了练习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);//动作客户端要发布一个目标点,,, 服务器需要让假想的机器人运动到那个点//并且动作服务器要定时返回feedbackhomework::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 functionBOOST_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 functionBOOST_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文件,虽然很简单,但是成就感满满。

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

ROS学习-8 自定义动作编程的大坑相关推荐

  1. ROS学习之自定义srv类型

    1. 创建srv文件 cd ~/catkin_ws/src/my_package mkdir srv echo "int64 a int64 b --- int64 sum" &g ...

  2. 机器人操作系统ROS(6)动作编程

    注:在 catkin\_ws 工作空间下的功能包earning\_communication 下继续实现通信编程,参考上节-服务编程 一.动作通讯模型 二.动作编程实现 1. 自定义动作文件actio ...

  3. ROS学习笔记publisher的编程实现c++详解

    前言 基于B站ROS公开课:[古月居]古月·ROS入门21讲 基于Ubuntu 20.04.1.Noetic版本 提示:以下是本篇文章正文内容,下面案例可供参考 一.ros publisher C++ ...

  4. ROS学习-3 (C++编程实现创建发布者+发布数据控制海龟运动)

    古月居21讲第10个视频 此处是创建的发布者, 下图中的topic 和/turtle1/cmd_vel 是ROS 自带的 发布者要往这个话题中发布数据. #include <ros/ros.h& ...

  5. ROS学习之Arduino篇——读取并发布各种传感器数据

    本篇主要包括以下五部分内容: 1. 说明 2. 在rosserial_arduino中自定义数据类型 3. 使用Arduino读取传感器的数据 4. 更改代码 5. 测试 本篇将读取超声波雷达.电位计 ...

  6. 周末ROS学习沙龙第四期——动作编程、dynamic_reconfigure动态参数更新、控制机器人移动、传感器数据处理

    非博主原创,出于方便学习的目的,将周末ROS学习沙龙www.corvin.cn的课堂讲义PPT整理在这(老师讲得超棒!),无任何盈利目的,若有侵权则删除. Ros小课堂链接:https://space ...

  7. ROS入门笔记(十二):动作编程 (C++)

    ROS入门笔记(十二):动作编程 (C++) 文章目录 01 导读 02 功能包的创建 03 在功能包中创建action(动作) 3.1 自定义action 3.2 在package.xml中添加功能 ...

  8. 机器人操作系统ROS动作编程

    目录 一.什么是动作通讯模型 二.创建工作区间 1.创建功能包 2.编译功能包 三.动作编程 1.定义action文件 2.创建.cpp文件 3.编译及运行 四.分布式通讯 1.主机 2.从机 3.运 ...

  9. ROS 学习笔记(三):自定义服务数据srv+server+client 示例运行

    ROS 学习笔记(三):自定义服务数据srv+Server+Client 示例运行 一.自定义服务数据: 1.向功能包添加自定义服务文件(AddTwoInts.srv) cd ~/catkin_ws/ ...

最新文章

  1. 智能车竞赛技术报告 | 智能车视觉 - 新余学院 - 开放艺术队
  2. MySQL用source命令导入不记入binlog中【原创】
  3. pop客户机程序流程图_基于.NET的在线考试系统的设计与实现
  4. linux centos7开放端口命令,Centos7开放端口教程
  5. 数字化赋能智能生产,一套数据决策分析体系,完美解决生产管理
  6. python Unable to find vcvarsall.bat 错误
  7. VMware内虚拟机自适应及最大化窗口调整方式
  8. 全局路径规划:图搜索算法介绍2(A star)
  9. [jQuery原理] jQuery事件操作相关方法
  10. Shell十三问总结
  11. 中止执行后超过2年_债权人申请强制执行满2年后怎么办?
  12. python计算机视觉库_荐 python计算机视觉入门
  13. 最新版的Python写春联,支持行书隶书楷书,不再有缺失汉字
  14. html css 实现文字竖排模拟古籍排版
  15. supervisor控制台运行出错,BACKOFF Exited too quickly
  16. Vulnhub-theEther
  17. CSS实现文字动画效果【每日一题】
  18. 工业互联网新发展:基于 HTML5 WebGL 的高炉炼铁厂可视化系统
  19. 讲述下我在EBC金融外汇平台交易的真实体验
  20. 解决Python安装pyqt5-tool出现的系列问题:ERROR: Could not find a version that satisfies the requirement xxx

热门文章

  1. 为什么香港计算机科学家多,[转载]为什么香港中文大学汤晓鸥教授团队的人脸识别技术能够击败人类?...
  2. 【云服务架构】阿里云ECS+RDS+OSS+SLB全域旅游营销推广解决方案
  3. 机器学习笔记--聚类算法 k-means--31省市消费水平聚类
  4. Apache的在线升级
  5. 淘宝技术架构演进之路--精华版
  6. npm离线安装npm包的两种方法
  7. UML关系-继承和泛化的区别
  8. 移动App设计的那些创新点
  9. 社会保障卡与应届生/工作人员/失业人员的爱恨情仇
  10. JAVA网络编程【转】出处不详