Skip to content

Commit 30d3aff

Browse files
AzaelCiceroKrzysztof Pawełczyk
andauthored
4320: Changed precision of calculations of the HybridNode MotionTable::getClosestAngularBin. (#4324)
Signed-off-by: Krzysztof Pawełczyk <[email protected]> Co-authored-by: Krzysztof Pawełczyk <[email protected]>
1 parent 7ef4473 commit 30d3aff

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

nav2_smac_planner/src/node_hybrid.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ MotionPoses HybridMotionTable::getProjections(const NodeHybrid * node)
330330

331331
unsigned int HybridMotionTable::getClosestAngularBin(const double & theta)
332332
{
333-
return static_cast<unsigned int>(floor(static_cast<float>(theta) / bin_size));
333+
return static_cast<unsigned int>(floor(theta / static_cast<double>(bin_size))) %
334+
num_angle_quantization;
334335
}
335336

336337
float HybridMotionTable::getAngleFromBin(const unsigned int & bin_idx)

nav2_smac_planner/test/test_nodehybrid.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License. Reserved.
1414

1515
#include <math.h>
16+
#include <cmath>
1617
#include <memory>
1718
#include <string>
1819
#include <vector>
@@ -384,6 +385,7 @@ TEST(NodeHybridTest, basic_get_closest_angular_bin_test)
384385

385386
{
386387
motion_table.bin_size = 3.1415926;
388+
motion_table.num_angle_quantization = 2;
387389
double test_theta = 3.1415926;
388390
unsigned int expected_angular_bin = 1;
389391
unsigned int calculated_angular_bin = motion_table.getClosestAngularBin(test_theta);
@@ -392,17 +394,28 @@ TEST(NodeHybridTest, basic_get_closest_angular_bin_test)
392394

393395
{
394396
motion_table.bin_size = M_PI;
397+
motion_table.num_angle_quantization = 2;
395398
double test_theta = M_PI;
396-
unsigned int expected_angular_bin = 1;
399+
unsigned int expected_angular_bin = 0;
397400
unsigned int calculated_angular_bin = motion_table.getClosestAngularBin(test_theta);
398401
EXPECT_EQ(expected_angular_bin, calculated_angular_bin);
399402
}
400403

401404
{
402405
motion_table.bin_size = M_PI;
406+
motion_table.num_angle_quantization = 2;
403407
float test_theta = M_PI;
404408
unsigned int expected_angular_bin = 1;
405409
unsigned int calculated_angular_bin = motion_table.getClosestAngularBin(test_theta);
406410
EXPECT_EQ(expected_angular_bin, calculated_angular_bin);
407411
}
412+
413+
{
414+
motion_table.bin_size = 0.0872664675;
415+
motion_table.num_angle_quantization = 72;
416+
double test_theta = 6.28318526567925;
417+
unsigned int expected_angular_bin = 71;
418+
unsigned int calculated_angular_bin = motion_table.getClosestAngularBin(test_theta);
419+
EXPECT_EQ(expected_angular_bin, calculated_angular_bin);
420+
}
408421
}

0 commit comments

Comments
 (0)