Skip to content

Commit

Permalink
Merge branch 'main' into add_polygon_velocity
Browse files Browse the repository at this point in the history
  • Loading branch information
kaichie committed Nov 16, 2023
2 parents 5dc403b + 600633a commit 3db0146
Show file tree
Hide file tree
Showing 236 changed files with 5,316 additions and 2,829 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
For detailed instructions on how to:
- [Getting Started](https://navigation.ros.org/getting_started/index.html)
- [Concepts](https://navigation.ros.org/concepts/index.html)
- [Build](https://navigation.ros.org/build_instructions/index.html#build)
- [Install](https://navigation.ros.org/build_instructions/index.html#install)
- [Build](https://navigation.ros.org/development_guides/build_docs/index.html#build)
- [Install](https://navigation.ros.org/development_guides/build_docs/index.html#install)
- [General Tutorials](https://navigation.ros.org/tutorials/index.html) and [Algorithm Developer Tutorials](https://navigation.ros.org/plugin_tutorials/index.html)
- [Configure](https://navigation.ros.org/configuration/index.html)
- [Navigation Plugins](https://navigation.ros.org/plugins/index.html)
Expand Down
4 changes: 2 additions & 2 deletions nav2_amcl/include/nav2_amcl/pf/pf_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef struct


// Return a zero vector
pf_vector_t pf_vector_zero();
pf_vector_t pf_vector_zero(void);

// Check for NAN or INF in any component
// int pf_vector_finite(pf_vector_t a);
Expand All @@ -71,7 +71,7 @@ pf_vector_t pf_vector_coord_add(pf_vector_t a, pf_vector_t b);


// Return a zero matrix
pf_matrix_t pf_matrix_zero();
pf_matrix_t pf_matrix_zero(void);

// Check for NAN or INF in any component
// int pf_matrix_finite(pf_matrix_t a);
Expand Down
5 changes: 0 additions & 5 deletions nav2_amcl/src/pf/pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ void pf_cluster_stats(pf_t * pf, pf_sample_set_t * set)

// Workspace
double m[4], c[2][2];
size_t count;
double weight;

// Cluster the samples
Expand All @@ -474,7 +473,6 @@ void pf_cluster_stats(pf_t * pf, pf_sample_set_t * set)

for (i = 0; i < set->cluster_max_count; i++) {
cluster = set->clusters + i;
cluster->count = 0;
cluster->weight = 0;
cluster->mean = pf_vector_zero();
cluster->cov = pf_matrix_zero();
Expand All @@ -490,7 +488,6 @@ void pf_cluster_stats(pf_t * pf, pf_sample_set_t * set)
}

// Initialize overall filter stats
count = 0;
weight = 0.0;
set->mean = pf_vector_zero();
set->cov = pf_matrix_zero();
Expand Down Expand Up @@ -521,10 +518,8 @@ void pf_cluster_stats(pf_t * pf, pf_sample_set_t * set)

cluster = set->clusters + cidx;

cluster->count += 1;
cluster->weight += sample->weight;

count += 1;
weight += sample->weight;

// Compute mean
Expand Down
4 changes: 2 additions & 2 deletions nav2_amcl/src/pf/pf_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


// Return a zero vector
pf_vector_t pf_vector_zero()
pf_vector_t pf_vector_zero(void)
{
pf_vector_t c;

Expand Down Expand Up @@ -130,7 +130,7 @@ pf_vector_t pf_vector_coord_add(pf_vector_t a, pf_vector_t b)


// Return a zero matrix
pf_matrix_t pf_matrix_zero()
pf_matrix_t pf_matrix_zero(void)
{
int i, j;
pf_matrix_t c;
Expand Down
6 changes: 6 additions & 0 deletions nav2_amcl/src/sensors/laser/beam_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ BeamModel::sensorFunction(LaserData * data, pf_sample_set_t * set)
step = (data->range_count - 1) / (self->max_beams_ - 1);
for (i = 0; i < data->range_count; i += step) {
obs_range = data->ranges[i][0];

// Check for NaN
if (isnan(obs_range)) {
continue;
}

obs_bearing = data->ranges[i][1];

// Compute the range according to the map
Expand Down
2 changes: 1 addition & 1 deletion nav2_behavior_tree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ The BehaviorTree engine has a run method that accepts an XML description of a BT
See the code in the [BT Navigator](../nav2_bt_navigator/src/bt_navigator.cpp) for an example usage of the BehaviorTreeEngine.
For more information about the behavior tree nodes that are available in the default BehaviorTreeCPP library, see documentation here: https://www.behaviortree.dev/docs/learn-the-basics/bt_basics/
For more information about the behavior tree nodes that are available in the default BehaviorTreeCPP library, see documentation here: https://www.behaviortree.dev/docs/3.8/learn-the-basics/BT_basics
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class BehaviorTreeEngine

/**
* @brief Function to explicitly reset all BT nodes to initial state
* @param root_node Pointer to BT root node
* @param tree Tree to halt
*/
void haltAllActions(BT::TreeNode * root_node);
void haltAllActions(BT::Tree & tree);

protected:
// The factory that will be used to dynamically construct the behavior tree
Expand Down
21 changes: 17 additions & 4 deletions nav2_behavior_tree/include/nav2_behavior_tree/bt_action_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class BtActionNode : public BT::ActionNodeBase
}

/**
* @brief Function to perform some user-defined operation whe the action is aborted.
* @brief Function to perform some user-defined operation when the action is aborted.
* @return BT::NodeStatus Returns FAILURE by default, user may override return another value
*/
virtual BT::NodeStatus on_aborted()
Expand Down Expand Up @@ -206,7 +206,8 @@ class BtActionNode : public BT::ActionNodeBase
// if new goal was sent and action server has not yet responded
// check the future goal handle
if (future_goal_handle_) {
auto elapsed = (node_->now() - time_goal_sent_).to_chrono<std::chrono::milliseconds>();
auto elapsed =
(node_->now() - time_goal_sent_).template to_chrono<std::chrono::milliseconds>();
if (!is_future_goal_handle_complete(elapsed)) {
// return RUNNING if there is still some time before timeout happens
if (elapsed < server_timeout_) {
Expand Down Expand Up @@ -237,7 +238,8 @@ class BtActionNode : public BT::ActionNodeBase
{
goal_updated_ = false;
send_new_goal();
auto elapsed = (node_->now() - time_goal_sent_).to_chrono<std::chrono::milliseconds>();
auto elapsed =
(node_->now() - time_goal_sent_).template to_chrono<std::chrono::milliseconds>();
if (!is_future_goal_handle_complete(elapsed)) {
if (elapsed < server_timeout_) {
return BT::NodeStatus::RUNNING;
Expand Down Expand Up @@ -266,7 +268,7 @@ class BtActionNode : public BT::ActionNodeBase
// Action related failure that should not fail the tree, but the node
return BT::NodeStatus::FAILURE;
} else {
// Internal exception to propogate to the tree
// Internal exception to propagate to the tree
throw e;
}
}
Expand Down Expand Up @@ -300,6 +302,7 @@ class BtActionNode : public BT::ActionNodeBase
void halt() override
{
if (should_cancel_goal()) {
auto future_result = action_client_->async_get_result(goal_handle_);
auto future_cancel = action_client_->async_cancel_goal(goal_handle_);
if (callback_group_executor_.spin_until_future_complete(future_cancel, server_timeout_) !=
rclcpp::FutureReturnCode::SUCCESS)
Expand All @@ -308,6 +311,16 @@ class BtActionNode : public BT::ActionNodeBase
node_->get_logger(),
"Failed to cancel action server for %s", action_name_.c_str());
}

if (callback_group_executor_.spin_until_future_complete(future_result, server_timeout_) !=
rclcpp::FutureReturnCode::SUCCESS)
{
RCLCPP_ERROR(
node_->get_logger(),
"Failed to get result for %s in node halt!", action_name_.c_str());
}

on_cancelled();
}

setStatus(BT::NodeStatus::IDLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ class BtActionServer
/**
* @brief Function to halt the current tree. It will interrupt the execution of RUNNING nodes
* by calling their halt() implementation (only for Async nodes that may return RUNNING)
* This should already done for all the exit states of the action but preemption
*/
void haltTree()
{
tree_.rootNode()->halt();
tree_.haltTree();
}

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ bool BtActionServer<ActionT>::on_cleanup()
plugin_lib_names_.clear();
current_bt_xml_filename_.clear();
blackboard_.reset();
bt_->haltAllActions(tree_.rootNode());
bt_->haltAllActions(tree_);
bt_.reset();
return true;
}
Expand Down Expand Up @@ -231,6 +231,11 @@ bool BtActionServer<ActionT>::loadBehaviorTree(const std::string & bt_xml_filena
// Create the Behavior Tree from the XML input
try {
tree_ = bt_->createTreeFromFile(filename, blackboard_);
for (auto & blackboard : tree_.blackboard_stack) {
blackboard->set<rclcpp::Node::SharedPtr>("node", client_node_);
blackboard->set<std::chrono::milliseconds>("server_timeout", default_server_timeout_);
blackboard->set<std::chrono::milliseconds>("bt_loop_duration", bt_loop_duration_);
}
} catch (const std::exception & e) {
RCLCPP_ERROR(logger_, "Exception when loading BT: %s", e.what());
return false;
Expand Down Expand Up @@ -276,7 +281,7 @@ void BtActionServer<ActionT>::executeCallback()

// Make sure that the Bt is not in a running state from a previous execution
// note: if all the ControlNodes are implemented correctly, this is not needed.
bt_->haltAllActions(tree_.rootNode());
bt_->haltAllActions(tree_);

// Give server an opportunity to populate the result message or simple give
// an indication that the action is complete.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class BtCancelActionNode : public BT::ActionNodeBase
return basic;
}

void halt()
void halt() override
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class BtServiceNode : public BT::ActionNodeBase
*/
virtual BT::NodeStatus check_future()
{
auto elapsed = (node_->now() - sent_time_).to_chrono<std::chrono::milliseconds>();
auto elapsed = (node_->now() - sent_time_).template to_chrono<std::chrono::milliseconds>();
auto remaining = server_timeout_ - elapsed;

if (remaining > std::chrono::milliseconds(0)) {
Expand All @@ -199,7 +199,7 @@ class BtServiceNode : public BT::ActionNodeBase

if (rc == rclcpp::FutureReturnCode::TIMEOUT) {
on_wait_for_result();
elapsed = (node_->now() - sent_time_).to_chrono<std::chrono::milliseconds>();
elapsed = (node_->now() - sent_time_).template to_chrono<std::chrono::milliseconds>();
if (elapsed < server_timeout_) {
return BT::NodeStatus::RUNNING;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RemovePassedGoals : public BT::ActionNodeBase
double viapoint_achieved_radius_;
double transform_tolerance_;
std::shared_ptr<tf2_ros::Buffer> tf_;
std::string global_frame_, robot_base_frame_;
std::string robot_base_frame_;
};

} // namespace nav2_behavior_tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class WaitAction : public BtActionNode<nav2_msgs::action::Wait>
{
return providedBasicPorts(
{
BT::InputPort<int>("wait_duration", 1, "Wait time")
BT::InputPort<double>("wait_duration", 1.0, "Wait time")
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class GoalReachedCondition : public BT::ConditionNode
bool initialized_;
double goal_reached_tol_;
double transform_tolerance_;
std::string global_frame_, robot_base_frame_;
std::string robot_base_frame_;
};

} // namespace nav2_behavior_tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ RemovePassedGoals::RemovePassedGoals(
auto node = config().blackboard->get<rclcpp::Node::SharedPtr>("node");
node->get_parameter("transform_tolerance", transform_tolerance_);

global_frame_ = BT::deconflictPortAndParamFrame<std::string, RemovePassedGoals>(
node, "global_frame", this);
robot_base_frame_ = BT::deconflictPortAndParamFrame<std::string, RemovePassedGoals>(
node, "robot_base_frame", this);
}
Expand All @@ -59,7 +57,7 @@ inline BT::NodeStatus RemovePassedGoals::tick()

geometry_msgs::msg::PoseStamped current_pose;
if (!nav2_util::getCurrentPose(
current_pose, *tf_, global_frame_, robot_base_frame_,
current_pose, *tf_, goal_poses[0].header.frame_id, robot_base_frame_,
transform_tolerance_))
{
return BT::NodeStatus::FAILURE;
Expand Down
7 changes: 4 additions & 3 deletions nav2_behavior_tree/plugins/action/wait_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <string>
#include <memory>
#include <cmath>

#include "nav2_behavior_tree/plugins/action/wait_action.hpp"

Expand All @@ -26,16 +27,16 @@ WaitAction::WaitAction(
const BT::NodeConfiguration & conf)
: BtActionNode<nav2_msgs::action::Wait>(xml_tag_name, action_name, conf)
{
int duration;
double duration;
getInput("wait_duration", duration);
if (duration <= 0) {
RCLCPP_WARN(
node_->get_logger(), "Wait duration is negative or zero "
"(%i). Setting to positive.", duration);
"(%f). Setting to positive.", duration);
duration *= -1;
}

goal_.time.sec = duration;
goal_.time = rclcpp::Duration::from_seconds(duration);
}

void WaitAction::on_tick()
Expand Down
10 changes: 4 additions & 6 deletions nav2_behavior_tree/plugins/condition/goal_reached_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ GoalReachedCondition::GoalReachedCondition(
{
auto node = config().blackboard->get<rclcpp::Node::SharedPtr>("node");

global_frame_ = BT::deconflictPortAndParamFrame<std::string, GoalReachedCondition>(
node, "global_frame", this);
robot_base_frame_ = BT::deconflictPortAndParamFrame<std::string, GoalReachedCondition>(
node, "robot_base_frame", this);
}
Expand Down Expand Up @@ -73,17 +71,17 @@ void GoalReachedCondition::initialize()

bool GoalReachedCondition::isGoalReached()
{
geometry_msgs::msg::PoseStamped current_pose;
geometry_msgs::msg::PoseStamped goal;
getInput("goal", goal);

geometry_msgs::msg::PoseStamped current_pose;
if (!nav2_util::getCurrentPose(
current_pose, *tf_, global_frame_, robot_base_frame_, transform_tolerance_))
current_pose, *tf_, goal.header.frame_id, robot_base_frame_, transform_tolerance_))
{
RCLCPP_DEBUG(node_->get_logger(), "Current robot pose is not available.");
return false;
}

geometry_msgs::msg::PoseStamped goal;
getInput("goal", goal);
double dx = goal.pose.position.x - current_pose.pose.position.x;
double dy = goal.pose.position.y - current_pose.pose.position.y;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void IsStuckCondition::logStuck(const std::string & msg) const
return;
}

RCLCPP_INFO(node_->get_logger(), msg.c_str());
RCLCPP_INFO(node_->get_logger(), "%s", msg.c_str());
prev_msg = msg;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TransformAvailableCondition::TransformAvailableCondition(
RCLCPP_FATAL(
node_->get_logger(), "Child frame (%s) or parent frame (%s) were empty.",
child_frame_.c_str(), parent_frame_.c_str());
exit(-1);
throw std::runtime_error("TransformAvailableCondition: Child or parent frames not provided!");
}

RCLCPP_DEBUG(node_->get_logger(), "Initialized an TransformAvailableCondition BT node");
Expand Down
2 changes: 1 addition & 1 deletion nav2_behavior_tree/plugins/decorator/speed_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SpeedController::SpeedController(

if (min_rate_ <= 0.0 || max_rate_ <= 0.0) {
std::string err_msg = "SpeedController node cannot have rate <= 0.0";
RCLCPP_FATAL(node_->get_logger(), err_msg.c_str());
RCLCPP_FATAL(node_->get_logger(), "%s", err_msg.c_str());
throw BT::BehaviorTreeException(err_msg);
}

Expand Down
Loading

0 comments on commit 3db0146

Please sign in to comment.