temporary storage 7/9/2026 19:41
This commit is contained in:
@@ -152,7 +152,9 @@ void testLoadPlugins()
|
||||
|
||||
// 4. Chuyển quyền giữ library vào storage sống lâu dài.
|
||||
libraries_.push_back(std::move(library));
|
||||
behavior->initialize(plugin.name, nullptr, &global_path_, nullptr, nullptr);
|
||||
recovery_core::RecoveryContext ctx;
|
||||
ctx.global_path = &global_path_;
|
||||
behavior->configure(plugin.name, ctx);
|
||||
creators_.push_back(behavior);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
@@ -170,18 +172,28 @@ for(const auto& behavior : creators_)
|
||||
{
|
||||
if(behavior->getNameRecoveryBehavior() == "rotation_rc")
|
||||
{
|
||||
const recovery_core::RecoveryResult first = behavior->computeCommand(0.1);
|
||||
// Caller đặt góc quay RUNTIME = pi/2 (90 độ) cho lượt này.
|
||||
recovery_core::RecoveryGoal goal;
|
||||
goal.angle = 1.57079632679;
|
||||
|
||||
const recovery_core::RecoveryResult started = behavior->start(goal);
|
||||
expect(started.status == recovery_core::RecoveryStatus::kRunning,
|
||||
"rotate must be running right after start");
|
||||
|
||||
const recovery_core::RecoveryResult first = behavior->update(0.1);
|
||||
expect(first.status == recovery_core::RecoveryStatus::kRunning,
|
||||
"rotate first cycle must be running");
|
||||
expect(first.output_type == recovery_core::RecoveryOutputType::kVelocity,
|
||||
"rotate must return velocity output");
|
||||
expect(first.command.angular.z > 0.0, "rotate must command positive angular.z by default");
|
||||
expect(first.command.angular.z > 0.0, "rotate must command positive angular.z for +angle");
|
||||
expect(first.progress >= 0.0 && first.progress < 1.0,
|
||||
"rotate progress must advance within [0,1)");
|
||||
expect(first.remaining > 0.0, "rotate must report remaining angle while running");
|
||||
|
||||
recovery_core::RecoveryResult last = first;
|
||||
for (int i = 0; i < 100 && last.status == recovery_core::RecoveryStatus::kRunning; ++i)
|
||||
{
|
||||
last = behavior->computeCommand(0.1);
|
||||
last = behavior->update(0.1);
|
||||
}
|
||||
|
||||
expect(last.status == recovery_core::RecoveryStatus::kSucceeded,
|
||||
@@ -190,6 +202,39 @@ for(const auto& behavior : creators_)
|
||||
"rotate final result must still be a velocity output");
|
||||
expect(std::abs(last.command.angular.z) < 1e-9,
|
||||
"rotate must return a zero angular command when complete");
|
||||
expect(std::abs(last.progress - 1.0) < 1e-9, "rotate must report full progress on success");
|
||||
expect(last.remaining < 1e-9, "rotate must report zero remaining on success");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testBackupPlugin()
|
||||
{
|
||||
for(const auto& behavior : creators_)
|
||||
{
|
||||
if(behavior->getNameRecoveryBehavior() == "backward_rc")
|
||||
{
|
||||
// Caller đặt khoảng lùi RUNTIME = 0.3 m cho lượt này.
|
||||
recovery_core::RecoveryGoal goal;
|
||||
goal.distance = 0.3;
|
||||
|
||||
behavior->start(goal);
|
||||
const recovery_core::RecoveryResult first = behavior->update(0.1);
|
||||
expect(first.status == recovery_core::RecoveryStatus::kRunning,
|
||||
"backup first cycle must be running");
|
||||
expect(first.command.linear.x < 0.0, "backup must command negative linear.x");
|
||||
|
||||
recovery_core::RecoveryResult last = first;
|
||||
for (int i = 0; i < 1000 && last.status == recovery_core::RecoveryStatus::kRunning; ++i)
|
||||
{
|
||||
last = behavior->update(0.1);
|
||||
}
|
||||
|
||||
expect(last.status == recovery_core::RecoveryStatus::kSucceeded,
|
||||
"backup must finish within bounded cycles");
|
||||
expect(std::abs(last.command.linear.x) < 1e-9,
|
||||
"backup must return a zero command when complete");
|
||||
expect(std::abs(last.progress - 1.0) < 1e-9, "backup must report full progress on success");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -208,7 +253,8 @@ global_path_.push_back(pose2);
|
||||
{
|
||||
if(behavior->getNameRecoveryBehavior() == "regen_path_rc")
|
||||
{
|
||||
const recovery_core::RecoveryResult result = behavior->runBehavior();
|
||||
behavior->start(recovery_core::RecoveryGoal());
|
||||
const recovery_core::RecoveryResult result = behavior->update(0.1);
|
||||
|
||||
expect(result.status == recovery_core::RecoveryStatus::kSucceeded,
|
||||
"regen path must succeed with a non-empty global path");
|
||||
@@ -234,6 +280,7 @@ int main()
|
||||
|
||||
testRegenPathPlugin();
|
||||
testRotatePlugin();
|
||||
testBackupPlugin();
|
||||
|
||||
std::cout << "[PASS] recovery_core plugin loader contract" << std::endl;
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user