Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nav2_smac_planner/src/node_hybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ MotionPoses HybridMotionTable::getProjections(const NodeHybrid * node)

unsigned int HybridMotionTable::getClosestAngularBin(const double & theta)
{
return static_cast<unsigned int>(floor(theta / bin_size));
return static_cast<unsigned int>(floor(static_cast<float>(theta) / bin_size));
}

float HybridMotionTable::getAngleFromBin(const unsigned int & bin_idx)
Expand Down
30 changes: 30 additions & 0 deletions nav2_smac_planner/test/test_nodehybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,33 @@ TEST(NodeHybridTest, test_node_reeds_neighbors)
// should be empty since totally invalid
EXPECT_EQ(neighbors.size(), 0u);
}

TEST(NodeHybridTest, basic_get_closest_angular_bin_test)
{
// Tests to check getClosestAngularBin behavior for different input types
nav2_smac_planner::HybridMotionTable motion_table;

{
motion_table.bin_size = 3.1415926;
double test_theta = 3.1415926;
unsigned int expected_angular_bin = 1;
unsigned int calculated_angular_bin = motion_table.getClosestAngularBin(test_theta);
EXPECT_EQ(expected_angular_bin, calculated_angular_bin);
}

{
motion_table.bin_size = M_PI;
double test_theta = M_PI;
unsigned int expected_angular_bin = 1;
unsigned int calculated_angular_bin = motion_table.getClosestAngularBin(test_theta);
EXPECT_EQ(expected_angular_bin, calculated_angular_bin);
}

{
motion_table.bin_size = M_PI;
float test_theta = M_PI;
unsigned int expected_angular_bin = 1;
unsigned int calculated_angular_bin = motion_table.getClosestAngularBin(test_theta);
EXPECT_EQ(expected_angular_bin, calculated_angular_bin);
}
}