Keep raw sensor readings so plugins can reach what the costmap threw away

Sensor data entered this runtime and disappeared into the costmap. At 0.05 m
with inflation the costmap has destroyed ray order and object shape, so a dock
detector fitting lines to find a V plate cannot reconstruct what the laser
saw - two 0.2 m wings on that grid are one blob. A reinforcement-learning
local planner wants the raw scan for the same reason. Neither had a route:
ActionContext held only TF, and LocalPlanner::initialize takes only a costmap.

NavigationServer now owns a SensorStore and feeds it from all five doors,
handing a read-only port to the action registry and to the controller runner.

The store gets the reading BEFORE the filter. Anything that wants filtering
filters upstream; the store does not know a filter exists. With laser SOR on,
the store and the costmap deliberately see different data - one wants outliers
gone, the other wants the true shape - and the comment at addLaserScan now
says so, because the one it replaces claimed the opposite.

remove* mirrors into the store, dropping readings while keeping the topic
declared. A host that has disowned data while the store still serves it means
the two disagree about what the robot can currently see, and max_age only
covers the tail of that.

Reaching a local planner without breaking every other one: widening
LocalPlanner::initialize would break hybrid, mppi, priest, stanley and
deep_mpc at once for the sake of one planner. A planner that wants sensor data
inherits SensorConsumer instead, and ControllerRunner finds out with a
dynamic_cast after loading it, at all three sites that build an instance and
always before initialize(). Planners that do not inherit it cast to null and
nothing happens, so nothing needs rebuilding. That cast crosses a .so boundary
and depends on matching RTTI, which a green build does not prove - hence the
log line, and hence TestControllerSensorProbe, dlopen'd like a real plugin, to
check it actually matches.

sensor_store/report_period prints what the store holds every N seconds, off by
default. Until a consumer exists it is the only way to see whether data
arrives at all, and it is what separates a mistyped topic from a dead sensor -
without it the two look identical. It reads age from the control loop's clock,
not robot::Time::now(), which is the wall clock while a simulated scan is not.

Config is refused at boot, not at first use: an unknown data_type, a short name
two packages share, a duplicate topic, a capacity below 1, a max_age that is
not positive. Declaring no sensor at all is valid and leaves the store empty
and silent - a runtime with no consumer of raw data holds nothing, which is an
answer rather than a reason to refuse to start.

robot_nav_msgs/OccupancyGrid is registered here rather than in
robot_sensor_ports, which ships only its own package's types; pulling
robot_nav_msgs into every translation unit that touches the store would be the
cost of doing otherwise.
This commit is contained in:
2026-08-26 11:35:17 +07:00
parent ea02392c69
commit b102391fb8
18 changed files with 975 additions and 2 deletions

View File

@@ -34,6 +34,10 @@
#include <robot_nav_2d_utils/conversions.h>
#include <robot_nav_core2/local_planner.h>
#include <robot_sensor_msgs/LaserScan.h>
#include <robot_sensor_ports/sensor_consumer.h>
#include <robot_sensor_ports/sensor_reader.h>
#include <robot_sensor_ports/sensor_types.h>
namespace move_base2
{
@@ -212,6 +216,85 @@ private:
bool has_limit_angular_ = false;
};
/**
* @class SensorProbeLocalPlanner
* @brief Planner giả có kế thừa `robot_sensor_ports::SensorConsumer`.
*
* Lý do tồn tại: `ControllerRunner` phát kho cảm biến bằng `dynamic_cast` qua ranh giới `.so`, mà
* cast đó chỉ đúng khi RTTI của hai bên khớp — build xanh KHÔNG chứng minh điều đó. Probe này là
* cách duy nhất kiểm được: nó bị `dlopen` như plugin thật, rồi báo ngược kết quả qua lệnh vận tốc.
*
* velocity.x = số lần đọc được scan mới
* velocity.theta = 1.0 nếu đã nhận cổng đọc khác null, 0.0 nếu chưa
*/
class SensorProbeLocalPlanner : public robot_nav_core2::LocalPlanner,
public robot_sensor_ports::SensorConsumer
{
public:
void setSensorReader(const robot_sensor_ports::SensorReader* reader) override
{
sensors_ = reader;
}
void initialize(robot::NodeHandle& /*parent*/, const std::string& /*name*/,
std::shared_ptr<tf3::BufferCore> /*tf*/,
robot_costmap_2d::Costmap2DROBOT* /*costmap*/) override
{
// Cổng phải có mặt TỪ initialize: planner có quyền dùng nó ngay khi tự cấu hình.
reader_at_init_ = sensors_;
}
void setGoalPose(const robot_nav_2d_msgs::Pose2DStamped& /*goal_pose*/) override
{
}
void setPlan(const robot_nav_2d_msgs::Path2D& /*path*/) override
{
}
void getPlan(robot_nav_2d_msgs::Path2D& path) override
{
path = robot_nav_2d_msgs::Path2D();
}
void getGlobalPlan(robot_nav_2d_msgs::Path2D& path) override
{
path = robot_nav_2d_msgs::Path2D();
}
robot_nav_2d_msgs::Twist2DStamped computeVelocityCommands(
const robot_nav_2d_msgs::Pose2DStamped& /*pose*/,
const robot_nav_2d_msgs::Twist2D& /*velocity*/) override
{
if (sensors_ != nullptr)
{
auto scan = robot_sensor_ports::latest<robot_sensor_msgs::LaserScan>(*sensors_, "/probe_scan",
cursor_);
if (scan)
{
++scans_read_;
}
}
robot_nav_2d_msgs::Twist2DStamped cmd;
cmd.velocity.x = static_cast<double>(scans_read_);
cmd.velocity.theta = reader_at_init_ != nullptr ? 1.0 : 0.0;
return cmd;
}
bool isGoalReached(const robot_nav_2d_msgs::Pose2DStamped& /*pose*/,
const robot_nav_2d_msgs::Twist2D& /*velocity*/) override
{
return false;
}
private:
const robot_sensor_ports::SensorReader* sensors_ = nullptr;
const robot_sensor_ports::SensorReader* reader_at_init_ = nullptr;
uint64_t cursor_ = 0;
unsigned int scans_read_ = 0;
};
robot_nav_core2::LocalPlanner::Ptr createOk()
{
return std::make_shared<TestLocalPlanner>(TestLocalPlanner::Behavior::kOk);
@@ -252,6 +335,11 @@ robot_nav_core2::LocalPlanner::Ptr createFootprintProbe()
return std::make_shared<TestLocalPlanner>(TestLocalPlanner::Behavior::kFootprintProbe);
}
robot_nav_core2::LocalPlanner::Ptr createSensorProbe()
{
return std::make_shared<SensorProbeLocalPlanner>();
}
} // namespace testing
} // namespace move_base2
@@ -263,3 +351,4 @@ BOOST_DLL_ALIAS(move_base2::testing::createThrowing, TestControllerThrowing)
BOOST_DLL_ALIAS(move_base2::testing::createRefusingLimits, TestControllerRefusesLimits)
BOOST_DLL_ALIAS(move_base2::testing::createMarkerProbe, TestControllerMarkerProbe)
BOOST_DLL_ALIAS(move_base2::testing::createFootprintProbe, TestControllerFootprintProbe)
BOOST_DLL_ALIAS(move_base2::testing::createSensorProbe, TestControllerSensorProbe)