当前位置:网站首页>ROS learning-8 pit for custom action programming
ROS learning-8 pit for custom action programming
2022-06-13 02:08:00 【Jerry-hao】
You want to achieve the following functions :( Pretend to realize , It's mainly for practice action Programming )
The client sends a coordinate to the server
The server controls the robot to go to the coordinates
Print out relevant information ( This is casual )
action file
#goal
uint32 x
#uint32 y
---
#result
uint32 b
---
#feedback
uint32 cclient
#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 yes typedef Coming out ,Client It's a type , then client It's an object , Follow behind () It's a constructor
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 These three functions fix the name , Don't change it
// guess :activeCb It is signaled by the server entering the callback function
// as->setSucceeded(); yes doneCb The signal of
ros::spin();
return 0;
}Server side
#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 Function pack :: file name GoalConstPtr
{
ros::Rate r(1);
ROS_INFO("I am Server : I know the goal X: %d Y: %d ",goal->x,goal->y);
// The action client needs to publish a target point ,,, The server needs to make the imaginary robot move to that point
// And the action server should return regularly 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);
// The server is running
server.start();
// Loop waiting for
ros::spin();
return 0;
}hole : Note the client side
client.sendGoal(goal, &doneCb,&activeCb,&feedbackCb);
// &doneCb,&activeCb,&feedbackCb These three functions fix the name , Don't change it , Don't move the sequence
If the change is made, an error will be reported ( Compile error )
[ 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
After the three functions are coded, the compilation is successful
Execute your own launch file , Although it's very simple , But the sense of achievement is full .

Put the execution process Analyze the situation :

边栏推荐
- Use mediapipe+opencv to make a simple virtual keyboard
- Magics 23.0 how to activate and use the slice preview function of the view tool page
- JS get element
- Using atexit to realize automatic destruct of singleton mode
- cin,cin. get(),cin. Summary of the use of getline() and getline()
- I didn't expect that the index occupies several times as much space as the data MySQL queries the space occupied by each table in the database, and the space occupied by data and indexes. It is used i
- C language volatile learning
- Number of special palindromes in basic exercise of test questions
- Delphi 10.4.2 release instructions and installation methods of three patches
- Restrict cell input type and display format in CXGRID control
猜你喜欢
![[open source] libinimini: a minimalist ini parsing library for single chip computers](/img/99/f2ded6c189bd45ea6c1e9f86fd64c1.jpg)
[open source] libinimini: a minimalist ini parsing library for single chip computers

Gome's ambition of "folding up" app

【Unity】打包WebGL項目遇到的問題及解决記錄

C language conditional compilation routine

Stm32+ze-08 formaldehyde sensor tutorial

Share three stories about CMDB

Sensorless / inductive manufacturing of brushless motor drive board based on stm32

The new wild prospect of JD instant retailing from the perspective of "hour shopping"

Get started quickly cmake

Record: how to solve the problem of "the system cannot find the specified path" in the picture message uploaded by transferto() of multipartfile class [valid through personal test]
随机推荐
Can't use typedef yet? C language typedef detailed usage summary, a solution to your confusion. (learning note 2 -- typedef setting alias)
How to solve the problem of obtaining the time through new date() and writing out the difference of 8 hours between the database and the current time [valid through personal test]
DFS and BFS to solve Treasure Island exploration
记录:如何解决MultipartFile类的transferTo()上传图片报“系统找不到指定的路径“问题【亲测有效】
Stm32+ze-08 formaldehyde sensor tutorial
Functional translation
The method of drawing rounded panel with Delphi
Alertwindowmanager pop up prompt window help (Part 1)
JS get element
10 days based on stm32f401ret6 smart lock project practice day 1 (environment construction and new construction)
【 unity】 Problems Encountered in Packaging webgl Project and their resolution Records
Ten thousand words make it clear that synchronized and reentrantlock implement locks in concurrency
js获取元素
Devexpress implementation flow chart
C language complex type description
16 embedded C language interview questions (Classic)
Record: how to solve the problem of "the system cannot find the specified path" in the picture message uploaded by transferto() of multipartfile class [valid through personal test]
Mac下搭建MySQL环境
Compiling minicom-2.7.1 under msys2
Calculation of accuracy, recall rate, F1 value and accuracy rate of pytorch prediction results (simple implementation)