One place raw sensor readings live, shared by everything that needs them
Sensor data entered the navigation 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 to it: ActionContext held only TF, and LocalPlanner::initialize takes only a costmap. The store keeps readings raw. Anything that wants filtering filters before publishing here; the store does not know a filter exists. That split is deliberate - a costmap wants outliers removed, a detector wants the true shape, and a store deciding for both would be wrong for one of them. Sharing is by shared_ptr to an immutable reading. Producers build a new one and swap the pointer rather than writing in place, so a reader copies the pointer under the mutex in tens of nanoseconds and then walks a thousand ranges with nobody able to change them underneath. Two consumers reading one topic share one copy rather than taking one each, which is what makes a megabyte depth cloud affordable to share. A bare pointer into the store would instead force every reader to hold the lock for the whole read, putting the sensor input path behind however long a detector takes. The store keeps its own mutex for the same reason: NavigationServer's already covers five kinds of data, and readers running at control-loop rate do not belong in that queue. Readers order on an arrival counter, not on the stamp. A stamp can go backwards - host restart, a switch to simulated time, a replayed bag - and a reader filtering on stamp then treats every later reading as old and freezes for good, silently. The stamp is still kept, for TF lookups and for age, which are different jobs. A consumer faster than its sensor gets null on the ticks with nothing new rather than the same reading handed back to be counted twice. The interface is type-erased because boost::dll-loaded plugins cross it. One virtual per message type would mean a new virtual per sensor, reshuffling the vtable and silently breaking every .so not rebuilt in the same pass - dlsym plus reinterpret_cast catches none of that at compile time. So identity travels as a string, payload as shared_ptr<const void>, and five virtuals cover every message type that exists or will. The typed sugar is a header-only template on the caller's side. typeid is avoided deliberately: comparing type_index across a .so depends on visibility and on how the linker merges typeinfo, and it fails quietly. Adding a message type is one line of a list that generates both the trait and the YAML short-name table, so a type can never be castable without being nameable, or the reverse. A read with the wrong identity is refused and logged once, never cast. static_pointer_cast to the wrong type reads garbage instead of crashing and surfaces somewhere unrelated; that check is the only thing standing between the erasure and it. 22 of the 24 robot_sensor_msgs types are registered. Imu and TimeReference are not, because their headers do not compile here at all - Imu.h still carries the unported ROS tail specialising ros::message_operations::Printer, and TimeReference.h declares its field as ros::Time. Both are faults in robot_sensor_msgs, and fixing them makes each one line here. Config is refused at boot rather than at first use, and an undeclared topic is dropped rather than added on the fly: an undeclared depth cloud would otherwise cost megabytes a frame and the config would stop describing what the process holds. A store with nothing declared stays silent - warning once per topic about a feature nobody switched on is how a working system starts printing errors after an upgrade. SensorConsumer is the side channel for a local planner: widening LocalPlanner::initialize would break every planner in the workspace at once for the sake of the one that wants a scan, so a planner that wants sensor data inherits this as well and the runtime finds out with a dynamic_cast.
This commit is contained in:
97
test/config/sensor_store_params.yaml
Normal file
97
test/config/sensor_store_params.yaml
Normal file
@@ -0,0 +1,97 @@
|
||||
# =================================================================================================
|
||||
# Cây config của test — KHÔNG phải bản chạy thật. Mỗi khối là một ca kiểm riêng.
|
||||
# =================================================================================================
|
||||
|
||||
# Ca thường: hai lidar, giữ bản mới nhất.
|
||||
sensor_store:
|
||||
sensors:
|
||||
- topic: /f_scan
|
||||
data_type: LaserScan # dạng ngắn
|
||||
capacity: 1
|
||||
max_age: 0.5 # [s]
|
||||
|
||||
- topic: /b_scan
|
||||
data_type: robot_sensor_msgs/LaserScan # dạng đầy đủ, phải tương đương
|
||||
capacity: 1
|
||||
max_age: 0.5
|
||||
|
||||
# Thiếu capacity và max_age -> phải rơi về default (1 và 0.5), không được từ chối.
|
||||
sensor_store_defaults:
|
||||
sensors:
|
||||
- topic: /f_scan
|
||||
data_type: LaserScan
|
||||
|
||||
# Stack frame: capacity > 1 cho consumer cần nhiều frame liên tiếp.
|
||||
sensor_store_stack:
|
||||
sensors:
|
||||
- topic: /f_scan
|
||||
data_type: LaserScan
|
||||
capacity: 5
|
||||
max_age: 0.5
|
||||
|
||||
# Nhiều loại cảm biến cùng lúc — kho không ưu ái loại nào.
|
||||
sensor_store_mixed:
|
||||
sensors:
|
||||
- topic: /f_scan
|
||||
data_type: LaserScan
|
||||
capacity: 1
|
||||
max_age: 0.5
|
||||
|
||||
- topic: /camera/depth/data
|
||||
data_type: DepthCameraData
|
||||
capacity: 1
|
||||
max_age: 0.3 # [s] depth chậm hơn lidar nhưng stale thì nguy hơn
|
||||
|
||||
- topic: /front_cloud
|
||||
data_type: PointCloud2
|
||||
capacity: 1
|
||||
max_age: 0.4
|
||||
|
||||
# Không khai sensor nào: hợp lệ, kho rỗng. Runtime không có consumer nào thì đây là câu trả lời
|
||||
# đúng, không phải lý do để không khởi động.
|
||||
sensor_store_empty:
|
||||
other_key: 1
|
||||
|
||||
# --- Các khối dưới đây đều PHẢI bị từ chối lúc boot -----------------------------------------------
|
||||
|
||||
# data_type không có thật.
|
||||
sensor_store_bad_type:
|
||||
sensors:
|
||||
- topic: /f_scan
|
||||
data_type: LazerScan
|
||||
|
||||
# thiếu khoá data_type.
|
||||
sensor_store_missing_type:
|
||||
sensors:
|
||||
- topic: /f_scan
|
||||
capacity: 1
|
||||
|
||||
# thiếu khoá topic.
|
||||
sensor_store_missing_topic:
|
||||
sensors:
|
||||
- data_type: LaserScan
|
||||
|
||||
# capacity < 1: không giữ bản nào thì consumer không bao giờ đọc được gì.
|
||||
sensor_store_bad_capacity:
|
||||
sensors:
|
||||
- topic: /f_scan
|
||||
data_type: LaserScan
|
||||
capacity: 0
|
||||
|
||||
# max_age <= 0: mọi bản đều stale ngay khi tới.
|
||||
sensor_store_bad_max_age:
|
||||
sensors:
|
||||
- topic: /f_scan
|
||||
data_type: LaserScan
|
||||
max_age: 0.0
|
||||
|
||||
# Một topic khai hai lần: một trong hai là config chết, và cái nào thắng chỉ do thứ tự khai.
|
||||
sensor_store_duplicate_topic:
|
||||
sensors:
|
||||
- topic: /f_scan
|
||||
data_type: LaserScan
|
||||
capacity: 1
|
||||
|
||||
- topic: /f_scan
|
||||
data_type: LaserScan
|
||||
capacity: 5
|
||||
Reference in New Issue
Block a user