创建example_action_rclcpp功能包,添加robot_control_interfaces、rclcpp_action、rclcpp三个依赖,自动创建action_robot_01节点,并手动创建action_control_01.cpp节点。 cd chapt4_ws/ ros2 pkg create example_action_rclcpp --build-type ament_cmake --dependencies rclcpp rclcpp_action robot_control_interfaces --...
RCLCPP_INFO(this->get_logger(),"读者节点%s已启动",name.c_str()); RCLCPP_INFO(this->get_logger(),"卖书服务端%s已启动",name.c_str()); //(3)创建订阅者 sub_readers = this->create_subscription<std_msgs::msg::String> ("no_time",10,std::bind(&ReadersAndSellServer::readnovels_call...
RCLCPP_INFO(this->get_logger(), "反馈剩余距离:%f", feedback->distance_remaining); }; // 设置执行结果回调函数 send_goal_options.result_callback = [this](const NavigationActionGoalHandle::WrappedResult& result) { if (result.code == rclcpp_action::ResultCode::SUCCEEDED) { RCLCPP_INFO(this-...
首先是初始化rclcpp客户端库,并实例化FrameListener节点对象,然后一直旋转(“spin”)该节点以调用其回调函数;最后关闭rclcpp客户端库。 int main(int argc, char * argv[]) { rclcpp::init(argc, argv); rclcpp::spin(std::make_shared<FrameListener>()); rclcpp::shutdown(); return 0; } 13.2 构建软件...
timer_callback函数是设置消息数据和实际发布消息的地方。RCLCPP_INFO宏确保将每个发布的消息打印到控制台: private: void timer_callback() { auto message = std_msgs::msg::String(); message.data= "Hello, world! " + std::to_string(count_++);RCLCPP_INFO(this->get_logger(),"Publishing: '%s'"...
ros2 run rclcpp_components component_container // 启动组件容器 因为组件没有 main 函数,不能单独运行,因此需要启动一个空的进程用来作为组件执行的容器。利用这个指令来启动 ros2 提供给我们的默认的容器。ros2 component load [包名] [组件名] // 该指令将组件挂在至默认的组件容器,注,执行此指令需新开一...
RCLCPP_INFO(this->get_logger(), "[this->now()] sec:%lf nano:%ld", t3.seconds(), t3.nanoseconds()); 当use_sim_time为false时,运行上面测试代码的结果为: 代码语言:shell AI代码解释 [time_api_test-1][INFO1658498046.378262276][time_api_test]:[rclcpp::Clock().now()]sec:1658498046.378260...
RCLCPP_INFO(get_logger(), "on_configure() is called."); return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS; } rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_activate(const rclcpp_lifecycle::State &) ...
RCLCPP_INFO(rclcpp::get_logger("server"), "Got request to cancel goal"); (void)goal_handle; return rclcpp_action::CancelResponse::ACCEPT; } void execute( const std::shared_ptrgoal_handle) { RCLCPP_INFO(rclcpp::get_logger("server"), "Executing goal"); ...
在ROS2中,可以使用`RCLCPP_INFO`、`RCLCPP_WARN`等宏来输出日志信息。日志信息可以在运行时通过命令行工具`ros2 topic echo`来查看。 六、时间 时间是ROS2中用于同步节点操作的一种机制。ROS2提供了一套时间API,用于获取当前时间、计算时间差、设置时间等操作。节点可以使用时间API来实现精确的时间控制。 在ROS2...