3333 * purposes notwithstanding any copyright notation herein.
3434 * -------------------------------------------------------------------------- */
3535#pragma once
36- #include < hydra/active_window/reconstruction_module.h>
37- #include < hydra/places/traversability_layer.h>
36+ #include < hydra/places/traversability_estimator.h>
3837#include < ianvs/node_handle.h>
3938#include < spark_dsg/bounding_box.h>
4039
41- #include < optional>
42-
4340#include < nav_msgs/msg/occupancy_grid.hpp>
4441#include < rclcpp/publisher.hpp>
4542
4643#include < Eigen/Geometry>
4744
4845namespace hydra {
4946
50- using Index2D = Eigen::Vector2i;
51-
52- struct Index2DHash {
53- inline static const auto s = Index2D(1 , 1290 );
54- int operator ()(const Index2D& index) const { return index.dot (s); }
55- };
56-
57- template <typename ValueT>
58- using Index2DMap =
59- std::unordered_map<Index2D,
60- ValueT,
61- Index2DHash,
62- std::equal_to<Index2D>,
63- Eigen::aligned_allocator<std::pair<const Index2D, ValueT>>>;
64-
65- struct GradientInfo {
66- float gradient = 0 .0f ; // mean gradient magnitude
67- float confidence = 0 .0f ; // num_neighbors / 8.0
68- };
69-
70- class TsdfGradientOccupancyPublisher : public ReconstructionModule ::Sink {
47+ class TsdfGradientOccupancyPublisher
48+ : public hydra::places::GradientTraversabilityEstimator::Sink {
7149 public:
7250 struct Config {
73- // Base occupancy config fields
7451 std::string ns = " ~/tsdf_gradient" ;
7552 bool collate = false ;
7653 bool use_relative_height = true ;
77- double slice_height = -1.0 ;
78- size_t num_slices = 20 ; // if if 10 cm, we want 2 m from -1 m to +1 m
79- bool add_robot_footprint = false ;
54+ bool add_robot_footprint = false ; // force voxels around robot to be free
8055 Eigen::Vector3f footprint_min = Eigen::Vector3f::Zero();
8156 Eigen::Vector3f footprint_max = Eigen::Vector3f::Zero();
8257
83- // Gradient-specific parameters
8458 float gradient_threshold = 0 .5f ; // m/m - max traversable gradient
85- float min_weight = 1 .0e-6f ; // min TSDF weight for observed voxel
8659 float min_confidence = 0 .5f ; // min confidence (neighbors/8) for valid cell
87- bool smoothing = true ; // apply box filter to reduce TSDF ripple
8860 bool probabilistic = false ; // continuous vs binary occupancy
8961 bool filter_disjoint = false ; // remove free space not connected to robot
9062 } const config;
@@ -95,55 +67,32 @@ class TsdfGradientOccupancyPublisher : public ReconstructionModule::Sink {
9567
9668 std::string printInfo () const override ;
9769
98- void call (uint64_t timestamp_ns ,
99- const VolumetricMap& map ,
70+ void call (const hydra::places::HeightMap& height_map ,
71+ const hydra::places::GradientMap& gradient_map ,
10072 const ActiveWindowOutput& output) const override ;
10173
10274 private:
10375 rclcpp::Publisher<nav_msgs::msg::OccupancyGrid>::SharedPtr pub_;
10476 rclcpp::Publisher<nav_msgs::msg::OccupancyGrid>::SharedPtr height_map_pub_;
10577 rclcpp::Publisher<nav_msgs::msg::OccupancyGrid>::SharedPtr gradient_map_pub_;
10678
107- // Helper functions
108- std::optional<float > extractSurfaceHeight (const TsdfLayer& layer,
109- const BlockIndex& block_2d_index,
110- const VoxelIndex& local_2d,
111- float min_z,
112- float max_z) const ;
113-
114- void buildHeightMap (const TsdfLayer& layer,
115- float min_z,
116- float max_z,
117- Index2DMap<float >& height_map) const ;
118-
119- void computeGradientMap (const Index2DMap<float >& height_map,
120- float voxel_size,
121- Index2DMap<GradientInfo>& gradient_map) const ;
122-
123- void fillOccupancyGrid (const Index2DMap<GradientInfo>& gradient_map,
79+ void fillOccupancyGrid (const hydra::places::GradientMap& gradient_map,
12480 const Eigen::Isometry3d& world_T_sensor,
12581 const TsdfLayer& layer,
12682 nav_msgs::msg::OccupancyGrid& msg) const ;
12783
12884 void filterDisjointFreeSpace (nav_msgs::msg::OccupancyGrid& msg,
12985 const Eigen::Isometry3d& world_T_body) const ;
13086
131- void publishHeightMapViz (const Index2DMap< float > & height_map,
87+ void publishHeightMapViz (const hydra::places::HeightMap & height_map,
13288 const TsdfLayer& layer,
13389 uint64_t timestamp_ns) const ;
13490
135- void publishGradientMapViz (const Index2DMap<GradientInfo> & gradient_map,
91+ void publishGradientMapViz (const hydra::places::GradientMap & gradient_map,
13692 const TsdfLayer& layer,
13793 uint64_t timestamp_ns) const ;
13894
139- float computeHorizontalDistance (const Index2D& offset, float voxel_size) const ;
140-
141- float computeTraversabilityFromGradient (float gradient) const ;
142-
14395 int8_t gradientToOccupancy (float gradient, float confidence) const ;
144-
145- // 8-way neighbor offsets
146- static const std::array<Index2D, 8 > kNeighborOffsets ;
14796};
14897
14998void declare_config (TsdfGradientOccupancyPublisher::Config& config);
0 commit comments