Skip to content

Commit 3ec1454

Browse files
Adding additional SmacPlanner tests (#2036)
* adding some more tests to smac_planner * addtl smac tests * remove unused functions
1 parent a71a5f2 commit 3ec1454

File tree

8 files changed

+65
-59
lines changed

8 files changed

+65
-59
lines changed

smac_planner/include/smac_planner/a_star.hpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,49 @@ class AStarAlgorithm
173173
*/
174174
int & getMaxIterations();
175175

176-
private:
177176
/**
178177
* @brief Get pointer reference to starting node
179178
* @return Node pointer reference to starting node
180179
*/
181-
inline NodePtr & getStart();
180+
NodePtr & getStart();
182181

183182
/**
184183
* @brief Get pointer reference to goal node
185184
* @return Node pointer reference to goal node
186185
*/
187-
inline NodePtr & getGoal();
186+
NodePtr & getGoal();
188187

188+
/**
189+
* @brief Get maximum number of on-approach iterations after within threshold
190+
* @return Reference to Maximum on-appraoch iterations parameter
191+
*/
192+
int & getOnApproachMaxIterations();
193+
194+
/**
195+
* @brief Get tolerance, in node nodes
196+
* @return Reference to tolerance parameter
197+
*/
198+
float & getToleranceHeuristic();
199+
200+
/**
201+
* @brief Get size of graph in X
202+
* @return Size in X
203+
*/
204+
unsigned int & getSizeX();
205+
206+
/**
207+
* @brief Get size of graph in Y
208+
* @return Size in Y
209+
*/
210+
unsigned int & getSizeY();
211+
212+
/**
213+
* @brief Get number of angle quantization bins (SE2) or Z coordinate (XYZ)
214+
* @return Number of angle bins / Z dimension
215+
*/
216+
unsigned int & getSizeDim3();
217+
218+
protected:
189219
/**
190220
* @brief Get pointer to next goal in open set
191221
* @return Node pointer reference to next heuristically scored node
@@ -242,36 +272,6 @@ class AStarAlgorithm
242272
*/
243273
inline bool areInputsValid();
244274

245-
/**
246-
* @brief Get maximum number of on-approach iterations after within threshold
247-
* @return Reference to Maximum on-appraoch iterations parameter
248-
*/
249-
inline int & getOnApproachMaxIterations();
250-
251-
/**
252-
* @brief Get tolerance, in node nodes
253-
* @return Reference to tolerance parameter
254-
*/
255-
inline float & getToleranceHeuristic();
256-
257-
/**
258-
* @brief Get size of graph in X
259-
* @return Size in X
260-
*/
261-
inline unsigned int & getSizeX();
262-
263-
/**
264-
* @brief Get size of graph in Y
265-
* @return Size in Y
266-
*/
267-
inline unsigned int & getSizeY();
268-
269-
/**
270-
* @brief Get number of angle quantization bins (SE2) or Z coordinate (XYZ)
271-
* @return Number of angle bins / Z dimension
272-
*/
273-
inline unsigned int & getSizeDim3();
274-
275275
/**
276276
* @brief Clear hueristic queue of nodes to search
277277
*/

smac_planner/include/smac_planner/costmap_downsampler.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ class CostmapDownsampler
7979
*/
8080
nav2_costmap_2d::Costmap2D * downsample(const unsigned int & downsampling_factor);
8181

82-
private:
83-
/**
84-
* @brief Update the sizes X-Y of the costmap and its downsampled version
85-
*/
86-
void updateCostmapSize();
8782
/**
8883
* @brief Resize the downsampled costmap. Used in case the costmap changes and we need to update the downsampled version
8984
*/
9085
void resizeCostmap();
86+
87+
protected:
88+
/**
89+
* @brief Update the sizes X-Y of the costmap and its downsampled version
90+
*/
91+
void updateCostmapSize();
92+
9193
/**
9294
* @brief Explore all subcells of the original costmap and assign the max cost to the new (downsampled) cell
9395
* @param new_mx The X-coordinate of the cell in the new costmap

smac_planner/include/smac_planner/node_basic.hpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,13 @@ class NodeBasic
5050
* @param index The index of this node for self-reference
5151
*/
5252
explicit NodeBasic(const unsigned int index)
53-
: _index(index),
53+
: index(index),
5454
graph_node_ptr(nullptr)
5555
{}
5656

57-
/**
58-
* @brief A destructor for smac_planner::NodeBasic
59-
*/
60-
~NodeBasic() {}
61-
62-
/**
63-
* @brief Gets cell index
64-
* @return Reference to cell index
65-
*/
66-
inline unsigned int & getIndex()
67-
{
68-
return _index;
69-
}
70-
7157
typename NodeT::Coordinates pose; // Used by NodeSE2
7258
NodeT * graph_node_ptr;
73-
74-
protected:
75-
unsigned int _index;
59+
unsigned int index;
7660
};
7761

