(C++停留在07年的水平,见谅)
以下写的第一个程序:
#include "rclcpp/rclcpp.hpp"
int main(int argc, char *argv[]) {
rclcpp::init(argc, argv);
auto node = rclcpp::Node::make_shared("test1");
RCLCPP_INFO(node->get_logger(), node->get_name());
rclcpp::shutdown();
}
注释:
rclcpp.hpp :rclcpp的头文件都在这里include,只要include这一个文件即可。
#include "rclcpp/executors.hpp"
#include "rclcpp/logging.hpp"
#include "rclcpp/node.hpp"
#include "rclcpp/parameter.hpp"
#include "rclcpp/parameter_client.hpp"
#include "rclcpp/parameter_service.hpp"
#include "rclcpp/rate.hpp"
#include "rclcpp/time.hpp"
#include "rclcpp/utilities.hpp"
#include "rclcpp/visibility_control.hpp"
rclcpp::init(argc, argv);在include/rclcpp/utilities.hpp声明,在src/rclcpp/utilities.cpp(163)实现,
主要是调用rcl_init, 然后初始化系统信号。
src/rclcpp/utilities.cpp文件定义了rclcpp的常用函数,比如ok, sleep_for等。
auto node = rclcpp::Node::make_shared("test1");
创建一个rclcpp的node实例,应该是同ROS1的节点。
RCLCPP_INFO(node->get_logger(), node->get_name());
输出node的名字。 RCLCPP_INFO的定义还在查找。
rclcpp::shutdown();在include/rclcpp/utilities.hpp声明,在src/rclcpp/utilities.cpp实现。
析构rclcpp。