|
@@ -1,10 +1,12 @@
|
|
|
|
|
+// event_input.cpp
|
|
|
#include "wheelchair_state_machine/event_input.hpp"
|
|
#include "wheelchair_state_machine/event_input.hpp"
|
|
|
#include <rclcpp/logging.hpp>
|
|
#include <rclcpp/logging.hpp>
|
|
|
#include <std_msgs/msg/bool.hpp>
|
|
#include <std_msgs/msg/bool.hpp>
|
|
|
using namespace std::chrono_literals;
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
|
|
EventInputHandler::EventInputHandler(rclcpp::Node *node)
|
|
EventInputHandler::EventInputHandler(rclcpp::Node *node)
|
|
|
- : node_(node), battery_manager_(nullptr), lidar_controller_(nullptr), ipad_manager_(nullptr), workflow_manager_(nullptr), report_manager_(nullptr)
|
|
|
|
|
|
|
+ : node_(node), battery_manager_(nullptr), lidar_controller_(nullptr),
|
|
|
|
|
+ ipad_manager_(nullptr), workflow_manager_(nullptr), report_manager_(nullptr)
|
|
|
{
|
|
{
|
|
|
RCLCPP_INFO(node_->get_logger(), "事件输入处理器已初始化");
|
|
RCLCPP_INFO(node_->get_logger(), "事件输入处理器已初始化");
|
|
|
}
|
|
}
|
|
@@ -25,9 +27,8 @@ void EventInputHandler::initializeModules()
|
|
|
// 初始化工作流管理器
|
|
// 初始化工作流管理器
|
|
|
workflow_manager_ = std::make_unique<WorkflowManager>(node_);
|
|
workflow_manager_ = std::make_unique<WorkflowManager>(node_);
|
|
|
|
|
|
|
|
- // 初始化报告管理器(包含错误管理)
|
|
|
|
|
|
|
+ // 初始化报告管理器
|
|
|
report_manager_ = std::make_unique<ReportManager>(node_);
|
|
report_manager_ = std::make_unique<ReportManager>(node_);
|
|
|
- report_manager_->initializeErrorManager(); // 初始化错误管理
|
|
|
|
|
|
|
|
|
|
setupModuleCallbacks();
|
|
setupModuleCallbacks();
|
|
|
setupSubscriptions();
|
|
setupSubscriptions();
|
|
@@ -62,7 +63,7 @@ void EventInputHandler::setupModuleCallbacks()
|
|
|
triggerLowBattery(state, percentage);
|
|
triggerLowBattery(state, percentage);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // 2. 设置iPad管理器回调 - 只处理开始和结束
|
|
|
|
|
|
|
+ // 2. 设置iPad管理器回调
|
|
|
ipad_manager_->setRechargeStartCallback(
|
|
ipad_manager_->setRechargeStartCallback(
|
|
|
[this]()
|
|
[this]()
|
|
|
{
|
|
{
|
|
@@ -77,36 +78,7 @@ void EventInputHandler::setupModuleCallbacks()
|
|
|
triggerEvent("ipad_phone_interface_cancel");
|
|
triggerEvent("ipad_phone_interface_cancel");
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // 3. 设置报告管理器错误回调
|
|
|
|
|
- report_manager_->setErrorCallback(
|
|
|
|
|
- [this](const ErrorInfo &error_info)
|
|
|
|
|
- {
|
|
|
|
|
- // 所有错误都通过报告管理器反馈
|
|
|
|
|
- std::stringstream msg;
|
|
|
|
|
- msg << "系统错误: " << error_info.module_name
|
|
|
|
|
- << " - " << error_info.description;
|
|
|
|
|
- report_manager_->reportWarning(msg.str());
|
|
|
|
|
-
|
|
|
|
|
- // 如果错误与回充相关,触发工作流事件
|
|
|
|
|
- if (error_info.getModule() == ErrorModule::RECHARGE)
|
|
|
|
|
- {
|
|
|
|
|
- triggerEvent("error_code_handling", error_info.description);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- report_manager_->setCriticalErrorCallback(
|
|
|
|
|
- [this](const ErrorInfo &error_info)
|
|
|
|
|
- {
|
|
|
|
|
- handleCriticalError(error_info);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- report_manager_->setRecoveryCallback(
|
|
|
|
|
- [this](const ErrorInfo &error_info)
|
|
|
|
|
- {
|
|
|
|
|
- handleErrorRecovery(error_info);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 4. 设置工作流管理器回调
|
|
|
|
|
|
|
+ // 3. 设置工作流管理器状态更新回调
|
|
|
workflow_manager_->setStateUpdateCallback(
|
|
workflow_manager_->setStateUpdateCallback(
|
|
|
[this](const std::string &state_str, const std::string &message)
|
|
[this](const std::string &state_str, const std::string &message)
|
|
|
{
|
|
{
|
|
@@ -130,68 +102,33 @@ void EventInputHandler::setupModuleCallbacks()
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // 5. 设置工作流管理器回充状态回调
|
|
|
|
|
|
|
+ // 4. 设置工作流管理器回充状态回调
|
|
|
workflow_manager_->setRechargeStatusCallback(
|
|
workflow_manager_->setRechargeStatusCallback(
|
|
|
[this](const std::string &status, const std::string &message)
|
|
[this](const std::string &status, const std::string &message)
|
|
|
{
|
|
{
|
|
|
// 处理回充状态更新
|
|
// 处理回充状态更新
|
|
|
RCLCPP_INFO(node_->get_logger(), "[回充状态] %s: %s", status.c_str(), message.c_str());
|
|
RCLCPP_INFO(node_->get_logger(), "[回充状态] %s: %s", status.c_str(), message.c_str());
|
|
|
|
|
|
|
|
- // 根据回充状态采取行动
|
|
|
|
|
|
|
+ // 所有回充状态都通过报告管理器反馈
|
|
|
if (status == "RECHARGE_FAILED")
|
|
if (status == "RECHARGE_FAILED")
|
|
|
{
|
|
{
|
|
|
- // 回充失败,通过报告管理器反馈
|
|
|
|
|
- std::string error_msg = "回充失败: " + message;
|
|
|
|
|
- report_manager_->reportWarning(error_msg);
|
|
|
|
|
-
|
|
|
|
|
- // 生成回充失败错误码
|
|
|
|
|
- uint32_t error_code = 0x51010101; // 回充检测失败
|
|
|
|
|
- report_manager_->processErrorCode(error_code);
|
|
|
|
|
|
|
+ report_manager_->reportWarning("回充失败: " + message);
|
|
|
}
|
|
}
|
|
|
else if (status == "RECHARGE_SUCCESS")
|
|
else if (status == "RECHARGE_SUCCESS")
|
|
|
{
|
|
{
|
|
|
- // 回充成功,记录信息
|
|
|
|
|
report_manager_->reportInfo("回充成功: " + message);
|
|
report_manager_->reportInfo("回充成功: " + message);
|
|
|
}
|
|
}
|
|
|
else if (status == "CHARGING_INTERRUPTED")
|
|
else if (status == "CHARGING_INTERRUPTED")
|
|
|
{
|
|
{
|
|
|
- // 充电中断
|
|
|
|
|
report_manager_->reportWarning("充电中断: " + message);
|
|
report_manager_->reportWarning("充电中断: " + message);
|
|
|
}
|
|
}
|
|
|
else if (status == "CHARGING_COMPLETED")
|
|
else if (status == "CHARGING_COMPLETED")
|
|
|
{
|
|
{
|
|
|
- // 充电完成
|
|
|
|
|
report_manager_->reportInfo("充电完成: " + message);
|
|
report_manager_->reportInfo("充电完成: " + message);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // 6. 设置工作流管理器回充错误回调
|
|
|
|
|
- workflow_manager_->setRechargeErrorCallback(
|
|
|
|
|
- [this](const ErrorInfo &error_info)
|
|
|
|
|
- {
|
|
|
|
|
- // 处理回充相关错误
|
|
|
|
|
- RCLCPP_WARN(node_->get_logger(), "回充错误: %s - %s",
|
|
|
|
|
- error_info.module_name.c_str(),
|
|
|
|
|
- error_info.description.c_str());
|
|
|
|
|
-
|
|
|
|
|
- // 通过报告管理器处理错误
|
|
|
|
|
- report_manager_->processErrorCode(error_info);
|
|
|
|
|
-
|
|
|
|
|
- // 如果错误严重,触发错误处理事件
|
|
|
|
|
- if (error_info.isCritical())
|
|
|
|
|
- {
|
|
|
|
|
- triggerEvent("error_code_handling", error_info.description);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 7. 设置事件处理器回调 - 所有事件都转发给工作流管理器
|
|
|
|
|
- registerEvent("error_code_handling",
|
|
|
|
|
- [this](const std::string &data)
|
|
|
|
|
- {
|
|
|
|
|
- RCLCPP_INFO(node_->get_logger(), "处理错误码事件: %s", data.c_str());
|
|
|
|
|
- workflow_manager_->handleEvent("error_code_handling");
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // 5. 设置事件处理器回调(仅外部输入事件)
|
|
|
registerEvent("ipad_phone_interface_start",
|
|
registerEvent("ipad_phone_interface_start",
|
|
|
[this](const std::string &data)
|
|
[this](const std::string &data)
|
|
|
{
|
|
{
|
|
@@ -297,13 +234,6 @@ void EventInputHandler::setupModuleCallbacks()
|
|
|
workflow_manager_->handleEvent("push_stop");
|
|
workflow_manager_->handleEvent("push_stop");
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- registerEvent("error_code_handling",
|
|
|
|
|
- [this](const std::string &data)
|
|
|
|
|
- {
|
|
|
|
|
- RCLCPP_INFO(node_->get_logger(), "处理错误码事件");
|
|
|
|
|
- workflow_manager_->handleEvent("error_code_handling");
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
registerEvent("base_station_lost",
|
|
registerEvent("base_station_lost",
|
|
|
[this](const std::string &data)
|
|
[this](const std::string &data)
|
|
|
{
|
|
{
|
|
@@ -331,21 +261,6 @@ void EventInputHandler::setupSubscriptions()
|
|
|
this->ipad_manager_->onCmdEnable(msg);
|
|
this->ipad_manager_->onCmdEnable(msg);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // 创建回充状态订阅者(用于监控回充超时)
|
|
|
|
|
- recharge_status_sub_ = node_->create_subscription<std_msgs::msg::String>(
|
|
|
|
|
- "wheelchair/recharge_timeout", 10,
|
|
|
|
|
- [this](const std_msgs::msg::String::SharedPtr msg)
|
|
|
|
|
- {
|
|
|
|
|
- RCLCPP_INFO(node_->get_logger(), "收到回充状态: %s", msg->data.c_str());
|
|
|
|
|
-
|
|
|
|
|
- // 检查是否是回充失败消息
|
|
|
|
|
- if (msg->data.find("RECHARGE_FAILED") != std::string::npos)
|
|
|
|
|
- {
|
|
|
|
|
- // 回充失败,记录到报告管理器
|
|
|
|
|
- report_manager_->reportWarning("回充失败通知: " + msg->data);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
RCLCPP_INFO(node_->get_logger(), "订阅器设置完成");
|
|
RCLCPP_INFO(node_->get_logger(), "订阅器设置完成");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -526,86 +441,4 @@ void EventInputHandler::displaySystemStatus()
|
|
|
lidar_controller_->getChargingVoltage(),
|
|
lidar_controller_->getChargingVoltage(),
|
|
|
isRechargeActive(),
|
|
isRechargeActive(),
|
|
|
control_mode);
|
|
control_mode);
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void EventInputHandler::handleCriticalError(const ErrorInfo &error_info)
|
|
|
|
|
-{
|
|
|
|
|
- RCLCPP_ERROR(node_->get_logger(), "检测到严重错误: %s - %s",
|
|
|
|
|
- error_info.module_name.c_str(),
|
|
|
|
|
- error_info.description.c_str());
|
|
|
|
|
-
|
|
|
|
|
- // 通过报告管理器反馈严重错误
|
|
|
|
|
- std::stringstream report;
|
|
|
|
|
- report << "严重错误警报!\n";
|
|
|
|
|
- report << "模块: " << error_info.module_name << "\n";
|
|
|
|
|
- report << "子模块: " << error_info.sub_module_name << "\n";
|
|
|
|
|
- report << "错误码: 0x" << std::hex << std::setw(8) << std::setfill('0')
|
|
|
|
|
- << error_info.error_code << "\n";
|
|
|
|
|
- report << "描述: " << error_info.description << "\n";
|
|
|
|
|
- report << "建议: 立即检查相关硬件或联系技术支持";
|
|
|
|
|
-
|
|
|
|
|
- report_manager_->reportError(report.str());
|
|
|
|
|
-
|
|
|
|
|
- // 根据错误类型采取行动
|
|
|
|
|
- ErrorModule module = error_info.getModule();
|
|
|
|
|
-
|
|
|
|
|
- if (module == ErrorModule::LIDAR5)
|
|
|
|
|
- { // 后雷达故障
|
|
|
|
|
- RCLCPP_WARN(node_->get_logger(), "后雷达故障,停止回充功能");
|
|
|
|
|
- if (isRechargeActive())
|
|
|
|
|
- {
|
|
|
|
|
- stopNavigationControl();
|
|
|
|
|
- triggerEvent("error_code_handling", "雷达故障导致回充停止");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (module == ErrorModule::DRIVER)
|
|
|
|
|
- { // 电机驱动器故障
|
|
|
|
|
- RCLCPP_WARN(node_->get_logger(), "电机驱动器故障,停止所有运动");
|
|
|
|
|
- lidar_controller_->stopMotion();
|
|
|
|
|
- triggerEvent("error_code_handling", "驱动器故障");
|
|
|
|
|
- }
|
|
|
|
|
- else if (module == ErrorModule::RECHARGE)
|
|
|
|
|
- { // 回充功能故障
|
|
|
|
|
- RCLCPP_WARN(node_->get_logger(), "回充功能故障: %s",
|
|
|
|
|
- error_info.description.c_str());
|
|
|
|
|
-
|
|
|
|
|
- // 如果是回充超时错误
|
|
|
|
|
- if (error_info.error_code == 0x51010101)
|
|
|
|
|
- {
|
|
|
|
|
- RCLCPP_WARN(node_->get_logger(), "回充超时30秒,通知用户");
|
|
|
|
|
- // 可以通过其他方式通知用户界面
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void EventInputHandler::handleErrorRecovery(const ErrorInfo &error_info)
|
|
|
|
|
-{
|
|
|
|
|
- RCLCPP_INFO(node_->get_logger(), "错误已恢复: %s - %s",
|
|
|
|
|
- error_info.module_name.c_str(),
|
|
|
|
|
- error_info.description.c_str());
|
|
|
|
|
-
|
|
|
|
|
- // 报告错误恢复
|
|
|
|
|
- std::stringstream report;
|
|
|
|
|
- report << "错误恢复通知\n";
|
|
|
|
|
- report << "模块: " << error_info.module_name << "\n";
|
|
|
|
|
- report << "错误: " << error_info.description << "\n";
|
|
|
|
|
- report << "状态: 已恢复正常";
|
|
|
|
|
-
|
|
|
|
|
- report_manager_->reportInfo(report.str());
|
|
|
|
|
-
|
|
|
|
|
- // 如果恢复了关键模块,可以重新启用相关功能
|
|
|
|
|
- if (error_info.getModule() == ErrorModule::LIDAR5)
|
|
|
|
|
- {
|
|
|
|
|
- RCLCPP_INFO(node_->get_logger(), "后雷达已恢复,可以重新启用回充功能");
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// 修改错误码触发函数
|
|
|
|
|
-void EventInputHandler::triggerErrorCode(int error_code)
|
|
|
|
|
-{
|
|
|
|
|
- std::string data = "错误码: 0x" + std::to_string(static_cast<uint32_t>(error_code));
|
|
|
|
|
- triggerEvent("error_code_handling", data);
|
|
|
|
|
-
|
|
|
|
|
- // 同时传递给报告管理器处理
|
|
|
|
|
- report_manager_->processErrorCode(static_cast<uint32_t>(error_code));
|
|
|
|
|
}
|
|
}
|