当前位置:网站首页>9、 Alternative implementation of client for service communication
9、 Alternative implementation of client for service communication
2022-07-26 17:54:00 【Rock magnon】
List of articles
1、 Background
In service communication , Sometimes we need to create a new client , At this time, we can get service topics through relevant commands , data type , Thus, a new client sends a request to the server .
2、 Implementation steps
1. Create Feature Pack , Add dependency :roscpp rospy std_msgs turtlesim
2. Get service topics and information
rosservice list
/clear
/key/get_loggers
/key/set_logger_level
/kill
/reset
/rosout/get_loggers
/rosout/set_logger_level
/spawn
/turtle/get_loggers
/turtle/set_logger_level
/turtle1/set_pen
/turtle1/teleport_absolute
/turtle1/teleport_relative
[email protected]:/media/d102/EPAN/Desktop/code_study_ubuntu/rosdemo_05$ rosservice type /spawn
turtlesim/Spawn
[email protected]:/media/d102/EPAN/Desktop/code_study_ubuntu/rosdemo_05$ rossrv info turtlesim/Spawn
float32 x
float32 y
float32 theta
string name
---
string name
3. Code implementation
- C++
/* The goal is : Make a little turtle service :/spawn Message type :turtlesim/Spawn Get ready : start-up turtlesim_node node */ #include"ros/ros.h" #include"turtlesim/Spawn.h" int main(int argc, char *argv[]){ setlocale(LC_ALL,""); ros::init(argc,argv,"turtle_add"); ros::NodeHandle nh; //spawn For service topics ros::ServiceClient client = nh.serviceClient<turtlesim::Spawn>("/spawn"); ros::service::waitForService("/spawn"); // establish spawn object turtlesim::Spawn spawn; spawn.request.x = 1.0; spawn.request.y = 1.1; spawn.request.theta = 2.2; // When the tortoise name is repeated, it will report an error spawn.request.name = "turtle_add1"; bool flag = client.call(spawn); if (flag){ ROS_INFO(" Tortoise name :%s",spawn.response.name.c_str()); } else{ ROS_INFO(" Failure !!!"); } return 0; } - Python
#! /usr/bin/env python from tkinter import EXCEPTION from rosdep2 import RosdepLookup import rospy from turtlesim.srv import Spawn,SpawnRequest,SpawnResponse if __name__ == "__main__": rospy.init_node("turtle_add_p") client = rospy.ServiceProxy("/spawn",Spawn) client.wait_for_service() req = SpawnRequest() req.x = 1.0 req.y = 4.3 req.theta = 3.4 req.name = "turtle_p" try: response = client.call(req)# Return tortoise name rospy.loginfo(" Tortoise name :%s",response.name) except EXCEPTION as e: rospy.loginfo(" Failure !!!!!")
边栏推荐
- SQL中去去重的三种方式
- URL jump vulnerability
- Coscon'22 city / school / institution producer solicitation order
- Several ways to resolve hash conflicts
- 图的遍历的定义以及深度优先搜索和广度优先搜索(一)
- Is it really safe and reliable to exempt five in case of opening an account in a stock company
- Mondriaans‘s Dream(状态压缩DP)
- 重磅!《2022中国开源发展蓝皮书》正式发布
- [day3] reconstruction of roads
- 如何通过学会提问,成为更加优秀的数据科学家
猜你喜欢

Asemi rectifier bridge kbpc2510, kbpc2510 parameters, kbpc2510 specifications

CCS tm4c123 new project

We were tossed all night by a Kong performance bug

(25) top level menu of blender source code analysis blender menu

Gan (generative adversarial network, GaN) generative countermeasure network

来吧开发者!不只为了 20 万奖金,试试用最好的“积木”来一场头脑风暴吧!...

Definition of graph traversal and depth first search and breadth first search (I)

重磅公布!ICML2022奖项:15篇杰出论文,复旦、厦大、上交大研究入选

ACL experiment demonstration (Huawei router device configuration)

敏捷开发与DevOps的对比
随机推荐
[Day2] cinema ticket
[300 opencv routines] 240. Shi Tomas corner detection in opencv
Is it really safe and reliable to exempt five in case of opening an account in a stock company
Redisdesktopmanager removes the upgrade prompt
uni-app
一文详解吞吐量、QPS、TPS、并发数等高并发指标
兆骑科创海外高层次人才引进平台,创业赛事活动路演
得不偿失!博士骗领210万元、硕士骗领3万元人才补贴,全被判刑了!
[cloud native] IVX low code development was introduced into Tencent map and previewed online
AI遮天传 DL-多层感知机
Analysis of interface testing
即刻报名|飞桨黑客马拉松第三期盛夏登场,等你挑战
股票公司开户万一免五这是真的安全靠谱的吗
【集训Day1】 Dwarves line up
Spark统一内存划分
数据库使用psql及jdbc进行远程连接,不定时自动断开的解决办法
跨站点请求伪造(CSRF)
天翼云Web应用防火墙(边缘云版)支持检测和拦截Apache Spark shell命令注入漏洞
Coscon'22 city / school / institution producer solicitation order
[training day3] section