Skip to content

Commit 0acecdf

Browse files
committed
Implement for spin
1 parent 4382062 commit 0acecdf

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/spin_action.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class SpinAction : public BtActionNode<nav2_msgs::action::Spin>
6565
BT::InputPort<double>("spin_dist", 1.57, "Spin distance"),
6666
BT::InputPort<double>("time_allowance", 10.0, "Allowed time for spinning"),
6767
BT::InputPort<bool>("is_recovery", true, "True if recovery"),
68+
BT::OutputPort<double>(
69+
"angular_distance_traveled", "Angular distance traveled (may be less than requested)"),
6870
BT::OutputPort<ActionResult::_error_code_type>(
6971
"error_code_id", "The spin behavior error code")
7072
});
@@ -85,6 +87,18 @@ class SpinAction : public BtActionNode<nav2_msgs::action::Spin>
8587
*/
8688
BT::NodeStatus on_cancelled() override;
8789

90+
/**
91+
* @brief Function to perform some user-defined operation after a timeout
92+
* waiting for a result that hasn't been received yet. Also provides access to
93+
* the latest feedback message from the action server. Feedback will be nullptr
94+
* in subsequent calls to this function if no new feedback is received while waiting for a result.
95+
* @param feedback shared_ptr to latest feedback message, nullptr if no new feedback was received
96+
*/
97+
void on_wait_for_result(std::shared_ptr<const typename Action::Feedback> feedback) override;
98+
99+
protected:
100+
double distance_traveled_;
101+
88102
private:
89103
bool is_recovery_;
90104
};

nav2_behavior_tree/plugins/action/spin_action.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,33 @@ void SpinAction::on_tick()
4949

5050
BT::NodeStatus SpinAction::on_success()
5151
{
52+
setOutput("angular_distance_traveled", distance_traveled_);
5253
setOutput("error_code_id", ActionGoal::NONE);
5354
return BT::NodeStatus::SUCCESS;
5455
}
5556

5657
BT::NodeStatus SpinAction::on_aborted()
5758
{
59+
setOutput("angular_distance_traveled", distance_traveled_);
5860
setOutput("error_code_id", result_.result->error_code);
5961
return BT::NodeStatus::FAILURE;
6062
}
6163

6264
BT::NodeStatus SpinAction::on_cancelled()
6365
{
66+
setOutput("angular_distance_traveled", distance_traveled_);
6467
setOutput("error_code_id", ActionGoal::NONE);
6568
return BT::NodeStatus::SUCCESS;
6669
}
6770

71+
void SpinAction::on_wait_for_result(std::shared_ptr<const typename Action::Feedback> feedback)
72+
{
73+
if (!feedback) {
74+
return;
75+
}
76+
distance_traveled_ = feedback->angular_distance_traveled;
77+
}
78+
6879
} // namespace nav2_behavior_tree
6980

7081
#include "behaviortree_cpp_v3/bt_factory.h"

0 commit comments

Comments
 (0)