53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "controller.hpp"
|
|
#include "config.hpp"
|
|
#include "logger.hpp"
|
|
#include "mqtt.hpp"
|
|
|
|
#include <memory>
|
|
#include <atomic>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <nlohmann/json.hpp>
|
|
#include <unitree/robot/go2/robot_state/robot_state_client.hpp>
|
|
|
|
namespace custom {
|
|
|
|
class CustomRobot {
|
|
public:
|
|
explicit CustomRobot();
|
|
~CustomRobot();
|
|
|
|
bool initialize();
|
|
bool start();
|
|
|
|
Controller* getController() const { return controller_.get(); }
|
|
|
|
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);
|
|
|
|
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;
|
|
std::unique_ptr<Controller> controller_;
|
|
std::unique_ptr<unitree::robot::go2::RobotStateClient> rsc_;
|
|
std::unique_ptr<MqttClient> mqttClient_;
|
|
|
|
CustomConfig config_;
|
|
std::atomic<bool> running_;
|
|
std::atomic<bool> initialized_;
|
|
};
|
|
|
|
} // namespace custom
|