|
| 1 | +/* |
| 2 | + * Copyright 2024, Justus Braun |
| 3 | + * |
| 4 | + * Redistribution and use in source and binary forms, with or without |
| 5 | + * modification, are permitted provided that the following conditions |
| 6 | + * are met: |
| 7 | + * |
| 8 | + * 1. Redistributions of source code must retain the above copyright |
| 9 | + * notice, this list of conditions and the following disclaimer. |
| 10 | + * |
| 11 | + * 2. Redistributions in binary form must reproduce the above |
| 12 | + * copyright notice, this list of conditions and the following |
| 13 | + * disclaimer in the documentation and/or other materials provided |
| 14 | + * with the distribution. |
| 15 | + * |
| 16 | + * 3. Neither the name of the copyright holder nor the names of its |
| 17 | + * contributors may be used to endorse or promote products derived |
| 18 | + * from this software without specific prior written permission. |
| 19 | + * |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 23 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 24 | + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 26 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 27 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 28 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 29 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 30 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 31 | + * POSSIBILITY OF SUCH DAMAGE. |
| 32 | + * |
| 33 | + * authors: |
| 34 | + * Justus Braun <[email protected]> |
| 35 | + * |
| 36 | + */ |
| 37 | + |
| 38 | +#ifndef MESH_MAP__FREESPACE_LAYER_H |
| 39 | +#define MESH_MAP__FREESPACE_LAYER_H |
| 40 | + |
| 41 | +#include <mesh_map/abstract_layer.h> |
| 42 | +#include <rclcpp/rclcpp.hpp> |
| 43 | + |
| 44 | +namespace mesh_layers |
| 45 | +{ |
| 46 | +/** |
| 47 | + * @brief Costmap layer which calculates the free space in the direction of the vertex normals |
| 48 | + */ |
| 49 | +class ClearanceLayer : public mesh_map::AbstractLayer |
| 50 | +{ |
| 51 | + /** |
| 52 | + * @brief try read layer from map file |
| 53 | + * |
| 54 | + * @return true if successul; else false |
| 55 | + */ |
| 56 | + virtual bool readLayer() override; |
| 57 | + |
| 58 | + /** |
| 59 | + * @brief try to write layer to map file |
| 60 | + * |
| 61 | + * @return true if successfull; else false |
| 62 | + */ |
| 63 | + virtual bool writeLayer() override; |
| 64 | + |
| 65 | + /** |
| 66 | + * @brief delivers the default layer value |
| 67 | + * |
| 68 | + * @return default value used for this layer |
| 69 | + */ |
| 70 | + virtual float defaultValue() override |
| 71 | + { |
| 72 | + return std::numeric_limits<float>::infinity(); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * @brief delivers the threshold above which vertices are marked lethal |
| 77 | + * |
| 78 | + * @return lethal threshold |
| 79 | + */ |
| 80 | + virtual float threshold() override; |
| 81 | + |
| 82 | + /** |
| 83 | + * @brief calculate the values of this layer |
| 84 | + * |
| 85 | + * @return true if successfull; else false |
| 86 | + */ |
| 87 | + virtual bool computeLayer() override; |
| 88 | + |
| 89 | + /** |
| 90 | + * @brief deliver the current costmap |
| 91 | + * |
| 92 | + * @return calculated costmap |
| 93 | + */ |
| 94 | + virtual lvr2::VertexMap<float>& costs() override; |
| 95 | + |
| 96 | + /** |
| 97 | + * @brief deliver set containing all vertices marked as lethal |
| 98 | + * |
| 99 | + * @return lethal vertices |
| 100 | + */ |
| 101 | + virtual std::set<lvr2::VertexHandle>& lethals() override |
| 102 | + { |
| 103 | + return lethal_vertices_; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @brief update set of lethal vertices by adding and removing vertices |
| 108 | + * |
| 109 | + * @param added_lethal vertices to be marked as lethal |
| 110 | + * @param removed_lethal vertices to be removed from the set of lethal vertices |
| 111 | + */ |
| 112 | + virtual void updateLethal(std::set<lvr2::VertexHandle>& added_lethal, std::set<lvr2::VertexHandle>& removed_lethal) override {}; |
| 113 | + |
| 114 | + /** |
| 115 | + * @brief initializes this layer plugin |
| 116 | + * |
| 117 | + * @return true if initialization was successfull; else false |
| 118 | + */ |
| 119 | + virtual bool initialize() override; |
| 120 | + |
| 121 | + /** |
| 122 | + * @brief callback for incoming param changes |
| 123 | + */ |
| 124 | + rcl_interfaces::msg::SetParametersResult reconfigureCallback(std::vector<rclcpp::Parameter> parameters); |
| 125 | + |
| 126 | +private: |
| 127 | + /** |
| 128 | + * @brief mark vertices without enough clearance as lethal and compute the costs |
| 129 | + * |
| 130 | + * @return true if successfull; else false |
| 131 | + */ |
| 132 | + bool computeLethalsAndCosts(); |
| 133 | + |
| 134 | + // distance along vertex normal until the next face |
| 135 | + lvr2::DenseVertexMap<float> clearance_; |
| 136 | + // Actual costs values |
| 137 | + lvr2::DenseVertexMap<float> costs_; |
| 138 | + // set of all current lethal vertices |
| 139 | + std::set<lvr2::VertexHandle> lethal_vertices_; |
| 140 | + |
| 141 | + rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr dyn_params_handler_; |
| 142 | + struct { |
| 143 | + double robot_height = 0.5; |
| 144 | + double height_inflation = 0.3; |
| 145 | + double factor = 1.0; |
| 146 | + } config_; |
| 147 | +}; |
| 148 | + |
| 149 | +} /* namespace mesh_layers */ |
| 150 | + |
| 151 | +#endif // MESH_MAP__FREESPACE_LAYER_H |
0 commit comments