|
@@ -38,25 +38,25 @@ void WorkflowManager::initializeSubscriptions()
|
|
|
{
|
|
{
|
|
|
this->stationDetectedCallback(msg);
|
|
this->stationDetectedCallback(msg);
|
|
|
});
|
|
});
|
|
|
- rotation_timeout_sub_ = node_->create_subscription<std_msgs::msg::String>(
|
|
|
|
|
- "/wheelchair/rotation_timeout", 10,
|
|
|
|
|
- [this](const std_msgs::msg::String::SharedPtr msg)
|
|
|
|
|
- {
|
|
|
|
|
- if (msg->data == "rotation_timeout")
|
|
|
|
|
- {
|
|
|
|
|
- RCLCPP_INFO(node_->get_logger(), "收到旋转超时信号,返回就绪状态");
|
|
|
|
|
-
|
|
|
|
|
- // 如果当前是旋转状态,处理超时
|
|
|
|
|
- if (current_state_ == WheelchairState::ROTATING)
|
|
|
|
|
- {
|
|
|
|
|
- // 发布回充失败通知
|
|
|
|
|
- publishRechargeStatus("RECHARGE_FAILED", "旋转搜索超时,未检测到基站");
|
|
|
|
|
-
|
|
|
|
|
- // 返回就绪状态
|
|
|
|
|
- transitionToReady();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // rotation_timeout_sub_ = node_->create_subscription<std_msgs::msg::String>(
|
|
|
|
|
+ // "/wheelchair/rotation_timeout", 10,
|
|
|
|
|
+ // [this](const std_msgs::msg::String::SharedPtr msg)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // if (msg->data == "rotation_timeout")
|
|
|
|
|
+ // {
|
|
|
|
|
+ // RCLCPP_INFO(node_->get_logger(), "收到旋转超时信号,返回就绪状态");
|
|
|
|
|
+
|
|
|
|
|
+ // // 如果当前是旋转状态,处理超时
|
|
|
|
|
+ // if (current_state_ == WheelchairState::ROTATING)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // // 发布回充失败通知
|
|
|
|
|
+ // publishRechargeStatus("RECHARGE_FAILED", "旋转搜索超时,未检测到基站");
|
|
|
|
|
+
|
|
|
|
|
+ // // 返回就绪状态
|
|
|
|
|
+ // transitionToReady();
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+ // });
|
|
|
|
|
|
|
|
RCLCPP_INFO(node_->get_logger(), "基站检测订阅者已初始化");
|
|
RCLCPP_INFO(node_->get_logger(), "基站检测订阅者已初始化");
|
|
|
node_->declare_parameter<bool>("in_rotation_delay", false);
|
|
node_->declare_parameter<bool>("in_rotation_delay", false);
|
|
@@ -75,26 +75,26 @@ void WorkflowManager::stationDetectedCallback(const std_msgs::msg::Bool::SharedP
|
|
|
current_state_str.c_str());
|
|
current_state_str.c_str());
|
|
|
|
|
|
|
|
// 处理旋转中检测到基站的情况
|
|
// 处理旋转中检测到基站的情况
|
|
|
- if (station_detected && current_state_ == WheelchairState::ROTATING)
|
|
|
|
|
- {
|
|
|
|
|
- RCLCPP_INFO(node_->get_logger(),
|
|
|
|
|
- "旋转中检测到基站,记录检测时间并设置延迟切换");
|
|
|
|
|
|
|
+ // if (station_detected && current_state_ == WheelchairState::ROTATING)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // RCLCPP_INFO(node_->get_logger(),
|
|
|
|
|
+ // "旋转中检测到基站,记录检测时间并设置延迟切换");
|
|
|
|
|
|
|
|
- // 记录检测时间和状态
|
|
|
|
|
- station_detected_while_rotating_ = true;
|
|
|
|
|
- station_detected_time_ = node_->now();
|
|
|
|
|
- // 通知激光控制器进入旋转延迟模式
|
|
|
|
|
- node_->set_parameter(rclcpp::Parameter("in_rotation_delay", true));
|
|
|
|
|
|
|
+ // // 记录检测时间和状态
|
|
|
|
|
+ // station_detected_while_rotating_ = true;
|
|
|
|
|
+ // station_detected_time_ = node_->now();
|
|
|
|
|
+ // // 通知激光控制器进入旋转延迟模式
|
|
|
|
|
+ // node_->set_parameter(rclcpp::Parameter("in_rotation_delay", true));
|
|
|
|
|
|
|
|
- // 启动延迟定时器(2秒后切换状态)
|
|
|
|
|
- startRotationDelayTimer();
|
|
|
|
|
|
|
+ // // 启动延迟定时器(2秒后切换状态)
|
|
|
|
|
+ // startRotationDelayTimer();
|
|
|
|
|
|
|
|
- // 发布状态信息
|
|
|
|
|
- publishState("STATION_DETECTED_WHILE_ROTATING",
|
|
|
|
|
- "旋转中检测到基站,继续旋转2秒后对接");
|
|
|
|
|
|
|
+ // // 发布状态信息
|
|
|
|
|
+ // publishState("STATION_DETECTED_WHILE_ROTATING",
|
|
|
|
|
+ // "旋转中检测到基站,继续旋转2秒后对接");
|
|
|
|
|
|
|
|
- return; // 直接返回,不立即切换状态
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // return; // 直接返回,不立即切换状态
|
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
// 搜索中检测到基站,立即切换状态(保持原有逻辑)
|
|
// 搜索中检测到基站,立即切换状态(保持原有逻辑)
|
|
|
if (station_detected && current_state_ == WheelchairState::SEARCHING)
|
|
if (station_detected && current_state_ == WheelchairState::SEARCHING)
|
|
@@ -778,8 +778,8 @@ void WorkflowManager::transitionToSearching()
|
|
|
RCLCPP_INFO(node_->get_logger(), "开始搜索充电站");
|
|
RCLCPP_INFO(node_->get_logger(), "开始搜索充电站");
|
|
|
publishState("SEARCH_CHARGING_STATION_START");
|
|
publishState("SEARCH_CHARGING_STATION_START");
|
|
|
startSearchTimeoutTimer();
|
|
startSearchTimeoutTimer();
|
|
|
- startRotationTimer();
|
|
|
|
|
- // 发布回充开始通知
|
|
|
|
|
|
|
+ // startRotationTimer();
|
|
|
|
|
+ // 发布回充开始通知
|
|
|
publishRechargeStatus("RECHARGE_STARTED", "回充功能已启动,正在搜索充电站");
|
|
publishRechargeStatus("RECHARGE_STARTED", "回充功能已启动,正在搜索充电站");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1278,20 +1278,25 @@ void WorkflowManager::handleSearchTimeoutEvent()
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
- RCLCPP_INFO(node_->get_logger(), "处理搜索超时事件");
|
|
|
|
|
-
|
|
|
|
|
- // 记录当前状态,便于调试
|
|
|
|
|
- std::string current_state_str = getCurrentState();
|
|
|
|
|
- RCLCPP_INFO(node_->get_logger(), "搜索超时发生时的状态: %s", current_state_str.c_str());
|
|
|
|
|
-
|
|
|
|
|
- // 搜索超时30秒视为回充失败
|
|
|
|
|
- RCLCPP_WARN(node_->get_logger(), "搜索30秒超时,回充失败");
|
|
|
|
|
|
|
+ if (DEBUG_LEVEL)
|
|
|
|
|
+ {
|
|
|
|
|
+ RCLCPP_INFO(node_->get_logger(), "转入旋转搜索");
|
|
|
|
|
+ // 进入旋转流程
|
|
|
|
|
+ transitionToRotating();
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ // 记录当前状态,便于调试
|
|
|
|
|
+ std::string current_state_str = getCurrentState();
|
|
|
|
|
+ RCLCPP_INFO(node_->get_logger(), "搜索超时发生时的状态: %s", current_state_str.c_str());
|
|
|
|
|
|
|
|
- // 发布回充失败通知
|
|
|
|
|
- publishRechargeStatus("RECHARGE_FAILED", "搜索充电站秒超时");
|
|
|
|
|
|
|
+ // 搜索超时30秒视为回充失败
|
|
|
|
|
+ RCLCPP_WARN(node_->get_logger(), "搜索超时,回充失败");
|
|
|
|
|
|
|
|
- // 退出回充流程
|
|
|
|
|
- transitionToReady();
|
|
|
|
|
|
|
+ // 发布回充失败通知
|
|
|
|
|
+ publishRechargeStatus("RECHARGE_FAILED", "搜索充电站秒超时");
|
|
|
|
|
+ transitionToReady();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
catch (const std::exception &e)
|
|
catch (const std::exception &e)
|
|
|
{
|
|
{
|
|
@@ -1467,9 +1472,9 @@ void WorkflowManager::startSearchTimeoutTimer()
|
|
|
search_timeout_timer_->cancel();
|
|
search_timeout_timer_->cancel();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 创建30秒定时器
|
|
|
|
|
|
|
+ // 创建10秒定时器
|
|
|
search_timeout_timer_ = node_->create_wall_timer(
|
|
search_timeout_timer_ = node_->create_wall_timer(
|
|
|
- std::chrono::seconds(30),
|
|
|
|
|
|
|
+ std::chrono::seconds(10),
|
|
|
[this]()
|
|
[this]()
|
|
|
{
|
|
{
|
|
|
this->searchTimeoutCallback();
|
|
this->searchTimeoutCallback();
|
|
@@ -1527,14 +1532,13 @@ void WorkflowManager::searchTimeoutCallback()
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
- // 只在搜索状态下处理搜索超时,旋转状态由RotationManager处理
|
|
|
|
|
if (current_state_ == WheelchairState::SEARCHING)
|
|
if (current_state_ == WheelchairState::SEARCHING)
|
|
|
{
|
|
{
|
|
|
double total_search_time = (node_->now() - search_start_time_).seconds();
|
|
double total_search_time = (node_->now() - search_start_time_).seconds();
|
|
|
|
|
|
|
|
- RCLCPP_WARN(node_->get_logger(),
|
|
|
|
|
- "搜索 %.1f 秒超时,回充失败",
|
|
|
|
|
- total_search_time);
|
|
|
|
|
|
|
+ // RCLCPP_WARN(node_->get_logger(),
|
|
|
|
|
+ // "搜索 %.1f 秒超时,回充失败",
|
|
|
|
|
+ // total_search_time);
|
|
|
handleSearchTimeoutEvent();
|
|
handleSearchTimeoutEvent();
|
|
|
}
|
|
}
|
|
|
else if (current_state_ == WheelchairState::ROTATING)
|
|
else if (current_state_ == WheelchairState::ROTATING)
|