Skip to content

Commit cd08071

Browse files
Port/traversability (#101)
* WIP: part 1 * Port traversability: Part 2/2 * updates to new hydra architecture and few missed updates, builds and passes tests * update gitignore * minor fixes and config * run linting * fix missing distance adaptor call * Update src/utils/nearest_neighbor_utilities.cpp Co-authored-by: Nathan Hughes <[email protected]> * address review comments * run linter --------- Co-authored-by: Nathan Hughes <[email protected]>
1 parent e669610 commit cd08071

File tree

11 files changed

+1567
-8
lines changed

11 files changed

+1567
-8
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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 <config_utilities/factory.h>
37+
#include <spark_dsg/traversability_boundary.h>
38+
39+
#include "hydra/backend/deformation_interpolator.h"
40+
#include "hydra/backend/update_functions.h"
41+
#include "hydra/utils/active_window_tracker.h"
42+
#include "hydra/utils/nearest_neighbor_utilities.h"
43+
44+
namespace hydra {
45+
46+
/**
47+
* @brief Functor to update traversability places in the DSG. This functor should be
48+
* called with exhaustive merging enabled.
49+
*/
50+
struct UpdateTraversabilityFunctor : public UpdateFunctor {
51+
struct Config {
52+
//! Layer to update traversability in
53+
std::string layer = DsgLayers::TRAVERSABILITY;
54+
55+
//! Minimum side length of a traversability area to be considered [m].
56+
double min_place_size = 0.5;
57+
58+
//! Maximum width of a place created in the active window [m].
59+
double max_place_size = 1.0;
60+
61+
//! Extra tolerance for connectivity distance and overlap checks for merging in
62+
//! meters.
63+
double tolerance = 0.1;
64+
65+
//! If false, compute the topoligcal distance to occupied space. If true, use metric
66+
//! distance.
67+
bool use_metric_distance = false;
68+
69+
DeformationInterpolator::Config deformation;
70+
} const config;
71+
72+
using EdgeSet = std::set<EdgeKey>;
73+
using NodeSet = std::set<NodeId>;
74+
using State = spark_dsg::TraversabilityState;
75+
76+
explicit UpdateTraversabilityFunctor(const Config& config);
77+
78+
Hooks hooks() const override;
79+
80+
void call(const DynamicSceneGraph& unmerged,
81+
SharedDsgInfo& dsg,
82+
const UpdateInfo::ConstPtr& info) const override;
83+
84+
protected:
85+
// Hook callbacks.
86+
MergeList findNodeMerges(const DynamicSceneGraph& dsg,
87+
const UpdateInfo::ConstPtr& info) const;
88+
89+
NodeAttributes::Ptr mergeNodes(const DynamicSceneGraph& dsg,
90+
const std::vector<NodeId>& merge_ids) const;
91+
92+
void cleanup(const UpdateInfo::ConstPtr& /* info */, SharedDsgInfo* dsg) const;
93+
94+
// Processing Steps.
95+
/**
96+
* @brief Update the positions of all traversability nodes in the DSG. Propagates to
97+
* the complete DSG in case of new loop closures.
98+
*/
99+
void updateDeformation(const DynamicSceneGraph& unmerged,
100+
SharedDsgInfo& dsg,
101+
const UpdateInfo::ConstPtr& info) const;
102+
103+
EdgeSet findActiveWindowEdges(DynamicSceneGraph& dsg) const;
104+
105+
void pruneActiveWindowEdges(DynamicSceneGraph& dsg,
106+
const EdgeSet& active_edges) const;
107+
108+
void updateDistances(const SceneGraphLayer& layer) const;
109+
110+
// Helper functions.
111+
112+
/**
113+
* @brief Find connections of places that should be considered for merging or
114+
* connection in the active window.
115+
*/
116+
std::vector<NodeId> findConnections(
117+
const DynamicSceneGraph& dsg,
118+
const TraversabilityNodeAttributes& from_attrs) const;
119+
120+
/**
121+
* @brief Check whether the two traversability areas overlap sufficiently to be
122+
* considered traversable in-place.
123+
*/
124+
bool hasTraversableOverlap(const TraversabilityNodeAttributes& from,
125+
const TraversabilityNodeAttributes& to) const;
126+
127+
/**
128+
* @brief Check whether the from boundary is contained in the in boundary.
129+
*/
130+
bool isContained(const Boundary& from, const Boundary& in) const;
131+
132+
/**
133+
* @brief Recursively compute the metrc distance to the nearest intraversable
134+
* obstacle for the query place.
135+
*/
136+
double computeMetricDistance(const SceneGraphLayer& layer,
137+
const Eigen::Vector2d& point,
138+
const NodeSet& to_visit,
139+
NodeSet& visited) const;
140+
141+
double distanceToIntraversable(const TraversabilityNodeAttributes& attrs,
142+
const Eigen::Vector2d& point) const;
143+
144+
void computeTopologicalDistances(const SceneGraphLayer& layer) const;
145+
146+
void resetNeighborFinder(const DynamicSceneGraph& dsg) const;
147+
148+
protected:
149+
// Cached constants.
150+
const double radius_;
151+
const double min_connectivity_;
152+
153+
// State.
154+
mutable EdgeSet previous_active_edges_;
155+
mutable std::set<EdgeKey> overlapping_nodes_to_cleanup_;
156+
157+
// Members.
158+
mutable ActiveWindowTracker active_tracker_;
159+
const DeformationInterpolator deformation_interpolator_;
160+
mutable NearestNodeFinder::Ptr nn_;
161+
};
162+
163+
void declare_config(UpdateTraversabilityFunctor::Config& config);
164+
165+
} // namespace hydra

include/hydra/places/traversability_layer.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ struct TraversabilityVoxel {
5858

5959
//! @brief Arbitrary debug value that can be set for viualization.
6060
// TODO(lschmid): Remove this at some point.
61-
mutable float debug_value = -1.0f;
61+
mutable float debug_value = 0.0f;
6262

63-
bool operator==(const TraversabilityVoxel& other) const {
64-
return traversability == other.traversability && confidence == other.confidence &&
65-
state == other.state;
66-
}
63+
bool operator==(const TraversabilityVoxel& other) const;
6764
};
6865

6966
// Voxel indices as pairs of (x, y) coordinates.

src/backend/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
target_sources(
22
${PROJECT_NAME}
33
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/association_strategies.cpp
4+
${CMAKE_CURRENT_SOURCE_DIR}/update_traversability_functor.cpp
45
${CMAKE_CURRENT_SOURCE_DIR}/backend_module.cpp
56
${CMAKE_CURRENT_SOURCE_DIR}/backend_utilities.cpp
67
${CMAKE_CURRENT_SOURCE_DIR}/deformation_interpolator.cpp

src/backend/backend_module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ void BackendModule::optimize(size_t timestamp_ns, bool force_find_merge) {
515515
[vertex_key](auto) { return vertex_key; });
516516
}
517517

518-
ScopedTimer timer("dsg_updater/optimization", timestamp_ns, true, 1, false);
518+
ScopedTimer timer("dsg_updater/optimization", timestamp_ns, true, 0, false);
519519
KimeraPgmoInterface::optimize();
520520
timer.stop();
521521

src/backend/dsg_updater.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void DsgUpdater::save(const DataDirectory& output, const std::string& label) con
8787
}
8888

8989
void DsgUpdater::resetBackendDsg(size_t timestamp_ns) {
90-
ScopedTimer timer("dsg_updater/reset_dsg", timestamp_ns, true, 1, false);
90+
ScopedTimer timer("dsg_updater/reset_dsg", timestamp_ns, true, 0, false);
9191
constexpr bool reset_mesh = false;
9292
{
9393
std::unique_lock<std::mutex> graph_lock(target_dsg_->mutex);

0 commit comments

Comments
 (0)