服务接口实现:【ROS2】ROS2使用C++实现简单服务端-CSDN博客
服务端实现:【ROS2】实现自定义服务接口-CSDN博客
代码如下:
#include <cstdio>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "base_interfaces_demo/msg/student.hpp"
#include "base_interfaces_demo/srv/add_ints.hpp"
using namespace std::chrono_literals;
using base_interfaces_demo::msg::Student;
using base_interfaces_demo::srv::AddInts;
class AddIntClient:public rclcpp::Node
{
public:
AddIntClient():rclcpp::Node("addIntClient_node_cpp"){
RCLCPP_INFO(this->get_logger(),"客户端节点已创建!");
// 创建客户端
client_=this->create