temporary storage
This commit is contained in:
19
src/recovery_behavior.cpp
Normal file
19
src/recovery_behavior.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
/*********************************************************************
|
||||
* recovery_core — default impl cho RecoveryBehavior.
|
||||
*
|
||||
* Chỉ chứa default computeCommand() (họ A/B không override). initialize()/runBehavior()/
|
||||
* status() là thuần ảo, do plugin cụ thể triển khai.
|
||||
*
|
||||
* Author: DuongTD
|
||||
*********************************************************************/
|
||||
#include <recovery_core/recovery_behavior.h>
|
||||
|
||||
namespace recovery_core
|
||||
{
|
||||
|
||||
RecoveryResult RecoveryBehavior::computeCommand(double /*dt*/)
|
||||
{
|
||||
return RecoveryResult::Failed();
|
||||
}
|
||||
|
||||
} // namespace recovery_core
|
||||
102
src/recovery_config.cpp
Normal file
102
src/recovery_config.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/*********************************************************************
|
||||
* recovery_core — validate + đọc RecoveryConfig.
|
||||
*
|
||||
* Author: DuongTD
|
||||
*********************************************************************/
|
||||
#include <recovery_core/recovery_config.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#include <robot/robot.h>
|
||||
|
||||
namespace recovery_core
|
||||
{
|
||||
namespace
|
||||
{
|
||||
|
||||
constexpr double kDefaultControlFrequency = 20.0;
|
||||
constexpr double kDefaultTimeout = 0.0;
|
||||
|
||||
void appendError(std::string* error, const std::string& message)
|
||||
{
|
||||
if (error == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!error->empty())
|
||||
{
|
||||
*error += "; ";
|
||||
}
|
||||
*error += message;
|
||||
}
|
||||
|
||||
bool invalidControlFrequency(double value)
|
||||
{
|
||||
return !std::isfinite(value) || value <= 0.0;
|
||||
}
|
||||
|
||||
bool invalidTimeout(double value)
|
||||
{
|
||||
return !std::isfinite(value) || value < 0.0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool RecoveryConfig::validate(std::string* error) const
|
||||
{
|
||||
if (error != nullptr)
|
||||
{
|
||||
error->clear();
|
||||
}
|
||||
|
||||
bool valid = true;
|
||||
if (invalidControlFrequency(control_frequency))
|
||||
{
|
||||
appendError(error, "control_frequency must be finite and > 0 Hz");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (invalidTimeout(timeout))
|
||||
{
|
||||
appendError(error, "timeout must be finite and >= 0 s");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
RecoveryConfig RecoveryConfig::fromNodeHandle(robot::NodeHandle& nh)
|
||||
{
|
||||
RecoveryConfig config;
|
||||
nh.param("control_frequency", config.control_frequency, kDefaultControlFrequency);
|
||||
nh.param("timeout", config.timeout, kDefaultTimeout);
|
||||
|
||||
std::string error;
|
||||
if (config.validate(&error))
|
||||
{
|
||||
return config;
|
||||
}
|
||||
|
||||
robot::log_warning("[recovery_core] Invalid common recovery config: %s. "
|
||||
"Replacing invalid values with defaults.",
|
||||
error.c_str());
|
||||
|
||||
if (invalidControlFrequency(config.control_frequency))
|
||||
{
|
||||
config.control_frequency = kDefaultControlFrequency;
|
||||
}
|
||||
if (invalidTimeout(config.timeout))
|
||||
{
|
||||
config.timeout = kDefaultTimeout;
|
||||
}
|
||||
|
||||
if (!config.validate(nullptr))
|
||||
{
|
||||
return RecoveryConfig{};
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
} // namespace recovery_core
|
||||
55
src/recovery_types.cpp
Normal file
55
src/recovery_types.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*********************************************************************
|
||||
* recovery_core — factory cho RecoveryResult.
|
||||
*
|
||||
* Author: DuongTD
|
||||
*********************************************************************/
|
||||
#include <recovery_core/recovery_types.h>
|
||||
|
||||
namespace recovery_core
|
||||
{
|
||||
|
||||
RecoveryResult RecoveryResult::Running()
|
||||
{
|
||||
RecoveryResult result;
|
||||
result.status = RecoveryStatus::kRunning;
|
||||
result.output_type = RecoveryOutputType::kNone;
|
||||
return result;
|
||||
}
|
||||
|
||||
RecoveryResult RecoveryResult::Succeeded()
|
||||
{
|
||||
RecoveryResult result;
|
||||
result.status = RecoveryStatus::kSucceeded;
|
||||
result.output_type = RecoveryOutputType::kNone;
|
||||
return result;
|
||||
}
|
||||
|
||||
RecoveryResult RecoveryResult::Failed()
|
||||
{
|
||||
RecoveryResult result;
|
||||
result.status = RecoveryStatus::kFailed;
|
||||
result.output_type = RecoveryOutputType::kNone;
|
||||
return result;
|
||||
}
|
||||
|
||||
RecoveryResult RecoveryResult::Velocity(const robot_geometry_msgs::Twist& command,
|
||||
RecoveryStatus status)
|
||||
{
|
||||
RecoveryResult result;
|
||||
result.status = status;
|
||||
result.output_type = RecoveryOutputType::kVelocity;
|
||||
result.command = command;
|
||||
return result;
|
||||
}
|
||||
|
||||
RecoveryResult RecoveryResult::PathOut(const robot_nav_msgs::Path& path,
|
||||
RecoveryStatus status)
|
||||
{
|
||||
RecoveryResult result;
|
||||
result.status = status;
|
||||
result.output_type = RecoveryOutputType::kPath;
|
||||
result.path = path;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace recovery_core
|
||||
Reference in New Issue
Block a user