ROS2 使用自定义消息
创建自定义消息
示例代码
service
#include <inttypes.h>
#include <memory>
#include "rclcpp/rclcpp.hpp"
#include "wxx_msgs/srv/test.hpp"
#define TestService wxx_msgs::srv::Test
rclcpp::Node::SharedPtr g_node = nullptr;
void handle_service(
const std::shared_ptr<rmw_request_id_t> request_header,
const std::shared_ptr<TestService::Request> request,
const std::shared_ptr<TestService::Response> response)
{
(void)request_header;
response->result_data = request->get_data + 10;
RCLCPP_INFO(g_node->get_logger(), "I get data: %d, I response data: %d", request->get_data, response->result_data)
}
int main(int argc, char ** a