|
| 1 | +/* ----------------------------------------------------------------------------- |
| 2 | + * Copyright 2022 Massachusetts Institute of Technology. |
| 3 | + * All Rights Reserved |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions are met: |
| 7 | + * |
| 8 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | + * this list of conditions and the following disclaimer. |
| 10 | + * |
| 11 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | + * this list of conditions and the following disclaimer in the documentation |
| 13 | + * and/or other materials provided with the distribution. |
| 14 | + * |
| 15 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 16 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 17 | + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 18 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 19 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 20 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 21 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 22 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 23 | + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | + * |
| 26 | + * Research was sponsored by the United States Air Force Research Laboratory and |
| 27 | + * the United States Air Force Artificial Intelligence Accelerator and was |
| 28 | + * accomplished under Cooperative Agreement Number FA8750-19-2-1000. The views |
| 29 | + * and conclusions contained in this document are those of the authors and should |
| 30 | + * not be interpreted as representing the official policies, either expressed or |
| 31 | + * implied, of the United States Air Force or the U.S. Government. The U.S. |
| 32 | + * Government is authorized to reproduce and distribute reprints for Government |
| 33 | + * purposes notwithstanding any copyright notation herein. |
| 34 | + * -------------------------------------------------------------------------- */ |
| 35 | +#pragma once |
| 36 | +#include <hydra/places/traversability_estimator.h> |
| 37 | +#include <ianvs/node_handle.h> |
| 38 | +#include <spark_dsg/bounding_box.h> |
| 39 | + |
| 40 | +#include <nav_msgs/msg/occupancy_grid.hpp> |
| 41 | +#include <rclcpp/publisher.hpp> |
| 42 | + |
| 43 | +#include <Eigen/Geometry> |
| 44 | + |
| 45 | +namespace hydra { |
| 46 | + |
| 47 | +class TsdfGradientOccupancyPublisher |
| 48 | + : public hydra::places::GradientTraversabilityEstimator::Sink { |
| 49 | + public: |
| 50 | + struct Config { |
| 51 | + std::string ns = "~/tsdf_gradient"; |
| 52 | + bool collate = false; |
| 53 | + bool use_relative_height = true; |
| 54 | + bool add_robot_footprint = false; // force voxels around robot to be free |
| 55 | + Eigen::Vector3f footprint_min = Eigen::Vector3f::Zero(); |
| 56 | + Eigen::Vector3f footprint_max = Eigen::Vector3f::Zero(); |
| 57 | + |
| 58 | + float gradient_threshold = 0.5f; // m/m - max traversable gradient |
| 59 | + float min_confidence = 0.5f; // min confidence (neighbors/8) for valid cell |
| 60 | + bool probabilistic = false; // continuous vs binary occupancy |
| 61 | + bool filter_disjoint = false; // remove free space not connected to robot |
| 62 | + } const config; |
| 63 | + |
| 64 | + explicit TsdfGradientOccupancyPublisher(const Config& config); |
| 65 | + |
| 66 | + virtual ~TsdfGradientOccupancyPublisher() = default; |
| 67 | + |
| 68 | + std::string printInfo() const override; |
| 69 | + |
| 70 | + void call(const hydra::places::HeightMap& height_map, |
| 71 | + const hydra::places::GradientMap& gradient_map, |
| 72 | + const ActiveWindowOutput& output, |
| 73 | + const TsdfLayer& tsdf_layer) const override; |
| 74 | + |
| 75 | + private: |
| 76 | + rclcpp::Publisher<nav_msgs::msg::OccupancyGrid>::SharedPtr pub_; |
| 77 | + rclcpp::Publisher<nav_msgs::msg::OccupancyGrid>::SharedPtr height_map_pub_; |
| 78 | + rclcpp::Publisher<nav_msgs::msg::OccupancyGrid>::SharedPtr gradient_map_pub_; |
| 79 | + |
| 80 | + void fillOccupancyGrid(const hydra::places::GradientMap& gradient_map, |
| 81 | + const Eigen::Isometry3d& world_T_sensor, |
| 82 | + const TsdfLayer& layer, |
| 83 | + nav_msgs::msg::OccupancyGrid& msg) const; |
| 84 | + |
| 85 | + void filterDisjointFreeSpace(nav_msgs::msg::OccupancyGrid& msg, |
| 86 | + const Eigen::Isometry3d& world_T_body) const; |
| 87 | + |
| 88 | + void publishHeightMapViz(const hydra::places::HeightMap& height_map, |
| 89 | + const TsdfLayer& layer, |
| 90 | + uint64_t timestamp_ns, |
| 91 | + float robot_z) const; |
| 92 | + |
| 93 | + void publishGradientMapViz(const hydra::places::GradientMap& gradient_map, |
| 94 | + const TsdfLayer& layer, |
| 95 | + uint64_t timestamp_ns, |
| 96 | + float robot_z) const; |
| 97 | + |
| 98 | + int8_t gradientToOccupancy(float gradient, float confidence) const; |
| 99 | +}; |
| 100 | + |
| 101 | +void declare_config(TsdfGradientOccupancyPublisher::Config& config); |
| 102 | + |
| 103 | +} // namespace hydra |
0 commit comments