Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <string>
#include <map>
#include <memory>

#include "geometry_msgs/msg/pose.hpp"
#include "nav2_msgs/action/navigate_to_pose.hpp"
Expand All @@ -39,6 +40,9 @@ class Move : public plansys2::BtActionNode<

BT::NodeStatus on_tick() override;
BT::NodeStatus on_success() override;
void on_feedback(
const std::shared_ptr<const nav2_msgs::action::NavigateToPose::Feedback> feedback)
override;
Comment thread
fmrico marked this conversation as resolved.

static BT::PortsList providedPorts()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <string>
#include <iostream>
#include <algorithm>

#include "plansys2_bt_example/behavior_tree_nodes/ApproachObject.hpp"

Expand All @@ -40,6 +41,9 @@ ApproachObject::tick()
{
std::cout << "ApproachObject tick " << counter_ << std::endl;

float completion = std::min(1.0f, counter_ / 5.0f);
config().blackboard->set<float>("completion", completion);
Comment thread
fmrico marked this conversation as resolved.

if (counter_++ < 5) {
return BT::NodeStatus::RUNNING;
} else {
Expand Down
4 changes: 4 additions & 0 deletions plansys2_bt_example/src/behavior_tree_nodes/CloseGripper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <string>
#include <iostream>
#include <algorithm>

#include "plansys2_bt_example/behavior_tree_nodes/CloseGripper.hpp"

Expand All @@ -40,6 +41,9 @@ CloseGripper::tick()
{
std::cout << "CloseGripper tick " << counter_ << std::endl;

float completion = std::min(1.0f, counter_ / 5.0f);
config().blackboard->set<float>("completion", completion);
Comment thread
fmrico marked this conversation as resolved.

if (counter_++ < 5) {
return BT::NodeStatus::RUNNING;
} else {
Expand Down
13 changes: 13 additions & 0 deletions plansys2_bt_example/src/behavior_tree_nodes/Move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
Expand Down Expand Up @@ -107,9 +108,21 @@ Move::on_tick()
BT::NodeStatus
Move::on_success()
{
config().blackboard->set<float>("completion", 1.0f);
return BT::NodeStatus::SUCCESS;
}

void
Move::on_feedback(
const std::shared_ptr<const nav2_msgs::action::NavigateToPose::Feedback> feedback)
{
// nav2_sim sends distance_remaining counting down from ~10 to ~0
constexpr float kInitialDistance = 10.0f;
float completion = 1.0f - std::min(
1.0f, std::max(0.0f, feedback->distance_remaining / kInitialDistance));
config().blackboard->set<float>("completion", completion);
}


} // namespace plansys2_bt_tests

Expand Down
4 changes: 4 additions & 0 deletions plansys2_bt_example/src/behavior_tree_nodes/OpenGripper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <string>
#include <iostream>
#include <algorithm>

#include "plansys2_bt_example/behavior_tree_nodes/OpenGripper.hpp"

Expand All @@ -40,6 +41,9 @@ OpenGripper::tick()
{
std::cout << "OpenGripper tick " << counter_ << std::endl;

float completion = std::min(1.0f, counter_ / 5.0f);
config().blackboard->set<float>("completion", completion);
Comment thread
fmrico marked this conversation as resolved.

if (counter_++ < 5) {
return BT::NodeStatus::RUNNING;
} else {
Expand Down
4 changes: 4 additions & 0 deletions plansys2_bt_example/src/behavior_tree_nodes/Recharge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <string>
#include <iostream>
#include <algorithm>

#include "plansys2_bt_example/behavior_tree_nodes/Recharge.hpp"

Expand All @@ -40,6 +41,9 @@ Recharge::tick()
{
std::cout << "Recharge tick " << counter_ << std::endl;

float completion = std::min(1.0f, counter_ / 10.0f);
config().blackboard->set<float>("completion", completion);
Comment thread
fmrico marked this conversation as resolved.

if (counter_++ < 10) {
return BT::NodeStatus::RUNNING;
} else {
Expand Down
Loading