Skip to content

Commit fcd2975

Browse files
authored
backport the fix for setting binary_state as the default (#5459)
Signed-off-by: olaghattas <olaghattas@hotmail.com>
1 parent a18aa6a commit fcd2975

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

‎nav2_costmap_2d/plugins/costmap_filters/binary_filter.cpp‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ void BinaryFilter::initializeFilter(
9696
base_ = BASE_DEFAULT;
9797
multiplier_ = MULTIPLIER_DEFAULT;
9898

99-
// Initialize state as "false" by-default
100-
changeState(default_state_);
99+
// Initialize state binary_state_ which at start its equal to default_state_
100+
changeState(binary_state_);
101101
}
102102

103103
void BinaryFilter::filterInfoCallback(
@@ -224,8 +224,11 @@ void BinaryFilter::resetFilter()
224224
{
225225
std::lock_guard<CostmapFilter::mutex_t> guard(*getMutex());
226226

227-
RCLCPP_INFO(logger_, "BinaryFilter: Resetting the filter to default state");
228-
changeState(default_state_);
227+
// Publishing new BinaryState in reset
228+
std::unique_ptr<std_msgs::msg::Bool> msg =
229+
std::make_unique<std_msgs::msg::Bool>();
230+
msg->data = binary_state_;
231+
binary_state_pub_->publish(std::move(msg));
229232

230233
filter_info_sub_.reset();
231234
mask_sub_.reset();

‎nav2_costmap_2d/test/unit/binary_filter_test.cpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class TestNode : public ::testing::Test
235235
std::shared_ptr<nav2_costmap_2d::Costmap2D> master_grid_;
236236

237237
bool default_state_;
238+
bool binary_state_;
238239

239240
private:
240241
void waitSome(const std::chrono::nanoseconds & duration);
@@ -674,12 +675,13 @@ void TestNode::testResetFilter()
674675
binary_filter_->process(*master_grid_, min_i, min_j, max_i, max_j, pose);
675676
binary_state = waitBinaryState();
676677
verifyBinaryState(getSign(pose.x, pose.y, base, multiplier, flip_threshold), binary_state);
678+
binary_state_ = binary_state->data;
677679

678-
// Reset binary filter and check its state was resetted to default
680+
// Reset binary filter and check its state was resetted to binary_state_
679681
binary_filter_->resetFilter();
680682
binary_state = waitBinaryState();
681683
ASSERT_TRUE(binary_state != nullptr);
682-
ASSERT_EQ(binary_state->data, default_state_);
684+
ASSERT_EQ(binary_state->data, binary_state_);
683685
}
684686

685687
void TestNode::resetMaps()

0 commit comments

Comments
 (0)