Remove MQTT dependency and refactor configuration structure. Updated CMakeLists.txt to eliminate MQTT library checks and adjusted config.hpp to use string_view for configuration parameters. Simplified controller and custom_robot classes by removing MQTT-related code and enhancing robot state management. Introduced service management methods in CustomRobot for better state handling.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace custom {
|
||||
namespace customConfig {
|
||||
|
||||
Config::Config() {
|
||||
// Load default configuration
|
||||
@@ -16,8 +16,6 @@ Config& Config::getInstance() {
|
||||
}
|
||||
|
||||
void Config::loadDefaults() {
|
||||
using namespace config;
|
||||
|
||||
config_.network_interface = NETWORK_INTERFACE;
|
||||
config_.mqtt_broker = MQTT_BROKER;
|
||||
config_.mqtt_port = MQTT_PORT;
|
||||
@@ -33,15 +31,15 @@ void Config::loadDefaults() {
|
||||
|
||||
config_.control_frequency = CONTROL_FREQUENCY;
|
||||
config_.state_publish_frequency = STATE_PUBLISH_FREQUENCY;
|
||||
config_.enable_video = ENABLE_VIDEO;
|
||||
config_.enable_audio = ENABLE_AUDIO;
|
||||
config_.enable_video = VIDEO_ENABLED;
|
||||
config_.enable_audio = AUDIO_ENABLED;
|
||||
|
||||
config_.max_linear_velocity = MAX_LINEAR_VELOCITY;
|
||||
config_.max_angular_velocity = MAX_ANGULAR_VELOCITY;
|
||||
config_.emergency_stop_timeout = EMERGENCY_STOP_TIMEOUT;
|
||||
|
||||
config_.stand_height = STAND_HEIGHT;
|
||||
config_.default_gait = GAIT;
|
||||
config_.default_gait = static_cast<int>(DEFAULT_GAIT);
|
||||
|
||||
config_.video_width = VIDEO_WIDTH;
|
||||
config_.video_height = VIDEO_HEIGHT;
|
||||
@@ -55,46 +53,48 @@ void Config::loadDefaults() {
|
||||
|
||||
void Config::loadHighPerformancePreset() {
|
||||
loadDefaults();
|
||||
config_.control_frequency = HighPerformancePreset::CONTROL_FREQUENCY;
|
||||
config_.state_publish_frequency = HighPerformancePreset::STATE_PUBLISH_FREQUENCY;
|
||||
config_.max_linear_velocity = HighPerformancePreset::MAX_LINEAR_VELOCITY;
|
||||
config_.max_angular_velocity = HighPerformancePreset::MAX_ANGULAR_VELOCITY;
|
||||
config_.enable_video = HighPerformancePreset::ENABLE_VIDEO;
|
||||
config_.enable_audio = HighPerformancePreset::ENABLE_AUDIO;
|
||||
using hp = ConfigParams<ConfigPreset::HighPerformance>;
|
||||
config_.control_frequency = hp::control_frequency;
|
||||
config_.state_publish_frequency = hp::state_publish_frequency;
|
||||
config_.max_linear_velocity = hp::max_linear_velocity;
|
||||
config_.max_angular_velocity = hp::max_angular_velocity;
|
||||
config_.enable_video = hp::video_enabled;
|
||||
config_.enable_audio = hp::audio_enabled;
|
||||
}
|
||||
|
||||
void Config::loadDevelopmentPreset() {
|
||||
loadDefaults();
|
||||
config_.control_frequency = DevelopmentPreset::CONTROL_FREQUENCY;
|
||||
config_.state_publish_frequency = DevelopmentPreset::STATE_PUBLISH_FREQUENCY;
|
||||
config_.max_linear_velocity = DevelopmentPreset::MAX_LINEAR_VELOCITY;
|
||||
config_.max_angular_velocity = DevelopmentPreset::MAX_ANGULAR_VELOCITY;
|
||||
config_.enable_video = DevelopmentPreset::ENABLE_VIDEO;
|
||||
config_.enable_audio = DevelopmentPreset::ENABLE_AUDIO;
|
||||
using dev = ConfigParams<ConfigPreset::Development>;
|
||||
config_.control_frequency = dev::control_frequency;
|
||||
config_.state_publish_frequency = dev::state_publish_frequency;
|
||||
config_.max_linear_velocity = dev::max_linear_velocity;
|
||||
config_.max_angular_velocity = dev::max_angular_velocity;
|
||||
config_.enable_video = dev::video_enabled;
|
||||
config_.enable_audio = dev::audio_enabled;
|
||||
}
|
||||
|
||||
void Config::loadSafetyPreset() {
|
||||
loadDefaults();
|
||||
config_.control_frequency = SafetyPreset::CONTROL_FREQUENCY;
|
||||
config_.state_publish_frequency = SafetyPreset::STATE_PUBLISH_FREQUENCY;
|
||||
config_.max_linear_velocity = SafetyPreset::MAX_LINEAR_VELOCITY;
|
||||
config_.max_angular_velocity = SafetyPreset::MAX_ANGULAR_VELOCITY;
|
||||
config_.emergency_stop_timeout = SafetyPreset::EMERGENCY_STOP_TIMEOUT;
|
||||
config_.enable_video = SafetyPreset::ENABLE_VIDEO;
|
||||
config_.enable_audio = SafetyPreset::ENABLE_AUDIO;
|
||||
using safe = ConfigParams<ConfigPreset::Safety>;
|
||||
config_.control_frequency = safe::control_frequency;
|
||||
config_.state_publish_frequency = safe::state_publish_frequency;
|
||||
config_.max_linear_velocity = safe::max_linear_velocity;
|
||||
config_.max_angular_velocity = safe::max_angular_velocity;
|
||||
config_.emergency_stop_timeout = safe::emergency_stop_timeout;
|
||||
config_.enable_video = safe::video_enabled;
|
||||
config_.enable_audio = safe::audio_enabled;
|
||||
}
|
||||
|
||||
bool Config::loadConfig(const std::string& configFile) {
|
||||
// If compile-time config is enabled, skip JSON loading
|
||||
if (config::USE_COMPILE_TIME_CONFIG) {
|
||||
loadDefaults();
|
||||
return true;
|
||||
}
|
||||
// For now just load defaults, JSON loading can be added later if needed
|
||||
loadDefaults();
|
||||
|
||||
/* TODO: Add JSON loading support if needed
|
||||
try {
|
||||
std::ifstream file(configFile);
|
||||
if (!file.is_open()) {
|
||||
LOG_WARN("Config file not found: " + configFile + ", using defaults");
|
||||
setDefaults();
|
||||
loadDefaults();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -175,9 +175,12 @@ bool Config::loadConfig(const std::string& configFile) {
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
LOG_ERROR("Failed to load config: " + std::string(e.what()));
|
||||
setDefaults();
|
||||
loadDefaults();
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Config::saveConfig(const std::string& configFile) {
|
||||
@@ -253,64 +256,64 @@ bool Config::validateConfig() {
|
||||
// Validate frequencies
|
||||
if (config_.control_frequency <= 0 || config_.control_frequency > 1000) {
|
||||
LOG_WARN("Invalid control frequency, setting to default");
|
||||
config_.control_frequency = config::CONTROL_FREQUENCY;
|
||||
config_.control_frequency = CONTROL_FREQUENCY;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (config_.state_publish_frequency <= 0 || config_.state_publish_frequency > 500) {
|
||||
LOG_WARN("Invalid state publish frequency, setting to default");
|
||||
config_.state_publish_frequency = config::STATE_PUBLISH_FREQUENCY;
|
||||
config_.state_publish_frequency = STATE_PUBLISH_FREQUENCY;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
// Validate velocities
|
||||
if (config_.max_linear_velocity <= 0 || config_.max_linear_velocity > 5.0) {
|
||||
LOG_WARN("Invalid max linear velocity, setting to default");
|
||||
config_.max_linear_velocity = config::MAX_LINEAR_VELOCITY;
|
||||
config_.max_linear_velocity = MAX_LINEAR_VELOCITY;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (config_.max_angular_velocity <= 0 || config_.max_angular_velocity > 10.0) {
|
||||
LOG_WARN("Invalid max angular velocity, setting to default");
|
||||
config_.max_angular_velocity = config::MAX_ANGULAR_VELOCITY;
|
||||
config_.max_angular_velocity = MAX_ANGULAR_VELOCITY;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
// Validate timeout
|
||||
if (config_.emergency_stop_timeout <= 0 || config_.emergency_stop_timeout > 60.0) {
|
||||
LOG_WARN("Invalid emergency stop timeout, setting to default");
|
||||
config_.emergency_stop_timeout = config::EMERGENCY_STOP_TIMEOUT;
|
||||
config_.emergency_stop_timeout = EMERGENCY_STOP_TIMEOUT;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
// Validate video settings
|
||||
if (config_.video_width <= 0 || config_.video_height <= 0) {
|
||||
LOG_WARN("Invalid video dimensions, setting to default");
|
||||
config_.video_width = config::VIDEO_WIDTH;
|
||||
config_.video_height = config::VIDEO_HEIGHT;
|
||||
config_.video_width = VIDEO_WIDTH;
|
||||
config_.video_height = VIDEO_HEIGHT;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (config_.video_fps <= 0 || config_.video_fps > 120) {
|
||||
LOG_WARN("Invalid video FPS, setting to default");
|
||||
config_.video_fps = config::VIDEO_FPS;
|
||||
config_.video_fps = VIDEO_FPS;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
// Validate audio settings
|
||||
if (config_.audio_sample_rate <= 0) {
|
||||
LOG_WARN("Invalid audio sample rate, setting to default");
|
||||
config_.audio_sample_rate = config::AUDIO_SAMPLE_RATE;
|
||||
config_.audio_sample_rate = AUDIO_SAMPLE_RATE;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (config_.audio_channels <= 0) {
|
||||
LOG_WARN("Invalid audio channels, setting to default");
|
||||
config_.audio_channels = config::AUDIO_CHANNELS;
|
||||
config_.audio_channels = AUDIO_CHANNELS;
|
||||
valid = false;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
} // namespace custom
|
||||
} // namespace customConfig
|
||||
|
||||
Reference in New Issue
Block a user