text: #include <functional>
  #include <future>
  #include <memory>
  #include <string>
  #include <sstream>
  
  #include "action_tutorials_interfaces/action/fibonacci.hpp"
  
  #include "rclcpp/rclcpp.hpp"
  #include "rclcpp_action/rclcpp_action.hpp"
  #include "rclcpp_components/register_node_macro.hpp"
  
  namespace action_tutorials_cpp
  {
  class FibonacciActionClient : public rclcpp::Node
  {
  public:
    using Fibonacci = action_tutorials_interfaces::action::Fibonacci;
    using GoalHandleFibonacci = rclcpp_action::ClientGoalHandle<Fibonacci>;
  
      // 构造函数
    explicit FibonacciActionClient(const rclcpp::NodeOptions & options)
    : Node("fibonacci_action_client", options)
    {
      this->client_ptr_ = rclcpp_action::create_client<Fibonacci>(
        this,
        "fibonacci");
  
          // 创建一个时间触发器 0.5s一个callback
      this->timer_ = this->create_wall_timer(
        std::chrono::milliseconds(500),
        std::bind(&FibonacciActionClient::send_goal, this));
      RCLCPP_INFO(this->get_logger(), "client构造函数");
    }
  
      // 定义回调函数
    void send_goal()
    {
      using namespace std::placeholders;
  
      this->timer_->cancel(); // 当已经在这个里面的时候就把这个回调的频率关闭
  
      //下面这个判断不知道是用来干啥
      if (!this->client_ptr_->wait_for_action_server()) {
        RCLCPP_ERROR(this->get_logger(), "Action server not available after waiting");
        rclcpp::shutdown();
      }
  
  
      auto goal_msg = Fibonacci::Goal();
      goal_msg.order = 10;
  
      RCLCPP_INFO(this->get_logger(), "发送目标，肥波级数是10");
      auto send_goal_options = rclcpp_action::Client<Fibonacci>::SendGoalOptions();
      send_goal_options.goal_response_callback =
        std::bind(&FibonacciActionClient::goal_response_callback, this, _1);
      send_goal_options.feedback_callback =
        std::bind(&FibonacciActionClient::feedback_callback, this, _1, _2);
      send_goal_options.result_callback =
        std::bind(&FibonacciActionClient::result_callback, this, _1);
      this->client_ptr_->async_send_goal(goal_msg, send_goal_options);
    }
  
  private:
    rclcpp_action::Client<Fibonacci>::SharedPtr client_ptr_;
    rclcpp::TimerBase::SharedPtr timer_;
  
    void goal_response_callback(std::shared_future<GoalHandleFibonacci::SharedPtr> future)
    {
      RCLCPP_INFO(this->get_logger(), "goal response callback 目标反馈的回调");
      
      auto goal_handle = future.get(); // 对应 server 里面的：return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE;
      if (!goal_handle) {
        RCLCPP_ERROR(this->get_logger(), "目标被服务器拒绝了");
      } else {
        RCLCPP_INFO(this->get_logger(), "目标已经被服务器接受，等待结果吧～～～");
      }
    }
  
    void feedback_callback(
      GoalHandleFibonacci::SharedPtr,
      const std::shared_ptr<const Fibonacci::Feedback> feedback)
    {
      RCLCPP_INFO(this->get_logger(), "feedback callback");
      std::stringstream ss;
      ss << "受到了： ";
      for (auto number : feedback->partial_sequence) {
        ss << number << " ";
      }
      RCLCPP_INFO(this->get_logger(), ss.str().c_str());
    }
  
    void result_callback(const GoalHandleFibonacci::WrappedResult & result)
    {
      RCLCPP_INFO(this->get_logger(),"result callback 结果回调");
      switch (result.code) {
        case rclcpp_action::ResultCode::SUCCEEDED:
          break; //跳出这个switch
        case rclcpp_action::ResultCode::ABORTED:
          RCLCPP_ERROR(this->get_logger(), "Goal was aborted");
          return; // 直接gg
        case rclcpp_action::ResultCode::CANCELED:
          RCLCPP_ERROR(this->get_logger(), "Goal was canceled");
          return;
        default:
          RCLCPP_ERROR(this->get_logger(), "Unknown result code");
          return;
      }
      std::stringstream ss;
      ss << "最终接受到的结果: ";
      for (auto number : result.result->sequence) {
        ss << number << " ";
      }
      RCLCPP_INFO(this->get_logger(), ss.str().c_str());
      rclcpp::shutdown(); // 着一块就会把client 在succeed之后关闭结点。而server目前还没有
    }
  };  // class FibonacciActionClient
  
  }  // namespace action_tutorials_cpp
  
  RCLCPP_COMPONENTS_REGISTER_NODE(action_tutorials_cpp::FibonacciActionClient)