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:
@@ -20,7 +20,9 @@
|
||||
|
||||
#include <robot_costmap_2d/layered_costmap.h>
|
||||
|
||||
#include <move_base2/io/sensor_store_types.h>
|
||||
#include <move_base2/navigation_server.h>
|
||||
#include <robot_sensor_ports/sensor_reader.h>
|
||||
|
||||
#include "fake_ports.h"
|
||||
#include "spy_layer.h"
|
||||
@@ -159,6 +161,21 @@ public:
|
||||
ASSERT_TRUE(server_.configureSensors(config, error)) << error;
|
||||
}
|
||||
|
||||
/// @brief Khai một topic laser trong kho cảm biến thô.
|
||||
void configureSensorStore(const std::string& topic = "/b_scan", std::size_t capacity = 1)
|
||||
{
|
||||
robot_sensor_ports::SensorStoreConfig config;
|
||||
robot_sensor_ports::SensorEntryConfig entry;
|
||||
entry.topic = topic;
|
||||
entry.data_type = "robot_sensor_msgs/LaserScan";
|
||||
entry.capacity = capacity;
|
||||
entry.max_age = 0.5; // [s]
|
||||
config.sensors.push_back(entry);
|
||||
|
||||
std::string error;
|
||||
ASSERT_TRUE(server_.configureSensorStore(config, error)) << error;
|
||||
}
|
||||
|
||||
/// @brief Chạy @p cycles control cycle, mỗi cycle nhích đồng hồ giả một chu kỳ.
|
||||
void spin(std::size_t cycles)
|
||||
{
|
||||
@@ -377,6 +394,199 @@ TEST(NavigationServerSensors, StoringStillWorksWhenNoCostmapIsAttachedYet)
|
||||
EXPECT_EQ(fixture.server_.sensors().stats().delivered, 0U);
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// Đường dữ liệu cảm biến THÔ từ host vào kho dùng chung
|
||||
//
|
||||
// Kho là đường thứ hai, song song với costmap: bộ dò dock và local planner học tăng cường cần đúng
|
||||
// mảng `ranges` theo thứ tự tia, thứ mà costmap ở 0.05 m đã inflate và xoá mất.
|
||||
// ================================================================================================
|
||||
|
||||
TEST(NavigationServerSensorStore, ADeclaredTopicReachesTheStore)
|
||||
{
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
fixture.configureSensorStore();
|
||||
|
||||
fixture.server_.addLaserScan("/b_scan", makeScan(40, 1.0F));
|
||||
|
||||
uint64_t cursor = 0;
|
||||
auto scan = robot_sensor_ports::latest<robot_sensor_msgs::LaserScan>(fixture.server_.sensorStore(),
|
||||
"/b_scan", cursor);
|
||||
ASSERT_TRUE(scan);
|
||||
EXPECT_EQ(scan->ranges.size(), 40U);
|
||||
EXPECT_FLOAT_EQ(scan->ranges[0], 1.0F);
|
||||
|
||||
// Cursor đã nhích: lần đọc kế tiếp phải nói "chưa có gì mới", không đưa lại đúng scan đó.
|
||||
EXPECT_FALSE(robot_sensor_ports::latest<robot_sensor_msgs::LaserScan>(fixture.server_.sensorStore(),
|
||||
"/b_scan", cursor));
|
||||
}
|
||||
|
||||
TEST(NavigationServerSensorStore, TheStoreGetsTheRawScanWhileTheCostmapGetsTheFilteredOne)
|
||||
{
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
|
||||
// SOR bật: bản vào costmap có outlier bị đặt NaN, bản vào kho thì không.
|
||||
SensorGatewayConfig sensors;
|
||||
sensors.laser_sor_enabled = true;
|
||||
sensors.laser_sor_mean_k = 4;
|
||||
sensors.laser_sor_stddev_mul = 0.5;
|
||||
fixture.configureSensors(sensors);
|
||||
fixture.configureSensorStore();
|
||||
|
||||
// Một tia lạc hẳn ra giữa một bức tường phẳng — đúng thứ SOR sinh ra để loại.
|
||||
robot_sensor_msgs::LaserScan scan = makeScan(40, 1.0F);
|
||||
scan.ranges[20] = 8.0F;
|
||||
fixture.server_.addLaserScan("/b_scan", scan);
|
||||
|
||||
uint64_t cursor = 0;
|
||||
auto stored = robot_sensor_ports::latest<robot_sensor_msgs::LaserScan>(
|
||||
fixture.server_.sensorStore(), "/b_scan", cursor);
|
||||
ASSERT_TRUE(stored);
|
||||
|
||||
// Kho giữ đúng thứ laser đã thấy. Đây là điều kiện sống của bộ dò hình dạng: fit đường thẳng trên
|
||||
// dữ liệu đã bị lọc là fit trên một hình khác.
|
||||
EXPECT_FLOAT_EQ(stored->ranges[20], 8.0F);
|
||||
|
||||
// Còn bản costmap nhìn thấy thì đã bị lọc. Hai bản khác nhau là CÓ CHỦ ĐÍCH.
|
||||
const robot_sensor_msgs::LaserScan filtered = fixture.server_.getLaserScan("/b_scan");
|
||||
ASSERT_EQ(filtered.ranges.size(), 40U);
|
||||
EXPECT_TRUE(std::isnan(filtered.ranges[20]))
|
||||
<< "SOR phải loại tia lạc; nếu không, test này không còn phân biệt được hai đường";
|
||||
}
|
||||
|
||||
TEST(NavigationServerSensorStore, AnUndeclaredTopicIsDroppedInsteadOfGrowingTheStore)
|
||||
{
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
fixture.configureSensorStore("/b_scan");
|
||||
|
||||
fixture.server_.addLaserScan("/f_scan", makeScan());
|
||||
|
||||
// Không tự thêm slot: một depth cloud không ai khai sẽ ngốn hàng MB mỗi frame.
|
||||
EXPECT_FALSE(robot_sensor_ports::has<robot_sensor_msgs::LaserScan>(fixture.server_.sensorStore(),
|
||||
"/f_scan"));
|
||||
// Nhưng đường cũ vẫn nhận, không đổi hành vi host đang có.
|
||||
EXPECT_EQ(fixture.server_.getLaserScan("/f_scan").ranges.size(), 40U);
|
||||
}
|
||||
|
||||
TEST(NavigationServerSensorStore, RemovingATopicMakesTheStoreForgetItToo)
|
||||
{
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
fixture.configureSensorStore();
|
||||
|
||||
fixture.server_.addLaserScan("/b_scan", makeScan());
|
||||
ASSERT_TRUE(fixture.server_.removeLaserScan("/b_scan"));
|
||||
|
||||
// Host đã bỏ dữ liệu đó; kho còn phát bản cũ là hai nguồn nói hai chuyện khác nhau về thứ robot
|
||||
// đang nhìn thấy.
|
||||
uint64_t cursor = 0;
|
||||
EXPECT_FALSE(robot_sensor_ports::latest<robot_sensor_msgs::LaserScan>(fixture.server_.sensorStore(),
|
||||
"/b_scan", cursor));
|
||||
|
||||
// Khai báo thì vẫn còn — bỏ dữ liệu không phải bỏ cấu hình.
|
||||
EXPECT_TRUE(robot_sensor_ports::has<robot_sensor_msgs::LaserScan>(fixture.server_.sensorStore(),
|
||||
"/b_scan"));
|
||||
}
|
||||
|
||||
TEST(NavigationServerSensorStore, RemoveAllLaserScansClearsEveryLaserTopic)
|
||||
{
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
fixture.configureSensorStore();
|
||||
|
||||
fixture.server_.addLaserScan("/b_scan", makeScan());
|
||||
ASSERT_TRUE(fixture.server_.removeAllLaserScans());
|
||||
|
||||
uint64_t cursor = 0;
|
||||
EXPECT_FALSE(robot_sensor_ports::latest<robot_sensor_msgs::LaserScan>(fixture.server_.sensorStore(),
|
||||
"/b_scan", cursor));
|
||||
}
|
||||
|
||||
TEST(NavigationServerSensorStore, KeepsAFrameStackWhenCapacityAllowsIt)
|
||||
{
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
fixture.configureSensorStore("/b_scan", 3);
|
||||
|
||||
for (int i = 1; i <= 4; ++i)
|
||||
{
|
||||
fixture.server_.addLaserScan("/b_scan", makeScan(40, static_cast<float>(i)));
|
||||
}
|
||||
|
||||
const auto frames = robot_sensor_ports::history<robot_sensor_msgs::LaserScan>(
|
||||
fixture.server_.sensorStore(), "/b_scan", 3);
|
||||
ASSERT_EQ(frames.size(), 3U);
|
||||
// Cũ trước, mới sau.
|
||||
EXPECT_FLOAT_EQ(frames[0]->ranges[0], 2.0F);
|
||||
EXPECT_FLOAT_EQ(frames[2]->ranges[0], 4.0F);
|
||||
}
|
||||
|
||||
TEST(NavigationServerSensorStore, TheReportIsOffUntilAskedFor)
|
||||
{
|
||||
// Mặc định tắt: đây là công cụ chẩn đoán, không phải thứ in trên robot sản xuất. Chỉ kiểm là
|
||||
// spinOnce() không nổ khi chưa bật và khi chưa có đồng hồ.
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
fixture.configureSensorStore();
|
||||
|
||||
fixture.server_.addLaserScan("/b_scan", makeScan());
|
||||
fixture.spin(3);
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST(NavigationServerSensorStore, TheReportSurvivesATopicThatNeverReceivedAnything)
|
||||
{
|
||||
// Ca đáng nói nhất khi chưa có consumer nào: gõ sai `topic` và cảm biến chết cho CÙNG một triệu
|
||||
// chứng. Báo cáo phải chạy được qua topic rỗng thay vì bỏ qua vì "không có gì để in".
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
fixture.configureSensorStore();
|
||||
fixture.server_.setSensorStoreReportPeriod(0.01); // [s]
|
||||
|
||||
fixture.spin(5);
|
||||
|
||||
robot_sensor_ports::SensorInfo info;
|
||||
ASSERT_TRUE(fixture.server_.sensorStore().describe("/b_scan", info));
|
||||
EXPECT_EQ(info.sequence, 0U);
|
||||
}
|
||||
|
||||
TEST(NavigationServerSensorStore, TheReportMeasuresRateAndAgeOfWhatArrived)
|
||||
{
|
||||
Fixture fixture;
|
||||
fixture.configure();
|
||||
fixture.configureSensorStore();
|
||||
fixture.server_.setSensorStoreReportPeriod(0.01); // [s]
|
||||
|
||||
// 10 Hz theo stamp, độc lập với đồng hồ control loop.
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
robot_sensor_msgs::LaserScan scan = makeScan();
|
||||
scan.header.stamp = robot::Time(100.0 + 0.1 * i);
|
||||
fixture.server_.addLaserScan("/b_scan", scan);
|
||||
}
|
||||
fixture.spin(3);
|
||||
|
||||
robot_sensor_ports::SensorInfo info;
|
||||
ASSERT_TRUE(fixture.server_.sensorStore().describe("/b_scan", info));
|
||||
EXPECT_EQ(info.sequence, 6U);
|
||||
EXPECT_NEAR(info.rate_hz, 10.0, 1.0);
|
||||
EXPECT_DOUBLE_EQ(info.stamp.toSec(), 100.5);
|
||||
}
|
||||
|
||||
TEST(NavigationServerSensorStore, RegisteringTheRuntimeOwnTypeMakesItNameableInYaml)
|
||||
{
|
||||
// OccupancyGrid thuộc robot_nav_msgs, không nằm trong danh sách sẵn có của robot_sensor_ports.
|
||||
// Đây chính là đường mở rộng: một dòng REGISTER_TYPE + một lời gọi add(), không đổi interface.
|
||||
move_base2::registerSensorStoreTypes();
|
||||
|
||||
std::string full;
|
||||
std::string error;
|
||||
ASSERT_TRUE(robot_sensor_ports::TypeNames::resolve("OccupancyGrid", full, error)) << error;
|
||||
EXPECT_EQ(full, "robot_nav_msgs/OccupancyGrid");
|
||||
}
|
||||
|
||||
TEST(NavigationServerSensors, StaticMapReceivedBeforeAttachIsReplayed)
|
||||
{
|
||||
// Không có phần phát lại này thì thứ tự "map tới trước, costmap dựng sau" — thứ tự thường gặp
|
||||
|
||||
Reference in New Issue
Block a user