7862
template class NodeBasic<Node2D>;

smac_planner/test/test_a_star.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,23 @@ TEST(AStarTest, test_a_star_2d)
106106
EXPECT_EQ(costmapA->getCost(path[i].x, path[i].y), 0);
107107
}
108108

109+
EXPECT_TRUE(a_star_2.getStart() != nullptr);
110+
EXPECT_TRUE(a_star_2.getGoal() != nullptr);
111+
EXPECT_EQ(a_star_2.getSizeX(), 100u);
112+
EXPECT_EQ(a_star_2.getSizeY(), 100u);
113+
EXPECT_EQ(a_star_2.getSizeDim3(), 1u);
114+
EXPECT_EQ(a_star_2.getToleranceHeuristic(), 1000.0);
115+
EXPECT_EQ(a_star_2.getOnApproachMaxIterations(), 10);
116+
109117
delete costmapA;
118+
119+
Eigen::Vector2d p1;
120+
p1[0] = 0.0;
121+
p1[1] = 0.0;
122+
Eigen::Vector2d p2;
123+
p2[0] = 0.0;
124+
p2[1] = 1.0;
125+
EXPECT_NEAR(smac_planner::squaredDistance(p1, p2), 1.0, 0.001);
110126
}
111127

112128
TEST(AStarTest, test_a_star_se2)

smac_planner/test/test_costmap_downsampler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ TEST(CostmapDownsampler, costmap_downsample_test)
5454
EXPECT_EQ(downsampledCostmapA->getSizeInCellsY(), 5u);
5555

5656
// give it another costmap of another size
57-
nav2_costmap_2d::Costmap2D costmapB(4, 4, 0.05, 0.0, 0.0, 0);
57+
nav2_costmap_2d::Costmap2D costmapB(4, 4, 0.10, 0.0, 0.0, 0);
5858

5959
// downsample it
6060
downsampler.initialize("map", "unused_topic", &costmapB, 4);
@@ -65,4 +65,6 @@ TEST(CostmapDownsampler, costmap_downsample_test)
6565
// validate size
6666
EXPECT_EQ(downsampledCostmapB->getSizeInCellsX(), 1u);
6767
EXPECT_EQ(downsampledCostmapB->getSizeInCellsY(), 1u);
68+
69+
downsampler.resizeCostmap();
6870
}

smac_planner/test/test_node2d.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ TEST(Node2DTest, test_node_2d)
9292
EXPECT_EQ(smac_planner::Node2D::getIndex(6u, 43u, 10u), 436u);
9393
EXPECT_EQ(smac_planner::Node2D::getCoords(436u, 10u, 1u).x, 6u);
9494
EXPECT_EQ(smac_planner::Node2D::getCoords(436u, 10u, 1u).y, 43u);
95+
EXPECT_THROW(smac_planner::Node2D::getCoords(436u, 10u, 10u), std::runtime_error);
9596
}
9697

9798
TEST(Node2DTest, test_node_2d_neighbors)

smac_planner/test/test_nodebasic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ TEST(NodeBasicTest, test_node_basic)
3939
{
4040
smac_planner::NodeBasic<smac_planner::NodeSE2> node(50);
4141

42-
EXPECT_EQ(node.getIndex(), 50u);
42+
EXPECT_EQ(node.index, 50u);
4343
EXPECT_EQ(node.graph_node_ptr, nullptr);
4444

4545
smac_planner::NodeBasic<smac_planner::Node2D> node2(100);
4646

47-
EXPECT_EQ(node2.getIndex(), 100u);
47+
EXPECT_EQ(node2.index, 100u);
4848
EXPECT_EQ(node2.graph_node_ptr, nullptr);
4949
}

smac_planner/test/test_smoother.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ TEST(SmootherTest, test_smoother)
7676
}
7777

7878
smac_planner::OptimizerParams params;
79+
params.debug = true;
7980
params.get(node2D.get(), "test");
8081

8182
smac_planner::SmootherParams smoother_params;

0 commit comments

Comments
 (0)