feat: take the detection frame from robot_base_frame, drop prior_frame

The search fan, prior and mount checks are now expressed in the context's
robot_base_frame, like DockPatternActionHandler. A leftover prior_frame equal
to it loads with one warning; a different one fails init.
This commit is contained in:
2026-11-12 17:01:54 +07:00
parent 775c16820b
commit 641932b601
5 changed files with 115 additions and 44 deletions

View File

@@ -210,8 +210,9 @@ double yawError(double a, double b)
class Rig
{
public:
Rig()
explicit Rig(const std::string& base_frame = kBaseFrame)
{
ctx.robot_base_frame = base_frame;
robot_sensor_ports::SensorStoreConfig store_config;
for (const char* topic : { kFrontTopic, kBackTopic })
{
@@ -245,7 +246,7 @@ public:
const double cy = std::cos(yaw * 0.5), sy = std::sin(yaw * 0.5);
tf3::TransformStampedMsg t;
t.header.stamp = tf3::Time();
t.header.frame_id = kBaseFrame;
t.header.frame_id = ctx.robot_base_frame;
t.child_frame_id = child;
t.transform.translation.x = x;
t.transform.translation.z = z;
@@ -261,7 +262,7 @@ public:
tf3::TransformStampedMsg t;
t.header.stamp = toTf3Time(stamp_s);
t.header.frame_id = kGlobalFrame;
t.child_frame_id = kBaseFrame;
t.child_frame_id = ctx.robot_base_frame;
t.transform.translation.x = x;
t.transform.translation.y = y;
t.transform.rotation.z = std::sin(yaw * 0.5);
@@ -319,6 +320,60 @@ public:
// 1. Đường chạy đủ + heading theo entry_direction
// ================================================================================================
TEST(TrolleyDetectionAction, AbsentPriorFrameDetectsInContextBaseFrame)
{
Rig rig("custom_robot_base");
ASSERT_TRUE(rig.store_ok);
ASSERT_FALSE(rig.nh.hasParam("actions_trolley/detect_trolley/prior_frame"));
ASSERT_TRUE(rig.loaded);
ActionHandler* h = rig.registry.find("DetectTrolley");
ASSERT_NE(h, nullptr);
ASSERT_TRUE(h->start(makeAction("DetectTrolley", "tci_trolley_prior"), robot::Time(10.0)));
EXPECT_EQ(rig.feed(h, cartLegs(kCartInLaser, 0.0, M_PI), kFrontTopic, kFrontFrame, 10),
ActionStatus::kSucceeded) << rig.last_message;
EXPECT_NEAR(rig.goal().transform.translation.x, kLaserX + kCartInLaser, 0.01);
}
TEST(TrolleyDetectionAction, LegacyPriorFrameEqualToContextBaseLoads)
{
Rig rig("custom_robot_base");
const std::string root = "actions_trolley/detect_trolley";
YAML::Node current;
ASSERT_TRUE(rig.nh.getParam(root, current));
const YAML::Node original = YAML::Clone(current);
rig.nh.setParam(root + "/prior_frame", "custom_robot_base");
ActionRegistry registry;
registry.setContext(rig.ctx);
EXPECT_TRUE(registry.loadFromConfig(rig.nh, kNamespace));
EXPECT_NE(registry.find("DetectTrolley"), nullptr);
rig.nh.setParam(root, original);
}
TEST(TrolleyDetectionAction, LegacyPriorFrameDifferentFromContextBaseFails)
{
Rig rig;
const std::string root = "actions_trolley/detect_trolley";
YAML::Node current;
ASSERT_TRUE(rig.nh.getParam(root, current));
const YAML::Node original = YAML::Clone(current);
rig.nh.setParam(root + "/prior_frame", "other_frame");
ActionRegistry registry;
registry.setContext(rig.ctx);
EXPECT_FALSE(registry.loadFromConfig(rig.nh, kNamespace));
EXPECT_EQ(registry.find("DetectTrolley"), nullptr);
rig.nh.setParam(root, original);
}
TEST(TrolleyDetectionAction, EmptyContextBaseFrameFails)
{
Rig rig;
rig.ctx.robot_base_frame.clear();
ActionRegistry registry;
registry.setContext(rig.ctx);
EXPECT_FALSE(registry.loadFromConfig(rig.nh, kNamespace));
EXPECT_EQ(registry.find("DetectTrolley"), nullptr);
}
TEST(TrolleyDetectionAction, ForwardEntryGoalPointsIntoTheCart)
{
Rig rig;