Add command processing functionality to CustomRobot class. Introduced methods for handling OAC and Sport commands via MQTT messages, including validation and response publishing. Removed unnecessary logging statements for cleaner output.

This commit is contained in:
2025-09-09 11:15:03 +08:00
parent cf58ad202a
commit f46bb3b7c9
5 changed files with 162 additions and 79 deletions

View File

@@ -9,6 +9,7 @@
#include <atomic>
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
#include <unitree/robot/go2/robot_state/robot_state_client.hpp>
namespace custom {
@@ -27,11 +28,15 @@ public:
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();
void processCmd(const nlohmann::json& message);
bool processOacCmd(const std::string& cmd, const nlohmann::json& message);
bool processSportCmd(const std::string& cmd, const nlohmann::json& message);
void publishCmdResponse(const std::string& type, const std::string& cmd, bool success);
private:
std::string generateRandomClientId() const;