feat(robot): 添加监控模块到自定义机器人

在自定义机器人中添加Monitor模块,用于监控机器人状态。包括在头文件中添加Monitor成员变量声明,在实现文件中添加初始化和资源释放逻辑。
This commit is contained in:
2025-09-30 16:38:00 +08:00
parent d3487a2613
commit 3a209734de
2 changed files with 9 additions and 0 deletions

View File

@@ -6,6 +6,7 @@
#include "mqtt.hpp" #include "mqtt.hpp"
#include "navigation.hpp" #include "navigation.hpp"
#include "recharge.hpp" #include "recharge.hpp"
#include "monitor.hpp"
// #include "low_controller.hpp" // #include "low_controller.hpp"
#include <memory> #include <memory>
@@ -59,6 +60,7 @@ private:
std::unique_ptr<unitree::robot::go2::RobotStateClient> rsc_; std::unique_ptr<unitree::robot::go2::RobotStateClient> rsc_;
std::unique_ptr<MqttClient> mqttClient_; std::unique_ptr<MqttClient> mqttClient_;
std::unique_ptr<Recharge> recharge_; std::unique_ptr<Recharge> recharge_;
std::unique_ptr<Monitor> monitor_;
CustomConfig config_; CustomConfig config_;
std::atomic<bool> running_; std::atomic<bool> running_;

View File

@@ -66,6 +66,10 @@ CustomRobot::~CustomRobot() {
recharge_.reset(); recharge_.reset();
} }
if (monitor_) {
monitor_.reset();
}
try { try {
unitree::robot::ChannelFactory::Instance()->Release(); unitree::robot::ChannelFactory::Instance()->Release();
LOG_INFO("ChannelFactory released"); LOG_INFO("ChannelFactory released");
@@ -94,6 +98,9 @@ bool CustomRobot::initialize() {
recharge_ = std::make_unique<Recharge>(); recharge_ = std::make_unique<Recharge>();
recharge_->Init(); recharge_->Init();
monitor_ = std::make_unique<Monitor>();
monitor_->initialize();
if (!initializeMqtt()) { if (!initializeMqtt()) {
LOG_ERROR("Failed to initialize MQTT client"); LOG_ERROR("Failed to initialize MQTT client");
return false; return false;