-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathping_bt_node.cpp
More file actions
77 lines (59 loc) · 1.77 KB
/
ping_bt_node.cpp
File metadata and controls
77 lines (59 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "ros2_behavior_tree_example/plugins/ping_bt_node.hpp"
#include "std_msgs/msg/int32.hpp"
namespace polymath
{
namespace bt_ros_example
{
PingNode::PingNode(const std::string &action_name, const BT::NodeConfiguration &conf)
: BT::StatefulActionNode(action_name, conf),
pub_topic_("outgoing_ping")
{
node_ = conf.blackboard->get<rclcpp_lifecycle::LifecycleNode::SharedPtr>("node");
pub_ = node_->create_publisher<std_msgs::msg::Int32>(pub_topic_,
rclcpp::SystemDefaultsQoS());
ping_msg_.data = 0;
return;
}
PingNode::~PingNode()
{
RCLCPP_INFO(node_->get_logger(),"SHUTTING DOWN PING NODE");
}
BT::NodeStatus PingNode::onStart()
{
getInput<int32_t>("num_pings", num_pings_ );
curr_ping_in_burst_ = 0;
RCLCPP_INFO(node_->get_logger(), "STARTING PING");
publish();
if(num_pings_ <= 1)
{
return BT::NodeStatus::SUCCESS;
}
curr_ping_in_burst_++;
return BT::NodeStatus::RUNNING;
}
BT::NodeStatus PingNode::onRunning()
{
RCLCPP_INFO(node_->get_logger(), "RUNNING PING");
// always start by publishing
publish();
curr_ping_in_burst_++;
if(curr_ping_in_burst_ == num_pings_)
{
return BT::NodeStatus::SUCCESS;
}
return BT::NodeStatus::RUNNING;
}
void PingNode::onHalted()
{
// Do any necessary cleanup for the running nodes
RCLCPP_INFO(node_->get_logger(), "HALTING RUN");
return;
}
void PingNode::publish()
{
ping_msg_.data++;
setOutput("last_ping_id", ping_msg_.data);
pub_->publish(ping_msg_);
}
}
}