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:
@@ -68,6 +68,7 @@ void readBinding(robot::NodeHandle& nh, const std::string& ns, ProfileBinding& b
|
||||
}
|
||||
|
||||
void readSensors(robot::NodeHandle& nh, SensorGatewayConfig& sensors);
|
||||
void readSensorStore(robot::NodeHandle& nh, MoveBase2Config& config);
|
||||
|
||||
/// Đọc cặp planner runtime trực tiếp, không có adapter gen-1 ở giữa.
|
||||
void readRootProfileBinding(robot::NodeHandle& nh, const std::string& ns, ProfileBinding& binding)
|
||||
@@ -232,6 +233,7 @@ void readMoveBase2Fields(robot::NodeHandle& nh, MoveBase2Config& config)
|
||||
readDouble(nh, "acc_lim_theta", config.velocity.max_accel_theta);
|
||||
|
||||
readSensors(nh, config.sensors);
|
||||
readSensorStore(nh, config);
|
||||
readPathMonitor(nh, config.path_monitor);
|
||||
readBool(nh, "docking_requires_marker", config.docking_requires_marker);
|
||||
|
||||
@@ -257,6 +259,24 @@ bool validateBinding(const ProfileBinding& binding, const char* name, std::strin
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Đọc khai báo kho cảm biến thô từ namespace con `sensor_store`.
|
||||
///
|
||||
/// Lỗi được CẤT chứ không ném: `fromNodeHandle` là void và được gọi trên nhiều schema khác nhau,
|
||||
/// nên chỗ duy nhất chặn boot được là `validate()`. Cùng khuôn với `docking_marker_profiles_error`.
|
||||
void readSensorStore(robot::NodeHandle& nh, MoveBase2Config& config)
|
||||
{
|
||||
config.sensor_store_error.clear();
|
||||
|
||||
if (!robot_sensor_ports::SensorStoreConfig::load(nh, "sensor_store", config.sensor_store,
|
||||
config.sensor_store_error))
|
||||
{
|
||||
config.sensor_store.sensors.clear();
|
||||
}
|
||||
|
||||
robot::NodeHandle store_nh(nh, "sensor_store");
|
||||
readDouble(store_nh, "report_period", config.sensor_store_report_period);
|
||||
}
|
||||
|
||||
/// Đọc cấu hình đường vào cảm biến từ namespace con `sensors`.
|
||||
void readSensors(robot::NodeHandle& nh, SensorGatewayConfig& sensors)
|
||||
{
|
||||
@@ -428,6 +448,20 @@ bool MoveBase2Config::validate(std::string& error) const
|
||||
return false;
|
||||
}
|
||||
|
||||
// Khai kho sai thì chặn boot, không im lặng chạy với kho rỗng: consumer nào cần dữ liệu thô sẽ
|
||||
// chờ mãi không có gì, và triệu chứng giống hệt cảm biến chết.
|
||||
if (!sensor_store_error.empty())
|
||||
{
|
||||
error = "sensor_store: " + sensor_store_error;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!std::isfinite(sensor_store_report_period) || sensor_store_report_period < 0.0)
|
||||
{
|
||||
error = "sensor_store/report_period must be a finite value >= 0 (0 = off)";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sau cùng: struct con. Thứ tự này có chủ đích — báo lỗi ở tầng cụ thể nhất trước, để thông báo
|
||||
// nói đúng khoá YAML mà người vận hành cần sửa, chứ không phải một ràng buộc phái sinh.
|
||||
//
|
||||
@@ -472,6 +506,14 @@ std::string MoveBase2Config::describe() const
|
||||
out << state_machine.describe();
|
||||
out << velocity.describe();
|
||||
out << sensors.describe();
|
||||
out << " sensor_store: " << sensor_store.sensors.size() << " topic(s)"
|
||||
<< (sensor_store.sensors.empty() ? " (off)" : "") << ", report_period: "
|
||||
<< sensor_store_report_period << " s" << (sensor_store_report_period > 0.0 ? "\n" : " (off)\n");
|
||||
for (const robot_sensor_ports::SensorEntryConfig& entry : sensor_store.sensors)
|
||||
{
|
||||
out << " '" << entry.topic << "' " << entry.data_type << " capacity=" << entry.capacity
|
||||
<< " max_age=" << entry.max_age << " s\n";
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
||||
21
src/io/sensor_store_types.cpp
Normal file
21
src/io/sensor_store_types.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/*********************************************************************
|
||||
*
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* move_base2 — registering this runtime's extra store types.
|
||||
*
|
||||
* Author: DuongTD
|
||||
*********************************************************************/
|
||||
#include <move_base2/io/sensor_store_types.h>
|
||||
|
||||
namespace move_base2
|
||||
{
|
||||
|
||||
void registerSensorStoreTypes()
|
||||
{
|
||||
// The 22 types of robot_sensor_msgs seed themselves inside robot_sensor_ports. Only what this
|
||||
// package adds belongs here.
|
||||
robot_sensor_ports::TypeNames::add("robot_nav_msgs/OccupancyGrid");
|
||||
}
|
||||
|
||||
} // namespace move_base2
|
||||
@@ -8,6 +8,8 @@
|
||||
*********************************************************************/
|
||||
#include <move_base2/navigation_runtime.h>
|
||||
|
||||
#include <move_base2/io/sensor_store_types.h>
|
||||
|
||||
#include <exception>
|
||||
|
||||
#include <boost/thread/locks.hpp>
|
||||
@@ -114,6 +116,11 @@ bool NavigationRuntime::buildCostmaps(const std::shared_ptr<tf3::BufferCore>& tf
|
||||
tf_ = tf;
|
||||
|
||||
// --- 1. Config ---------------------------------------------------------------------------------
|
||||
//
|
||||
// Đăng ký kiểu message riêng của gói này TRƯỚC khi đọc config: `data_type: OccupancyGrid` trong
|
||||
// khối `sensor_store` sẽ bị từ chối là "unknown" nếu bảng tên chưa có nó.
|
||||
registerSensorStoreTypes();
|
||||
|
||||
robot::NodeHandle root_nh("~");
|
||||
config_ = MoveBase2Config::load(root_nh);
|
||||
|
||||
@@ -204,6 +211,10 @@ bool NavigationRuntime::buildRunners(std::string& error)
|
||||
planner_.attachStats(stats_.get());
|
||||
controller_.attachStats(stats_.get());
|
||||
|
||||
// Trước configure(): planner nạp trong configure() và có thể muốn đọc cảm biến ngay trong
|
||||
// initialize() của nó.
|
||||
controller_.setSensorReader(sensors_);
|
||||
|
||||
if (!planner_.configure(root_nh, global_costmap_.get(), config_.position.global_planner_name,
|
||||
error))
|
||||
{
|
||||
@@ -267,6 +278,8 @@ bool NavigationRuntime::buildRunners(std::string& error)
|
||||
action_ctx.tf = tf_.get();
|
||||
action_ctx.global_frame = global_costmap_->getGlobalFrameID();
|
||||
action_ctx.robot_base_frame = config_.robot_base_frame;
|
||||
// Null khi host không cấp kho — handler nào cần dữ liệu thô tự từ chối ở configure().
|
||||
action_ctx.sensors = sensors_;
|
||||
action_.setContext(action_ctx);
|
||||
|
||||
if (!action_.configure(root_nh))
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*********************************************************************/
|
||||
#include <move_base2/navigation_server.h>
|
||||
|
||||
#include <move_base2/io/sensor_store_types.h>
|
||||
#include <robot_sensor_ports/sensor_writer.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <mission_adapters/mission_request.h>
|
||||
@@ -128,6 +131,10 @@ bool NavigationServer::configureLoop(const ControlLoopConfig& config, const Cont
|
||||
|
||||
robot_base_frame_ = config.robot_base_frame;
|
||||
|
||||
// Mượn đồng hồ của control loop cho phần chẩn đoán kho cảm biến. Phải là đồng hồ này chứ không
|
||||
// phải robot::Time::now(): cái sau đọc wall clock trong khi scan mang sim time.
|
||||
clock_ = deps.clock;
|
||||
|
||||
|
||||
nav_feedback_->is_ready = true;
|
||||
nav_feedback_->feed_back_str = "ready";
|
||||
@@ -135,6 +142,16 @@ bool NavigationServer::configureLoop(const ControlLoopConfig& config, const Cont
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NavigationServer::configureSensorStore(const robot_sensor_ports::SensorStoreConfig& config,
|
||||
std::string& error)
|
||||
{
|
||||
// Đăng ký kiểu riêng của gói này trước: khai `data_type: OccupancyGrid` mà bảng tên chưa có nó thì
|
||||
// config bị từ chối là "unknown". Idempotent nên gọi lại vô hại.
|
||||
registerSensorStoreTypes();
|
||||
|
||||
return sensor_store_.configure(config, error);
|
||||
}
|
||||
|
||||
bool NavigationServer::configureSensors(const SensorGatewayConfig& config, std::string& error)
|
||||
{
|
||||
return sensors_.configure(config, error);
|
||||
@@ -199,6 +216,7 @@ bool NavigationServer::spinOnce()
|
||||
cachePlans();
|
||||
}
|
||||
refreshFeedback();
|
||||
reportSensorStore();
|
||||
return running;
|
||||
}
|
||||
|
||||
@@ -285,6 +303,44 @@ bool NavigationServer::missionHasPendingWork() const
|
||||
runtime_->mission().hasActiveMission();
|
||||
}
|
||||
|
||||
void NavigationServer::reportSensorStore()
|
||||
{
|
||||
if (sensor_store_report_period_ <= 0.0 || clock_ == nullptr || !sensor_store_.configured())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const robot::Time now = clock_->now();
|
||||
|
||||
if (have_sensor_store_report_ &&
|
||||
(now - last_sensor_store_report_).toSec() < sensor_store_report_period_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
last_sensor_store_report_ = now;
|
||||
have_sensor_store_report_ = true;
|
||||
|
||||
for (const robot_sensor_ports::SensorInfo& info : sensor_store_.inventory())
|
||||
{
|
||||
if (info.sequence == 0)
|
||||
{
|
||||
// Chưa bao giờ có mẫu nào. Đây là ca đáng nói nhất: gõ sai `topic` và cảm biến chết cho cùng
|
||||
// một triệu chứng, nên phải in ra chứ không phải bỏ qua vì "không có gì để in".
|
||||
robot::log_warning("[move_base2] sensor store: '%s' (%s) — NO DATA YET. Kiểm tên topic host "
|
||||
"đang dùng khi gọi add*().\n",
|
||||
info.topic.c_str(), info.data_type.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
const double age = (now - info.stamp).toSec();
|
||||
robot::log_info("[move_base2] sensor store: '%s' %.1f Hz, age %.3f s%s, %zu/%zu kept, %llu "
|
||||
"rejected\n",
|
||||
info.topic.c_str(), info.rate_hz, age,
|
||||
age > info.max_age ? " [STALE]" : "", info.size, info.capacity,
|
||||
static_cast<unsigned long long>(info.rejected));
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationServer::refreshFeedback()
|
||||
{
|
||||
robot::move_base_core::State host_state = toHostState(loop_.state());
|
||||
@@ -393,6 +449,29 @@ void NavigationServer::initialize(robot::TFListenerPtr tf)
|
||||
// ra khỏi phần "(không đăng ký)".
|
||||
sensors_.attachTelemetry(stats_);
|
||||
|
||||
// Kho cảm biến THÔ dùng chung. Dựng trước buildRunners vì action handler và local planner đều
|
||||
// nhận cổng đọc lúc nạp plugin.
|
||||
if (!configureSensorStore(runtime_->config().sensor_store, error))
|
||||
{
|
||||
runtime_.reset();
|
||||
stats_ = nullptr;
|
||||
nav_feedback_->is_ready = false;
|
||||
nav_feedback_->feed_back_str = "invalid sensor_store: " + error;
|
||||
robot::log_error("[move_base2] initialize() failed: invalid sensor_store: %s\n", error.c_str());
|
||||
return;
|
||||
}
|
||||
runtime_->setSensorReader(&sensor_store_);
|
||||
setSensorStoreReportPeriod(runtime_->config().sensor_store_report_period);
|
||||
|
||||
if (sensor_store_.configured())
|
||||
{
|
||||
for (const robot_sensor_ports::SensorInfo& info : sensor_store_.inventory())
|
||||
{
|
||||
robot::log_info("[move_base2] sensor store: '%s' %s capacity=%zu max_age=%.2f s\n",
|
||||
info.topic.c_str(), info.data_type.c_str(), info.capacity, info.max_age);
|
||||
}
|
||||
}
|
||||
|
||||
if (!configureSensors(runtime_->config().sensors, error))
|
||||
{
|
||||
runtime_.reset();
|
||||
@@ -567,6 +646,7 @@ void NavigationServer::applyPendingFootprint()
|
||||
|
||||
void NavigationServer::addStaticMap(const std::string& map_name, robot_nav_msgs::OccupancyGrid map)
|
||||
{
|
||||
robot_sensor_ports::put(sensor_store_, map_name, map, map.header.stamp);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
static_maps_[map_name] = map;
|
||||
@@ -577,8 +657,14 @@ void NavigationServer::addStaticMap(const std::string& map_name, robot_nav_msgs:
|
||||
void NavigationServer::addLaserScan(const std::string& laser_scan_name,
|
||||
robot_sensor_msgs::LaserScan laser_scan)
|
||||
{
|
||||
// Lọc TRƯỚC khi cất: bản được cất và bản costmap nhìn thấy phải là một. Bản cũ cũng cất bản đã
|
||||
// lọc; nếu getter trả bản thô còn costmap thấy bản lọc thì hai nguồn sự thật sẽ lệch nhau.
|
||||
// Kho dùng chung nhận bản THÔ, và cố ý nhận TRƯỚC bộ lọc: bộ dò dock fit đường thẳng trên đúng
|
||||
// hình dạng laser đã thấy, còn costmap muốn bớt điểm nhiễu. Bật `laser_sor_enabled` là hai bên
|
||||
// nhìn hai bản khác nhau — có chủ đích, không phải sai sót.
|
||||
robot_sensor_ports::put(sensor_store_, laser_scan_name, laser_scan, laser_scan.header.stamp);
|
||||
|
||||
// Lọc TRƯỚC khi cất: bản được cất ở `laser_scans_` và bản costmap nhìn thấy phải là một. Bản cũ
|
||||
// cũng cất bản đã lọc; nếu getter trả bản thô còn costmap thấy bản lọc thì hai nguồn sự thật sẽ
|
||||
// lệch nhau.
|
||||
const robot_sensor_msgs::LaserScan prepared = sensors_.prepareLaserScan(laser_scan);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
@@ -590,6 +676,7 @@ void NavigationServer::addLaserScan(const std::string& laser_scan_name,
|
||||
void NavigationServer::addPointCloud(const std::string& point_cloud_name,
|
||||
robot_sensor_msgs::PointCloud point_cloud)
|
||||
{
|
||||
robot_sensor_ports::put(sensor_store_, point_cloud_name, point_cloud, point_cloud.header.stamp);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
point_clouds_[point_cloud_name] = point_cloud;
|
||||
@@ -600,6 +687,8 @@ void NavigationServer::addPointCloud(const std::string& point_cloud_name,
|
||||
void NavigationServer::addPointCloud2(const std::string& point_cloud2_name,
|
||||
robot_sensor_msgs::PointCloud2 point_cloud2)
|
||||
{
|
||||
robot_sensor_ports::put(sensor_store_, point_cloud2_name, point_cloud2,
|
||||
point_cloud2.header.stamp);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
point_cloud2s_[point_cloud2_name] = point_cloud2;
|
||||
@@ -614,6 +703,9 @@ void NavigationServer::addDepthCameraData(const std::string& topic,
|
||||
{
|
||||
return; // Bỏ mẫu null thay vì cất một con trỏ rỗng để tầng sau vấp phải.
|
||||
}
|
||||
|
||||
// Zero copy: host đã cầm sẵn ConstPtr, và một mẫu depth là hàng MB — copy để cất là phí thuần tuý.
|
||||
robot_sensor_ports::put(sensor_store_, topic, data, data->header.stamp);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
depth_camera_data_[topic] = data;
|
||||
@@ -685,30 +777,50 @@ std::map<std::string, robot_sensor_msgs::PointCloud2> NavigationServer::getAllPo
|
||||
|
||||
bool NavigationServer::removeStaticMap(const std::string& map_name)
|
||||
{
|
||||
// Kho dùng chung phải quên theo: host đã bỏ dữ liệu đó, mà kho vẫn phát bản cũ thì hai
|
||||
// nguồn nói hai chuyện khác nhau về thứ robot đang nhìn thấy.
|
||||
sensor_store_.clearTopic(map_name);
|
||||
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
return static_maps_.erase(map_name) > 0;
|
||||
}
|
||||
|
||||
bool NavigationServer::removeLaserScan(const std::string& laser_scan_name)
|
||||
{
|
||||
// Kho dùng chung phải quên theo: host đã bỏ dữ liệu đó, mà kho vẫn phát bản cũ thì hai
|
||||
// nguồn nói hai chuyện khác nhau về thứ robot đang nhìn thấy.
|
||||
sensor_store_.clearTopic(laser_scan_name);
|
||||
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
return laser_scans_.erase(laser_scan_name) > 0;
|
||||
}
|
||||
|
||||
bool NavigationServer::removePointCloud(const std::string& point_cloud_name)
|
||||
{
|
||||
// Kho dùng chung phải quên theo: host đã bỏ dữ liệu đó, mà kho vẫn phát bản cũ thì hai
|
||||
// nguồn nói hai chuyện khác nhau về thứ robot đang nhìn thấy.
|
||||
sensor_store_.clearTopic(point_cloud_name);
|
||||
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
return point_clouds_.erase(point_cloud_name) > 0;
|
||||
}
|
||||
|
||||
bool NavigationServer::removePointCloud2(const std::string& point_cloud2_name)
|
||||
{
|
||||
// Kho dùng chung phải quên theo: host đã bỏ dữ liệu đó, mà kho vẫn phát bản cũ thì hai
|
||||
// nguồn nói hai chuyện khác nhau về thứ robot đang nhìn thấy.
|
||||
sensor_store_.clearTopic(point_cloud2_name);
|
||||
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
return point_cloud2s_.erase(point_cloud2_name) > 0;
|
||||
}
|
||||
|
||||
bool NavigationServer::removeAllStaticMaps()
|
||||
{
|
||||
// Kho dùng chung phải quên theo: host đã bỏ dữ liệu đó, mà kho vẫn phát bản cũ thì hai
|
||||
// nguồn nói hai chuyện khác nhau về thứ robot đang nhìn thấy.
|
||||
sensor_store_.clearOfType(robot_sensor_ports::SensorType<robot_nav_msgs::OccupancyGrid>::id());
|
||||
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
static_maps_.clear();
|
||||
return true;
|
||||
@@ -716,6 +828,10 @@ bool NavigationServer::removeAllStaticMaps()
|
||||
|
||||
bool NavigationServer::removeAllLaserScans()
|
||||
{
|
||||
// Kho dùng chung phải quên theo: host đã bỏ dữ liệu đó, mà kho vẫn phát bản cũ thì hai
|
||||
// nguồn nói hai chuyện khác nhau về thứ robot đang nhìn thấy.
|
||||
sensor_store_.clearOfType(robot_sensor_ports::SensorType<robot_sensor_msgs::LaserScan>::id());
|
||||
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
laser_scans_.clear();
|
||||
return true;
|
||||
@@ -723,6 +839,10 @@ bool NavigationServer::removeAllLaserScans()
|
||||
|
||||
bool NavigationServer::removeAllPointClouds()
|
||||
{
|
||||
// Kho dùng chung phải quên theo: host đã bỏ dữ liệu đó, mà kho vẫn phát bản cũ thì hai
|
||||
// nguồn nói hai chuyện khác nhau về thứ robot đang nhìn thấy.
|
||||
sensor_store_.clearOfType(robot_sensor_ports::SensorType<robot_sensor_msgs::PointCloud>::id());
|
||||
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
point_clouds_.clear();
|
||||
return true;
|
||||
@@ -730,6 +850,10 @@ bool NavigationServer::removeAllPointClouds()
|
||||
|
||||
bool NavigationServer::removeAllPointCloud2s()
|
||||
{
|
||||
// Kho dùng chung phải quên theo: host đã bỏ dữ liệu đó, mà kho vẫn phát bản cũ thì hai
|
||||
// nguồn nói hai chuyện khác nhau về thứ robot đang nhìn thấy.
|
||||
sensor_store_.clearOfType(robot_sensor_ports::SensorType<robot_sensor_msgs::PointCloud2>::id());
|
||||
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
point_cloud2s_.clear();
|
||||
return true;
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
*********************************************************************/
|
||||
#include <move_base2/runners/controller_runner.h>
|
||||
|
||||
#include <robot_sensor_ports/sensor_consumer.h>
|
||||
#include <robot_sensor_ports/sensor_reader.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <exception>
|
||||
#include <sstream>
|
||||
@@ -116,6 +119,7 @@ robot_nav_core2::LocalPlanner* ControllerRunner::acquire(const std::string& name
|
||||
"rebuilding for the new marker.\n", name.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
attachSensors(fresh.get());
|
||||
fresh->initialize(nh_, name, tf_, costmap_);
|
||||
cached->second.instance = std::move(fresh);
|
||||
}
|
||||
@@ -183,6 +187,7 @@ robot_nav_core2::LocalPlanner* ControllerRunner::acquire(const std::string& name
|
||||
{
|
||||
// Chữ ký gen-2: (parent NodeHandle, tên, TF, costmap). Khác hẳn gen-1 — và vì Boost.DLL không
|
||||
// kiểm kiểu, gọi nhầm chữ ký sẽ không lỗi biên dịch mà hỏng vtable lúc chạy.
|
||||
attachSensors(loaded.instance.get());
|
||||
loaded.instance->initialize(nh_, name, tf_, costmap_);
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
@@ -240,6 +245,28 @@ bool ControllerRunner::setDockingMarker(const std::string& marker)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ControllerRunner::attachSensors(robot_nav_core2::LocalPlanner* controller) const
|
||||
{
|
||||
if (controller == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto* consumer = dynamic_cast<robot_sensor_ports::SensorConsumer*>(controller);
|
||||
if (consumer == nullptr)
|
||||
{
|
||||
return; // Planner không khai nhận cảm biến. Đúng với phần lớn planner, không phải lỗi.
|
||||
}
|
||||
|
||||
consumer->setSensorReader(sensors_);
|
||||
|
||||
// Log vì cast qua ranh giới `.so` phụ thuộc RTTI khớp giữa hai bên, và build xanh không nói gì về
|
||||
// chuyện đó. Một planner khai kế thừa mà không bao giờ thấy dòng này nghĩa là RTTI lệch.
|
||||
robot::log_info("[move_base2] ControllerRunner: local planner accepts the shared sensor store "
|
||||
"(%s).\n",
|
||||
sensors_ != nullptr ? "store attached" : "no store configured");
|
||||
}
|
||||
|
||||
void ControllerRunner::applyPendingLimits(robot_nav_core2::LocalPlanner* controller)
|
||||
{
|
||||
if (controller == nullptr)
|
||||
@@ -411,6 +438,7 @@ bool ControllerRunner::refreshActivePlanner()
|
||||
"refreshing its footprint cache.\n", active_name_.c_str());
|
||||
return false;
|
||||
}
|
||||
attachSensors(fresh.get());
|
||||
fresh->initialize(nh_, active_name_, tf_, costmap_);
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
|
||||
Reference in New Issue
Block a user