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:
2026-11-04 08:52:00 +07:00
parent 47dd76f39e
commit 471d13410c
4 changed files with 68 additions and 15 deletions

View File

@@ -3,6 +3,7 @@
#include <cstddef>
#include <cstdint>
#include <limits>
#include <vector>
#include <robot_costmap_2d/direction_field.h>
@@ -34,8 +35,13 @@ public:
/** @brief A direction mask for one cell relative to the action source. */
struct CellMask { int64_t dx, dy; uint8_t mask; };
/** @brief Rebuild after each successful InitializeEnv; false means invalid primitive geometry. */
bool buildDirectionTable();
/** @brief Rebuild after InitializeEnv or a deviation change.
* @param max_deviation_rad Maximum inclusive deviation [rad], in (0, pi).
* @return False for invalid deviation or primitive geometry; the previous table is retained.
*/
bool buildDirectionTable(double max_deviation_rad);
/** @brief Deviation [rad] used for the current table, or NaN before a successful build. */
double tableMaxDeviationRad() const { return table_max_deviation_rad_; }
/** @brief Attach a snapshot owned by the caller, or detach with nullptr. */
void setDirectionField(const robot_costmap_2d::DirectionField* field) { field_ = field; }
/** @brief Reset per-plan rejection statistics. */
@@ -61,6 +67,7 @@ private:
uint64_t rejections_ = 0;
std::vector<CellMask> cells_;
std::vector<size_t> offsets_;
double table_max_deviation_rad_ = std::numeric_limits<double>::quiet_NaN();
};
} // namespace sbpl_lattice_planner
#endif