Skip to content

Commit

Permalink
reload behavior tree before creating RosTopicLogger to prevent nullpt…
Browse files Browse the repository at this point in the history
…r error or no /behavior_tree_log problem (#1849)

Signed-off-by: Daisuke Sato <daisukes@cmu.edu>
  • Loading branch information
daisukes authored Jul 9, 2020
1 parent 3dcd589 commit 69977cd
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions nav2_bt_navigator/src/bt_navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ BtNavigator::navigateToPose()
return action_server_->is_cancel_requested();
};

auto bt_xml_filename = action_server_->get_current_goal()->behavior_tree;

// Empty id in request is default for backward compatibility
bt_xml_filename = bt_xml_filename == "" ? default_bt_xml_filename_ : bt_xml_filename;

if (!loadBehaviorTree(bt_xml_filename)) {
RCLCPP_ERROR(
get_logger(), "BT file not found: %s. Navigation canceled",
bt_xml_filename.c_str(), current_bt_xml_filename_.c_str());
action_server_->terminate_current();
return;
}

RosTopicLogger topic_logger(client_node_, tree_);
std::shared_ptr<Action::Feedback> feedback_msg = std::make_shared<Action::Feedback>();

Expand Down Expand Up @@ -276,19 +289,6 @@ BtNavigator::navigateToPose()
action_server_->publish_feedback(feedback_msg);
};

auto bt_xml_filename = action_server_->get_current_goal()->behavior_tree;

// Empty id in request is default for backward compatibility
bt_xml_filename = bt_xml_filename == "" ? default_bt_xml_filename_ : bt_xml_filename;

if (!loadBehaviorTree(bt_xml_filename)) {
RCLCPP_ERROR(
get_logger(), "BT file not found: %s. Navigation canceled",
bt_xml_filename.c_str(), current_bt_xml_filename_.c_str());
action_server_->terminate_current();
return;
}

// Execute the BT that was previously created in the configure step
nav2_behavior_tree::BtStatus rc = bt_->run(&tree_, on_loop, is_canceling);
// Make sure that the Bt is not in a running state from a previous execution
Expand Down

0 comments on commit 69977cd

Please sign in to comment.