feat(sbpl): rebuild the direction table when the field deviation changes
The per-action mask table records the deviation it was built with. When a ready field carries another value, rebuild before attaching it and plan from scratch; on failure keep the old table, detach the field and refuse to plan.
This commit is contained in:
@@ -32,7 +32,7 @@ robot_nav_msgs::OccupancyGrid grid()
|
||||
return g;
|
||||
}
|
||||
std::shared_ptr<const DirectionField> makeField(const robot_nav_msgs::OccupancyGrid& g)
|
||||
{ return DirectionField::create(g, geometry()); }
|
||||
{ return DirectionField::create(g, geometry(), M_PI / 2.0); }
|
||||
|
||||
class DirectionEnvironmentTest : public ::testing::Test
|
||||
{
|
||||
@@ -43,7 +43,7 @@ protected:
|
||||
std::vector<sbpl_2Dpt_t> footprint;
|
||||
ASSERT_TRUE(env.InitializeEnv(kWidth, kHeight, nullptr, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
footprint, kResolution, 1.0, 1.0, 254, DIRECTION_TEST_MPRIM));
|
||||
ASSERT_TRUE(env.buildDirectionTable());
|
||||
ASSERT_TRUE(env.buildDirectionTable(M_PI / 2.0));
|
||||
}
|
||||
EnvNAVXYTHETALATAction_t* action(int theta, int dx, int dy, bool rotation = false)
|
||||
{
|
||||
@@ -67,7 +67,7 @@ TEST_F(DirectionEnvironmentTest, TableMatchesDirectTraversalAtMultipleSources)
|
||||
for (size_t i = 1; i < p.size(); ++i) {
|
||||
const double dx = p[i].x - p[i-1].x, dy = p[i].y - p[i-1].y;
|
||||
if (dx == 0 && dy == 0) continue;
|
||||
const uint8_t mask = robot_costmap_2d::allowedDirectionMask(dx, dy);
|
||||
const uint8_t mask = robot_costmap_2d::allowedDirectionMask(dx, dy, M_PI / 2.0);
|
||||
ASSERT_TRUE(robot_costmap_2d::traverseGridSegment(source.first + 0.5 + p[i-1].x/kResolution,
|
||||
source.second + 0.5 + p[i-1].y/kResolution, source.first + 0.5 + p[i].x/kResolution,
|
||||
source.second + 0.5 + p[i].y/kResolution, [&](int64_t x, int64_t y) {
|
||||
@@ -115,12 +115,33 @@ TEST_F(DirectionEnvironmentTest, ActionCostsRespectDisplacementAndObstacles)
|
||||
// A narrower field makes a base-valid action leave the direction grid.
|
||||
auto small_g = grid(); small_g.info.width = 21; small_g.data.assign(21*kHeight, 0);
|
||||
auto small_geo = geometry(); small_geo.width = 21;
|
||||
auto small = DirectionField::create(small_g, small_geo); ASSERT_TRUE(small);
|
||||
auto small = DirectionField::create(small_g, small_geo, M_PI / 2.0); ASSERT_TRUE(small);
|
||||
env.setDirectionField(small.get());
|
||||
EXPECT_GE(env.GetActionCost(20, 15, 0, forward), INFINITECOST);
|
||||
env.setDirectionField(nullptr);
|
||||
}
|
||||
|
||||
TEST_F(DirectionEnvironmentTest, RebuildChangesPerpendicularActionCost)
|
||||
{
|
||||
auto* forward = action(0, 1, 0);
|
||||
ASSERT_TRUE(forward);
|
||||
auto g = grid();
|
||||
std::fill(g.data.begin(), g.data.end(), 3); // +Y zone.
|
||||
const auto wide = makeField(g);
|
||||
const auto narrow = DirectionField::create(g, geometry(), M_PI / 4.0);
|
||||
ASSERT_TRUE(wide && narrow);
|
||||
env.setDirectionField(wide.get());
|
||||
EXPECT_LT(env.GetActionCost(20, 15, 0, forward), INFINITECOST);
|
||||
ASSERT_TRUE(env.buildDirectionTable(narrow->maxDeviationRad()));
|
||||
EXPECT_DOUBLE_EQ(env.tableMaxDeviationRad(), M_PI / 4.0);
|
||||
env.setDirectionField(narrow.get());
|
||||
EXPECT_GE(env.GetActionCost(20, 15, 0, forward), INFINITECOST);
|
||||
EXPECT_FALSE(env.buildDirectionTable(0));
|
||||
EXPECT_DOUBLE_EQ(env.tableMaxDeviationRad(), M_PI / 4.0);
|
||||
EXPECT_GE(env.GetActionCost(20, 15, 0, forward), INFINITECOST);
|
||||
env.setDirectionField(nullptr);
|
||||
}
|
||||
|
||||
TEST(DirectionDecisionTest, StatesGeometryAndGeneration)
|
||||
{
|
||||
using sbpl_lattice_planner::decideDirection;
|
||||
|
||||
Reference in New Issue
Block a user