Skip to content

Commit c83f7b2

Browse files
committed
Requested changes
Signed-off-by: redvinaa <redvinaa@gmail.com>
1 parent 839fc54 commit c83f7b2

File tree

7 files changed

+270
-325
lines changed

7 files changed

+270
-325
lines changed

nav2_behavior_tree/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ list(APPEND plugin_libs nav2_pipeline_sequence_bt_node)
212212
add_library(nav2_round_robin_node_bt_node SHARED plugins/control/round_robin_node.cpp)
213213
list(APPEND plugin_libs nav2_round_robin_node_bt_node)
214214

215-
add_library(nav2_pause_bt_node SHARED plugins/control/pause.cpp)
216-
list(APPEND plugin_libs nav2_pause_bt_node)
215+
add_library(nav2_pause_resume_controller_bt_node SHARED plugins/control/pause_resume_controller.cpp)
216+
list(APPEND plugin_libs nav2_pause_resume_controller_bt_node)
217217

218218
add_library(nav2_sequence_with_blackboard_memory_bt_node SHARED plugins/control/sequence_with_blackboard_memory.cpp)
219219
list(APPEND plugin_libs nav2_sequence_with_blackboard_memory_bt_node)

nav2_behavior_tree/include/nav2_behavior_tree/plugins/control/pause.hpp renamed to nav2_behavior_tree/include/nav2_behavior_tree/plugins/control/pause_resume_controller.hpp

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019 Intel Corporation
1+
// Copyright (c) 2025 Intel Corporation
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -18,11 +18,14 @@
1818
// Other includes
1919
#include <string>
2020
#include <memory>
21-
#include <mutex>
21+
#include <map>
2222

2323
// ROS includes
2424
#include "rclcpp/rclcpp.hpp"
25+
#include "rclcpp/callback_group.hpp"
26+
#include "rclcpp/executors/single_threaded_executor.hpp"
2527
#include "behaviortree_cpp/control_node.h"
28+
#include "nav2_util/service_server.hpp"
2629

2730
// Interface definitions
2831
#include "std_srvs/srv/trigger.hpp"
@@ -34,25 +37,49 @@ namespace nav2_behavior_tree
3437
using Trigger = std_srvs::srv::Trigger;
3538

3639
enum state_t {UNPAUSED, PAUSED, PAUSE_REQUESTED, ON_PAUSE, RESUME_REQUESTED, ON_RESUME};
40+
const std::map<state_t, std::string> state_names = {
41+
{UNPAUSED, "UNPAUSED"},
42+
{PAUSED, "PAUSED"},
43+
{PAUSE_REQUESTED, "PAUSE_REQUESTED"},
44+
{ON_PAUSE, "ON_PAUSE"},
45+
{RESUME_REQUESTED, "RESUME_REQUESTED"},
46+
{ON_RESUME, "ON_RESUME"}
47+
};
48+
const std::map<state_t, uint> child_indices = {
49+
{UNPAUSED, 0},
50+
{PAUSED, 1},
51+
{ON_PAUSE, 2},
52+
{ON_RESUME, 3}
53+
};
3754

3855
/* @brief Controlled through service calls to pause and resume the execution of the tree
3956
* It has one mandatory child for the UNPAUSED, and three optional for the PAUSED state,
4057
* the ON_PAUSE event and the ON_RESUME event.
4158
* It has two input ports:
4259
* - pause_service_name: name of the service to pause
4360
* - resume_service_name: name of the service to resume
61+
*
62+
* Usage:
63+
* <Pause pause_service_name="/pause" resume_service_name="/resume">
64+
* <!-- UNPAUSED branch -->
65+
*
66+
* <!-- PAUSED branch (optional) -->
67+
*
68+
* <!-- ON_PAUSE branch (optional) -->
69+
*
70+
* <!-- ON_RESUME branch (optional) -->
71+
* </Pause>
4472
*/
45-
class Pause : public BT::ControlNode
73+
74+
75+
class PauseResumeController : public BT::ControlNode
4676
{
4777
public:
4878
//! @brief Constructor
49-
Pause(
79+
PauseResumeController(
5080
const std::string & xml_tag_name,
5181
const BT::NodeConfiguration & conf);
5282

53-
//! @brief Destructor
54-
~Pause();
55-
5683
//! @brief Reset state and go to Idle
5784
void halt() override;
5885

@@ -74,23 +101,27 @@ class Pause : public BT::ControlNode
74101

75102
private:
76103
//! @brief Service callback to pause
77-
void pause_service_callback(
104+
void pauseServiceCallback(
105+
const std::shared_ptr<rmw_request_id_t>/*request_header*/,
78106
const std::shared_ptr<Trigger::Request> request,
79107
std::shared_ptr<Trigger::Response> response);
80108

81109
//! @brief Service callback to resume
82-
void resume_service_callback(
110+
void resumeServiceCallback(
111+
const std::shared_ptr<rmw_request_id_t>/*request_header*/,
83112
const std::shared_ptr<Trigger::Request> request,
84113
std::shared_ptr<Trigger::Response> response);
85114

115+
BT::NodeStatus tickChildAndTransition();
116+
117+
void switchState(const state_t new_state);
118+
86119
rclcpp::Node::SharedPtr node_;
87120
rclcpp::CallbackGroup::SharedPtr cb_group_;
88121
rclcpp::executors::SingleThreadedExecutor::SharedPtr executor_;
89-
std::unique_ptr<std::thread> spinner_thread_;
90-
rclcpp::Service<Trigger>::SharedPtr pause_srv_;
91-
rclcpp::Service<Trigger>::SharedPtr resume_srv_;
122+
nav2_util::ServiceServer<Trigger>::SharedPtr pause_srv_;
123+
nav2_util::ServiceServer<Trigger>::SharedPtr resume_srv_;
92124
state_t state_;
93-
std::mutex state_mutex_;
94125
};
95126

96127
} // namespace nav2_behavior_tree

nav2_behavior_tree/include/nav2_behavior_tree/plugins/control/sequence_with_blackboard_memory.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019 Intel Corporation
1+
// Copyright (c) 2025 Intel Corporation
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -44,8 +44,6 @@ class SequenceWithBlackboardMemoryNode : public BT::ControlNode
4444

4545
~SequenceWithBlackboardMemoryNode() override = default;
4646

47-
void halt() override;
48-
4947
//! @brief Declare ports
5048
static BT::PortsList providedPorts()
5149
{

nav2_behavior_tree/nav2_tree_nodes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@
390390

391391
<Control ID="RoundRobin"/>
392392

393-
<Control ID="Pause">
393+
<Control ID="PauseResumeController">
394394
<input_port name="pause_service_name">Service to call to pause</input_port>
395395
<input_port name="resume_service_name">Service to call to resume</input_port>
396396
</Control>

0 commit comments

Comments
 (0)