using namespace std::literals::chrono_literals; timer_ = this->create_wall_timer( 500ms, std::bind(&ParametersBasicNode::timer_callback, this)); } private: int log_level; rclcpp::TimerBase::SharedPtr timer_; void timer_callback() { this->get_parameter("rcl_log_level", log_level);...
// 成员变量:发布者和定时器的智能指针rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;rclcpp::TimerBase::SharedPtr timer_;}; // 使用宏注册组件,使其可被动态加载#include"rclcpp_components/register_node_...
定时器是ROS2中的另外一个常用功能,通过定时器可以实现按照一定周期调用某个函数以实现定时发布等逻辑。 定时器对应的类是rclcpp::TimerBase,调用create_wall_timer将返回其共享指针。 创建定时器时传入了两个参数,这两个参数都利用了C++11的新特性。 std::chrono::milliseconds(500),代表500ms,chrono是c++ 11中的...
using namespace std::literals::chrono_literals; timer_ = this->create_wall_timer( 500ms, std::bind(&ParametersBasicNode::timer_callback, this)); } private: int log_level; rclcpp::TimerBase::SharedPtr timer_; void timer_callback() { this->get_parameter("rcl_log_level", log_level);...
c_str()); publisher_->publish(message); } rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_; rclcpp::TimerBase::SharedPtr timer_; size_t count_ = 0; }; int main(int argc, char * argv[]) { rclcpp::init(argc, argv); rclcpp::spin(std::make_shared<...
"; publisher_->publish(*message); // 发布消息 } // 成员变量:发布者和定时器的智能指针 rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_; rclcpp::TimerBase::SharedPtr timer_; }; // 使用宏注册组件,使其可被动态加载 #include "rclcpp_components/register_node_macro.hpp" RCLCPP...
rclcpp::TimerBase::SharedPtr timer_; /*定时器,用于定时发布机器人位置*/ rclcpp::Service<example_ros2_interfaces::srv::MoveRobot>::SharedPtr move_robot_server_; /*移动机器人服务*/ rclcpp::Publisher<example_ros2_interfaces::msg::RobotStatus>::SharedPtr robot_status_publisher_; /*发布机器人位...