208 lines
7.4 KiB
C++
208 lines
7.4 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace customConfig {
|
|
|
|
// Configuration template selector
|
|
enum class ConfigPreset {
|
|
Default,
|
|
HighPerformance,
|
|
Development,
|
|
Safety
|
|
};
|
|
|
|
// Motion gait enum
|
|
enum class Gait : int {
|
|
IDLE = 0,
|
|
TROT = 1,
|
|
TROT_RUNNING = 2
|
|
};
|
|
|
|
// Network configuration
|
|
constexpr std::string_view NETWORK_INTERFACE = "eth0";
|
|
|
|
// MQTT configuration
|
|
constexpr std::string_view MQTT_BROKER = "localhost";
|
|
constexpr int MQTT_PORT = 1883;
|
|
constexpr std::string_view MQTT_USERNAME = "";
|
|
constexpr std::string_view MQTT_PASSWORD = "";
|
|
constexpr std::string_view MQTT_CLIENT_ID = "unitree_go2_client";
|
|
|
|
// Topic configuration
|
|
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 configuration
|
|
constexpr double CONTROL_FREQUENCY = 200.0; // Hz
|
|
constexpr double STATE_PUBLISH_FREQUENCY = 50.0; // Hz
|
|
|
|
// Safety configuration
|
|
constexpr double MAX_LINEAR_VELOCITY = 1.5; // m/s
|
|
constexpr double MAX_ANGULAR_VELOCITY = 2.0; // rad/s
|
|
constexpr double EMERGENCY_STOP_TIMEOUT = 5.0; // seconds
|
|
|
|
// Motion configuration
|
|
constexpr double STAND_HEIGHT = 0.0; // relative height
|
|
constexpr Gait DEFAULT_GAIT = Gait::IDLE;
|
|
|
|
// Video configuration
|
|
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 configuration
|
|
constexpr int AUDIO_SAMPLE_RATE = 16000;
|
|
constexpr int AUDIO_CHANNELS = 1;
|
|
constexpr std::string_view AUDIO_FORMAT = "pcm";
|
|
constexpr bool AUDIO_ENABLED = true;
|
|
|
|
// Configuration presets using template specialization
|
|
template<ConfigPreset P>
|
|
struct ConfigParams;
|
|
|
|
// Default preset
|
|
template<>
|
|
struct ConfigParams<ConfigPreset::Default> {
|
|
static constexpr double control_frequency = CONTROL_FREQUENCY;
|
|
static constexpr double state_publish_frequency = STATE_PUBLISH_FREQUENCY;
|
|
static constexpr double max_linear_velocity = MAX_LINEAR_VELOCITY;
|
|
static constexpr double max_angular_velocity = MAX_ANGULAR_VELOCITY;
|
|
static constexpr double emergency_stop_timeout = EMERGENCY_STOP_TIMEOUT;
|
|
static constexpr bool video_enabled = VIDEO_ENABLED;
|
|
static constexpr bool audio_enabled = AUDIO_ENABLED;
|
|
};
|
|
|
|
// High performance preset
|
|
template<>
|
|
struct ConfigParams<ConfigPreset::HighPerformance> {
|
|
static constexpr double control_frequency = 500.0;
|
|
static constexpr double state_publish_frequency = 100.0;
|
|
static constexpr double max_linear_velocity = 2.5;
|
|
static constexpr double max_angular_velocity = 3.0;
|
|
static constexpr double emergency_stop_timeout = EMERGENCY_STOP_TIMEOUT;
|
|
static constexpr bool video_enabled = false; // Disabled for performance
|
|
static constexpr bool audio_enabled = false; // Disabled for performance
|
|
};
|
|
|
|
// Development preset
|
|
template<>
|
|
struct ConfigParams<ConfigPreset::Development> {
|
|
static constexpr double control_frequency = 100.0;
|
|
static constexpr double state_publish_frequency = 20.0;
|
|
static constexpr double max_linear_velocity = 0.8;
|
|
static constexpr double max_angular_velocity = 1.0;
|
|
static constexpr double emergency_stop_timeout = EMERGENCY_STOP_TIMEOUT;
|
|
static constexpr bool video_enabled = true;
|
|
static constexpr bool audio_enabled = true;
|
|
};
|
|
|
|
// Safety preset
|
|
template<>
|
|
struct ConfigParams<ConfigPreset::Safety> {
|
|
static constexpr double control_frequency = 50.0;
|
|
static constexpr double state_publish_frequency = 10.0;
|
|
static constexpr double max_linear_velocity = 0.5;
|
|
static constexpr double max_angular_velocity = 0.5;
|
|
static constexpr double emergency_stop_timeout = 2.0;
|
|
static constexpr bool video_enabled = true;
|
|
static constexpr bool audio_enabled = true;
|
|
};
|
|
|
|
// Compile-time configuration selection (set this to choose preset)
|
|
constexpr ConfigPreset ACTIVE_PRESET = ConfigPreset::Default;
|
|
|
|
// Compile-time configuration struct
|
|
template<ConfigPreset P = ACTIVE_PRESET>
|
|
struct CompileTimeConfig {
|
|
// Use selected preset parameters
|
|
using params = ConfigParams<P>;
|
|
|
|
// Network settings
|
|
static constexpr std::string_view network_interface = NETWORK_INTERFACE;
|
|
|
|
// MQTT settings
|
|
static constexpr std::string_view mqtt_broker = MQTT_BROKER;
|
|
static constexpr int mqtt_port = MQTT_PORT;
|
|
static constexpr std::string_view mqtt_username = MQTT_USERNAME;
|
|
static constexpr std::string_view mqtt_password = MQTT_PASSWORD;
|
|
static constexpr std::string_view mqtt_client_id = MQTT_CLIENT_ID;
|
|
|
|
// Topics
|
|
static constexpr std::string_view topic_prefix = TOPIC_PREFIX;
|
|
static constexpr std::string_view cmd_topic = TOPIC_CMD;
|
|
static constexpr std::string_view state_topic = TOPIC_STATE;
|
|
static constexpr std::string_view video_topic = TOPIC_VIDEO;
|
|
static constexpr std::string_view audio_topic = TOPIC_AUDIO;
|
|
|
|
// Robot settings (from preset)
|
|
static constexpr double control_frequency = params::control_frequency;
|
|
static constexpr double state_publish_frequency = params::state_publish_frequency;
|
|
static constexpr bool enable_video = params::video_enabled;
|
|
static constexpr bool enable_audio = params::audio_enabled;
|
|
|
|
// Safety settings (from preset)
|
|
static constexpr double max_linear_velocity = params::max_linear_velocity;
|
|
static constexpr double max_angular_velocity = params::max_angular_velocity;
|
|
static constexpr double emergency_stop_timeout = params::emergency_stop_timeout;
|
|
|
|
// Motion settings
|
|
static constexpr double stand_height = STAND_HEIGHT;
|
|
static constexpr Gait default_gait = DEFAULT_GAIT;
|
|
|
|
// Video settings
|
|
static constexpr int video_width = VIDEO_WIDTH;
|
|
static constexpr int video_height = VIDEO_HEIGHT;
|
|
static constexpr int video_fps = VIDEO_FPS;
|
|
static constexpr std::string_view video_format = VIDEO_FORMAT;
|
|
|
|
// Audio settings
|
|
static constexpr int audio_sample_rate = AUDIO_SAMPLE_RATE;
|
|
static constexpr int audio_channels = AUDIO_CHANNELS;
|
|
static constexpr std::string_view audio_format = AUDIO_FORMAT;
|
|
|
|
// Utility functions
|
|
static std::string getFullTopic(std::string_view topic) {
|
|
return std::string(topic_prefix) + "/" + std::string(topic);
|
|
}
|
|
};
|
|
|
|
// Type alias for current configuration
|
|
using RobotConfig = CompileTimeConfig<ACTIVE_PRESET>;
|
|
|
|
// Configuration validation utilities
|
|
template<ConfigPreset P>
|
|
constexpr bool isConfigValid() {
|
|
using config = ConfigParams<P>;
|
|
return config::control_frequency > 0.0 &&
|
|
config::state_publish_frequency > 0.0 &&
|
|
config::max_linear_velocity > 0.0 &&
|
|
config::max_angular_velocity > 0.0 &&
|
|
config::emergency_stop_timeout > 0.0;
|
|
}
|
|
|
|
// Compile-time validation
|
|
static_assert(isConfigValid<ACTIVE_PRESET>(), "Invalid configuration parameters");
|
|
|
|
// Configuration preset name utilities
|
|
template<ConfigPreset P>
|
|
constexpr const char* getPresetName() {
|
|
if constexpr (P == ConfigPreset::Default) return "Default";
|
|
else if constexpr (P == ConfigPreset::HighPerformance) return "HighPerformance";
|
|
else if constexpr (P == ConfigPreset::Development) return "Development";
|
|
else if constexpr (P == ConfigPreset::Safety) return "Safety";
|
|
else return "Unknown";
|
|
}
|
|
|
|
constexpr const char* getActivePresetName() {
|
|
return getPresetName<ACTIVE_PRESET>();
|
|
}
|
|
|
|
} // namespace customConfig
|