Implement MQTT functionality in CustomRobot class. Added methods for MQTT initialization, message handling, and connection management. Updated configuration to remove multimedia settings and streamline MQTT-related parameters. Enhanced logging for MQTT operations and ensured proper cleanup during shutdown.
This commit is contained in:
@@ -29,8 +29,6 @@ constexpr std::string_view MQTT_PASSWORD = "";
|
||||
constexpr std::string_view TOPIC_PREFIX = "unitree/go2";
|
||||
constexpr std::string_view TOPIC_CMD = "cmd";
|
||||
constexpr std::string_view TOPIC_STATE = "state";
|
||||
constexpr std::string_view TOPIC_VIDEO = "video";
|
||||
constexpr std::string_view TOPIC_AUDIO = "audio";
|
||||
|
||||
// Robot control settings
|
||||
constexpr double CONTROL_FREQUENCY = 200.0; // Hz
|
||||
@@ -45,18 +43,6 @@ constexpr double EMERGENCY_STOP_TIMEOUT = 5.0; // seconds
|
||||
constexpr double STAND_HEIGHT = 0.0; // relative height
|
||||
constexpr Gait DEFAULT_GAIT = Gait::IDLE;
|
||||
|
||||
// Video settings
|
||||
constexpr int VIDEO_WIDTH = 1280;
|
||||
constexpr int VIDEO_HEIGHT = 720;
|
||||
constexpr int VIDEO_FPS = 30;
|
||||
constexpr std::string_view VIDEO_FORMAT = "h264";
|
||||
constexpr bool VIDEO_ENABLED = true;
|
||||
|
||||
// Audio settings
|
||||
constexpr int AUDIO_SAMPLE_RATE = 16000;
|
||||
constexpr int AUDIO_CHANNELS = 1;
|
||||
constexpr std::string_view AUDIO_FORMAT = "pcm";
|
||||
constexpr bool AUDIO_ENABLED = true;
|
||||
|
||||
class CustomConfig {
|
||||
public:
|
||||
@@ -72,8 +58,6 @@ public:
|
||||
std::string topic_prefix;
|
||||
std::string topic_cmd;
|
||||
std::string topic_state;
|
||||
std::string topic_video;
|
||||
std::string topic_audio;
|
||||
|
||||
// 机器人控制和安全
|
||||
double control_frequency;
|
||||
@@ -84,16 +68,6 @@ public:
|
||||
double stand_height;
|
||||
int default_gait;
|
||||
|
||||
// 多媒体
|
||||
bool enable_video;
|
||||
bool enable_audio;
|
||||
int video_width;
|
||||
int video_height;
|
||||
int video_fps;
|
||||
std::string video_format;
|
||||
int audio_sample_rate;
|
||||
int audio_channels;
|
||||
std::string audio_format;
|
||||
|
||||
void loadDefaults();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "controller.hpp"
|
||||
#include "config.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "mqtt.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
@@ -22,14 +23,21 @@ public:
|
||||
|
||||
Controller* getController() const { return controller_.get(); }
|
||||
|
||||
// Robot state methods
|
||||
bool GetServiceList(std::vector<unitree::robot::go2::ServiceState>& serviceList);
|
||||
bool SwitchService(const std::string& serviceName, bool enable);
|
||||
bool SetReportFreq(int32_t interval, int32_t duration);
|
||||
|
||||
// MQTT related methods
|
||||
bool initializeMqtt();
|
||||
void onMqttMessage(const std::string& topic, const std::string& payload);
|
||||
void onMqttConnection(bool connected);
|
||||
void publishStatus();
|
||||
|
||||
private:
|
||||
std::string generateRandomClientId() const;
|
||||
std::unique_ptr<Controller> controller_;
|
||||
std::unique_ptr<unitree::robot::go2::RobotStateClient> rsc_;
|
||||
std::unique_ptr<MqttClient> mqttClient_;
|
||||
|
||||
CustomConfig config_;
|
||||
std::atomic<bool> running_;
|
||||
|
||||
Reference in New Issue
Block a user