From 3b7692ed8b4028e9885dcbbbe7c9038313ae4d14 Mon Sep 17 00:00:00 2001 From: duongtd Date: Wed, 26 Aug 2026 11:34:35 +0700 Subject: [PATCH] Give action handlers a port onto the shared raw sensor store A handler that samples through TF only ever sees what perception already decided. One that detects for itself - picking the V plate of a charging dock out of a laser scan - needs the ranges array in ray order, and the costmap at 0.05 m has inflated that away beyond reconstruction. ActionContext carried no way to reach sensor data at all, so that handler could not be written. It now carries a read-only port onto the store in robot_sensor_ports. Null when the host provides none, and a handler that needs sensor data is expected to refuse in configure() rather than discover it mid-shift, the same contract the tf pointer already has. The struct is crossed by boost::dll, so its layout is an ABI. Adding a field changes that layout and dlsym plus reinterpret_cast catches none of it at compile time - an old .so reads the old offsets off new data and returns garbage. The field goes at the end and the warning now says so in the doc, but the rule stands: every handler .so is rebuilt in the same pass. --- CMakeLists.txt | 5 ++++- include/action_core/action_context.h | 22 ++++++++++++++++++++++ package.xml | 5 +++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac2857d..d7375d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,13 +87,14 @@ if(NOT BUILDING_WITH_CATKIN) /usr/local/lib ) - # Gói này KHÔNG kéo costmap/tf3: action không chạm bản đồ và không phát vận tốc (D8), nên bốn + # Gói này KHÔNG kéo costmap/tf3: action không chạm bản đồ và không phát vận tốc (D8), nên năm # thư viện dưới đây là toàn bộ phụ thuộc runtime của nó. set(STANDALONE_LIBRARIES robot_cpp robot_time robot_xmlrpcpp robot_protocol_msgs + robot_sensor_ports ) include_directories( @@ -116,6 +117,7 @@ else() robot_time robot_protocol_msgs robot_xmlrpcpp + robot_sensor_ports ) catkin_package( @@ -134,6 +136,7 @@ else() robot_time robot_protocol_msgs robot_xmlrpcpp + robot_sensor_ports DEPENDS Boost diff --git a/include/action_core/action_context.h b/include/action_core/action_context.h index 56def00..3703a8c 100644 --- a/include/action_core/action_context.h +++ b/include/action_core/action_context.h @@ -16,6 +16,11 @@ namespace tf3 class BufferCore; } +namespace robot_sensor_ports +{ +class SensorReader; +} + namespace action_core { @@ -34,6 +39,11 @@ namespace action_core * * @warning Con trỏ **non-owning**. Buffer thuộc navigation runtime và sống lâu hơn handler; handler * không được giữ bản sao nào của dữ liệu bên trong nó qua các tick. + * + * @warning Struct này đi qua ranh giới `boost::dll`. Thêm/bớt/đổi thứ tự trường là đổi layout, mà + * `dlsym` + `reinterpret_cast` không bắt được lệch đó lúc biên dịch — handler cũ sẽ đọc + * đúng offset cũ trên dữ liệu mới và ra rác. Mỗi lần sửa struct này phải build lại TOÀN BỘ + * `.so` handler cùng một lượt, và trường mới luôn thêm vào CUỐI. */ struct ActionContext { @@ -45,6 +55,18 @@ struct ActionContext /// Frame gắn với thân robot. std::string robot_base_frame = "base_link"; + + /** + * Kho cảm biến thô dùng chung, chỉ-đọc. Có thể null — handler cần dữ liệu cảm biến phải tự từ + * chối ở `configure()`. + * + * Vì sao cần dù đã có `tf`: handler dò mẫu qua TF chỉ thấy KẾT QUẢ của perception. Handler tự dò + * (bắt chữ V của trạm sạc từ LiDAR chẳng hạn) cần mảng `ranges` theo đúng thứ tự tia — costmap ở + * 0.05 m đã inflate và xoá mất thứ tự đó, không dựng lại được. + * + * Non-owning; kho thuộc navigation runtime và sống lâu hơn handler. + */ + const robot_sensor_ports::SensorReader* sensors = nullptr; }; } // namespace action_core diff --git a/package.xml b/package.xml index 55bbfa6..4da1afa 100644 --- a/package.xml +++ b/package.xml @@ -42,6 +42,11 @@ robot_xmlrpcpp robot_xmlrpcpp + + robot_sensor_ports + robot_sensor_ports + yaml-cpp yaml-cpp