From 09799dffdda04977e956d9148cb8d2a2edb1bc7c Mon Sep 17 00:00:00 2001 From: duongtd Date: Thu, 27 Aug 2026 12:05:53 +0700 Subject: [PATCH] api: the sensor key is a topic, so call it one Five add* functions each named the same argument differently - map_name, laser_scan_name, point_cloud_name, point_cloud2_name, odometry_name - while addDepthCameraData already called it topic. The get* and remove* families disagreed in the same way, though they take the same key. It is not a label. It has to match the topic a costmap layer names in observation_sources, and the entry in sensor_store_params.yaml. A key matching nothing is accepted in silence and read by nobody, which surfaces as an empty costmap with no error anywhere - so the parameter name is the first place to say what the string is for. Fourteen declarations now say topic. A parameter name has no effect at a call site, so this touches no host: no ABI change, nothing to rebuild in lockstep. addDepthCameraData is the one add* taking a const pointer rather than a value, and the header now says why, because the next reader will otherwise see an inconsistency and even it up. Every other sensor is reduced by the host before it arrives - a laser scan is 5.5 KB, a depth cloud is voxel-filtered from 3.26 MB to 24 KB - and copying all four together costs about 25 microseconds per second of runtime, measured against a running simulation. A depth image arrives whole at 398 KB because the voxel layer needs the full frame for its clearing frustum, and copying that costs roughly 250 times the other four combined. That is what earns a pointer, and a 5 KB scan does not. --- .../include/move_base_core/navigation.h | 82 ++++++++++++------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/src/Navigations/Cores/move_base_core/include/move_base_core/navigation.h b/src/Navigations/Cores/move_base_core/include/move_base_core/navigation.h index 525bdb3..e22a8f2 100755 --- a/src/Navigations/Cores/move_base_core/include/move_base_core/navigation.h +++ b/src/Navigations/Cores/move_base_core/include/move_base_core/navigation.h @@ -234,67 +234,93 @@ namespace robot /** * @brief Add a static map to the navigation system. - * @param map_name The name of the map. - * @param map The map to add. + * + * @param topic Logical topic this map arrives on. It is a KEY, not a label: it must match + * the `topic` a costmap layer names in `observation_sources`, and the entry + * in `sensor_store_params.yaml`. A name that matches nothing is accepted in + * silence and read by nobody - an empty costmap with no error anywhere. + * @param map The map to add. */ - virtual void addStaticMap(const std::string &map_name, robot_nav_msgs::OccupancyGrid map) = 0; + virtual void addStaticMap(const std::string &topic, robot_nav_msgs::OccupancyGrid map) = 0; /** * @brief Add a laser scan to the navigation system. - * @param laser_scan_name The name of the laser scan. + * @param topic Logical topic this scan arrives on. See @ref addStaticMap for what + * happens when it matches nothing. * @param laser_scan The laser scan to add. */ - virtual void addLaserScan(const std::string &laser_scan_name, robot_sensor_msgs::LaserScan laser_scan) = 0; + virtual void addLaserScan(const std::string &topic, robot_sensor_msgs::LaserScan laser_scan) = 0; /** * @brief Add a point cloud to the navigation system. - * @param point_cloud_name The name of the point cloud. + * @param topic Logical topic this cloud arrives on. * @param point_cloud The point cloud to add. + * + * @note The older of the two cloud types. New sensors should use @ref addPointCloud2. */ - virtual void addPointCloud(const std::string &point_cloud_name, robot_sensor_msgs::PointCloud point_cloud) = 0; + virtual void addPointCloud(const std::string &topic, robot_sensor_msgs::PointCloud point_cloud) = 0; /** * @brief Add a point cloud2 to the navigation system. - * @param point_cloud2_name The name of the point cloud2. + * @param topic Logical topic this cloud arrives on. * @param point_cloud2 The point cloud2 to add. */ - virtual void addPointCloud2(const std::string &point_cloud2_name, robot_sensor_msgs::PointCloud2 point_cloud2) = 0; + virtual void addPointCloud2(const std::string &topic, robot_sensor_msgs::PointCloud2 point_cloud2) = 0; /** * @brief Add one coherent depth-camera sample to the navigation system. + * * @param topic The logical topic of the combined depth-camera stream. - * @param data Depth image and matching camera intrinsics. + * @param data Depth image and matching camera intrinsics. + * + * @note This is the ONE add* function taking a const pointer instead of a value, and the + * asymmetry is deliberate rather than an oversight - do not "even it up". + * + * Every other sensor is reduced by the host before it gets here: a laser scan is + * 5.5 KB, and a depth cloud is voxel-filtered from 3.26 MB down to 24 KB. Measured + * against a running simulation, copying ALL of them costs about 25 microseconds + * per second of runtime, which is nothing. + * + * A depth image is not reduced first - it arrives whole, 398 KB, because the voxel + * layer needs the full frame to carve its clearing frustum. Copying that costs + * roughly 250 times what the other four cost together, and that is what earns a + * pointer. + * + * The price of a pointer is a harder contract: the caller must not modify @p data + * after handing it over. Nothing catches a violation - not the compiler, not a + * crash - the costmap simply sees something other than what the host believes it + * sent. Worth paying here; not worth paying for a 5 KB scan. */ virtual void addDepthCameraData(const std::string &topic, robot_sensor_msgs::DepthCameraData::ConstPtr data) = 0; /** * @brief Get a static map from the navigation system. - * @param map_name The name of the map. + * @param topic Logical topic the map arrives on. Same key used by the matching add*. * @return The map. */ - virtual robot_nav_msgs::OccupancyGrid getStaticMap(const std::string &map_name) = 0; + virtual robot_nav_msgs::OccupancyGrid getStaticMap(const std::string &topic) = 0; /** * @brief Get a laser scan from the navigation system. - * @param laser_scan_name The name of the laser scan. + * @param topic Logical topic the laser scan arrives on. Same key used by the matching add*. * @return The laser scan. */ - virtual robot_sensor_msgs::LaserScan getLaserScan(const std::string &laser_scan_name) = 0; + virtual robot_sensor_msgs::LaserScan getLaserScan(const std::string &topic) = 0; /** * @brief Get a point cloud from the navigation system. - * @param point_cloud_name The name of the point cloud. + * @param topic Logical topic the point cloud arrives on. Same key used by the matching add*. * @return The point cloud. */ - virtual robot_sensor_msgs::PointCloud getPointCloud(const std::string &point_cloud_name) = 0; + virtual robot_sensor_msgs::PointCloud getPointCloud(const std::string &topic) = 0; /** * @brief Get a point cloud2 from the navigation system. - * @param point_cloud2_name The name of the point cloud2. + * @param topic Logical topic the point cloud2 arrives on. Same key used by the matching add*. * @return The point cloud2. */ - virtual robot_sensor_msgs::PointCloud2 getPointCloud2(const std::string &point_cloud2_name) = 0; + virtual robot_sensor_msgs::PointCloud2 getPointCloud2(const std::string &topic) = 0; /** * @brief Get all static maps from the navigation system. @@ -322,31 +348,31 @@ namespace robot /** * @brief Remove a static map from the navigation system. - * @param map_name The name of the map. + * @param topic Logical topic the map arrives on. Same key used by the matching add*. * @return True if the map was removed successfully. */ - virtual bool removeStaticMap(const std::string &map_name) = 0; + virtual bool removeStaticMap(const std::string &topic) = 0; /** * @brief Remove a laser scan from the navigation system. - * @param laser_scan_name The name of the laser scan. + * @param topic Logical topic the laser scan arrives on. Same key used by the matching add*. * @return True if the laser scan was removed successfully. */ - virtual bool removeLaserScan(const std::string &laser_scan_name) = 0; + virtual bool removeLaserScan(const std::string &topic) = 0; /** * @brief Remove a point cloud from the navigation system. - * @param point_cloud_name The name of the point cloud. + * @param topic Logical topic the point cloud arrives on. Same key used by the matching add*. * @return True if the point cloud was removed successfully. */ - virtual bool removePointCloud(const std::string &point_cloud_name) = 0; + virtual bool removePointCloud(const std::string &topic) = 0; /** * @brief Remove a point cloud2 from the navigation system. - * @param point_cloud2_name The name of the point cloud2. + * @param topic Logical topic the point cloud2 arrives on. Same key used by the matching add*. * @return True if the point cloud2 was removed successfully. */ - virtual bool removePointCloud2(const std::string &point_cloud2_name) = 0; + virtual bool removePointCloud2(const std::string &topic) = 0; /** * @brief Remove all static maps from the navigation system. @@ -380,10 +406,10 @@ namespace robot /** * @brief Add an odometry to the navigation system. - * @param odometry_name The name of the odometry. + * @param topic Logical topic the odometry arrives on. Same key used by the matching add*. * @param odometry The odometry to add. */ - virtual void addOdometry(const std::string &odometry_name, robot_nav_msgs::Odometry odometry) = 0; + virtual void addOdometry(const std::string &topic, robot_nav_msgs::Odometry odometry) = 0; /** * @brief Send a goal for the robot to navigate to.