当前位置:网站首页>Programming implementation of ROS learning 5-client node
Programming implementation of ROS learning 5-client node
2022-07-05 08:45:00 【m0_ forty-six million ninety-three thousand eight hundred and t】
One 、 Concept
service Service It is a way of synchronous communication between nodes ; Allow clients Client Node issue request Request; By the server Server Feedback response after node processing Response.

Two 、 establish Client Process overview of
1、 establish Client Program
2、 compile
3、 Configure environment variables
4、 perform Client Program
3、 ... and 、 The specific process is as follows :
3.1 establish client.cpp file
Create in the function pack of the corresponding workspace client.cpp file , The file should include the following four parts
1. initialization ROS node
2. Create a Client example
3. Publish service request data
4. wait for Server Response result after processing
example : Create a turtle_spawn.cpp
/** * The routine will request /spawn service , Service data type turtlesim::Spawn */ #include <ros/ros.h> #include <turtlesim/Spawn.h> int main(int argc, char** argv) { // initialization ROS node ros::init(argc, argv, "turtle_spawn"); // Create node handle ros::NodeHandle node; // Find out /spawn After service , Create a service client , The connection name is /spawn Of service ros::service::waitForService("/spawn");// This is a blocking function , It means waiting for the server to start ros::ServiceClient add_turtle = node.serviceClient<turtlesim::Spawn>("/spawn");// The data type of the requested service is turtlesim::Spawn // initialization turtlesim::Spawn Request data for turtlesim::Spawn srv; srv.request.x = 2.0; srv.request.y = 2.0; srv.request.name = "turtle2"; // Request service call , That is, publish the request data ROS_INFO("Call service to spwan turtle[x:%0.6f, y:%0.6f, name:%s]", srv.request.x, srv.request.y, srv.request.name.c_str()); add_turtle.call(srv); // Display the service call result ROS_INFO("Spwan turtle successfully [name:%s]", srv.response.name.c_str()); return 0; };
3.2 compile
1. First in CMakeLists.txt Add Compilation Rules to
add_executable(turtle_spawn src/turtle_spawn.cpp)
target_link_libraries(turtle_spawn ${catkin_LIBRARIES})
The reasons for adding these two Compilation Rules and their adding locations are as follows :

2. Return to the workspace home directory , At terminal catkin_make
3.3 Set the environment variable
Also in the workspace main directory , Input... At the terminal :source devel/setup.bash
3.4 perform client Program
Because the service makes the little turtle move , So start the little turtle first
roscore
rosrun turtlesim turtlesim_nodeThen directly execute your client File can , The instructions are as follows :
rosrun Function package name .cpp file name
rosrun learning_service turtle_spawn边栏推荐
- 猜谜语啦(142)
- MATLAB skills (28) Fuzzy Comprehensive Evaluation
- Business modeling of software model | overview
- Apaas platform of TOP10 abroad
- Matlab tips (28) fuzzy comprehensive evaluation
- 整形的分类:short in long longlong
- Halcon affine transformations to regions
- Esp8266 interrupt configuration
- Guess riddles (8)
- It cold knowledge (updating ing~)
猜你喜欢

Arduino+a4988 control stepper motor

Halcon affine transformations to regions

How to manage the performance of R & D team?

Example 007: copy data from one list to another list.

MATLAB小技巧(28)模糊綜合評價
![[noi simulation] juice tree (tree DP)](/img/19/bc71e8dc3958e4cb87b31423a74617.png)
[noi simulation] juice tree (tree DP)

It cold knowledge (updating ing~)

猜谜语啦(11)

Guess riddles (5)

Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)
随机推荐
Task failed task_ 1641530057069_ 0002_ m_ 000000
Pytorch entry record
How apaas is applied in different organizational structures
Guess riddles (8)
Matlab tips (28) fuzzy comprehensive evaluation
Halcon affine transformations to regions
location search 属性获取登录用户名
整形的分类:short in long longlong
Apaas platform of TOP10 abroad
RT-Thread内核快速入门,内核实现与应用开发学习随笔记
U8g2 drawing
leetcode - 445. Add two numbers II
Digital analog 2: integer programming
C language data type replacement
Business modeling | process of software model
[matlab] matlab reads and writes Excel
ORACLE进阶(三)数据字典详解
Speech recognition learning summary
ABC#237 C
暑假第一周