feat(low_controller): Integrate LowController for low-level command handling
- Added LowController class to manage low-level commands and communication. - Updated CustomRobot to initialize and manage LowController, including methods for processing low-level commands. - Enhanced logger functionality with variadic template methods for formatted logging. - Updated CMakeLists.txt to include the new low_controller.cpp source file and low_controller.hpp header.
This commit is contained in:
@@ -42,6 +42,11 @@ CustomRobot::~CustomRobot() {
|
||||
controller_->shutdown();
|
||||
controller_.reset();
|
||||
}
|
||||
|
||||
if (low_controller_) {
|
||||
low_controller_->shutdown();
|
||||
low_controller_.reset();
|
||||
}
|
||||
|
||||
if (rsc_) {
|
||||
rsc_.reset();
|
||||
@@ -66,6 +71,9 @@ bool CustomRobot::initialize() {
|
||||
controller_ = std::make_unique<Controller>();
|
||||
controller_->initialize();
|
||||
|
||||
low_controller_ = std::make_unique<LowController>();
|
||||
low_controller_->initialize();
|
||||
|
||||
navigation_ = std::make_unique<Navigation>();
|
||||
navigation_->Init();
|
||||
|
||||
@@ -115,6 +123,12 @@ bool CustomRobot::start() {
|
||||
LOG_ERROR("Failed to start robot controller");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!low_controller_->start()) {
|
||||
LOG_ERROR("Failed to start low-level controller");
|
||||
return false;
|
||||
}
|
||||
|
||||
running_ = true;
|
||||
LOG_INFO("CustomRobot started successfully");
|
||||
return true;
|
||||
@@ -266,6 +280,8 @@ void CustomRobot::processCmd(const nlohmann::json& message) {
|
||||
success = processNavCmd(cmd, message);
|
||||
} else if (type == "msc") {
|
||||
success = processMscCmd(cmd, message);
|
||||
} else if (type == "low") {
|
||||
success = processLowCmd(cmd, message);
|
||||
} else {
|
||||
LOG_ERROR("Unknown command type: " + type);
|
||||
return;
|
||||
@@ -277,6 +293,45 @@ void CustomRobot::processCmd(const nlohmann::json& message) {
|
||||
}
|
||||
}
|
||||
|
||||
bool CustomRobot::processLowCmd(const std::string& cmd, const nlohmann::json& message)
|
||||
{
|
||||
if (!low_controller_)
|
||||
{
|
||||
LOG_ERROR("LowController not initialized");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (cmd == "requestAutoCharge")
|
||||
{
|
||||
if (!message.contains("param") || !message["param"].contains("enable"))
|
||||
{
|
||||
LOG_ERROR("requestAutoCharge cmd missing 'enable' parameter");
|
||||
return false;
|
||||
}
|
||||
bool enable = message["param"]["enable"];
|
||||
low_controller_->requestAutoCharge(enable);
|
||||
return true;
|
||||
}
|
||||
else if (cmd == "powerOff")
|
||||
{
|
||||
low_controller_->powerOff();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Unknown Low command: " + cmd);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
LOG_ERROR("Error executing Low command " + cmd + ": " + std::string(e.what()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CustomRobot::processOacCmd(const std::string& cmd, const nlohmann::json& message) {
|
||||
if (!controller_) {
|
||||
LOG_ERROR("Controller not initialized");
|
||||
|
||||
Reference in New Issue
Block a user