sample_nodes
movebase_node.cpp
Go to the documentation of this file.
1
#include "
movebase_node.h
"
2
#include "
behaviortree_cpp/bt_factory.h
"
3
4
// This function must be implemented in the .cpp file to create
5
// a plugin that can be loaded at run-time
6
BT_REGISTER_NODES
(factory)
7
{
8
factory.registerNodeType<
MoveBaseAction
>(
"MoveBase"
);
9
}
10
11
BT::NodeStatus
MoveBaseAction::onStart
()
12
{
13
if
(!getInput<Pose2D>(
"goal"
,
_goal
))
14
{
15
throw
BT::RuntimeError
(
"missing required input [goal]"
);
16
}
17
printf(
"[ MoveBase: SEND REQUEST ]. goal: x=%.1f y=%.1f theta=%.1f\n"
,
_goal
.
x
,
_goal
.
y
,
18
_goal
.
theta
);
19
20
// We use this counter to simulate an action that takes a certain
21
// amount of time to be completed (220 ms)
22
_completion_time
= chr::system_clock::now() + chr::milliseconds(220);
23
24
return
BT::NodeStatus::RUNNING
;
25
}
26
27
BT::NodeStatus
MoveBaseAction::onRunning
()
28
{
29
// Pretend that we are checking if the reply has been received
30
// you don't want to block inside this function too much time.
31
std::this_thread::sleep_for(chr::milliseconds(10));
32
33
// Pretend that, after a certain amount of time,
34
// we have completed the operation
35
if
(chr::system_clock::now() >=
_completion_time
)
36
{
37
std::cout <<
"[ MoveBase: FINISHED ]"
<< std::endl;
38
return
BT::NodeStatus::SUCCESS
;
39
}
40
return
BT::NodeStatus::RUNNING
;
41
}
42
43
void
MoveBaseAction::onHalted
()
44
{
45
printf(
"[ MoveBase: ABORTED ]"
);
46
}
bt_factory.h
MoveBaseAction
Definition:
movebase_node.h:54
MoveBaseAction::_goal
Pose2D _goal
Definition:
movebase_node.h:79
movebase_node.h
BT::RuntimeError
Definition:
exceptions.h:58
Pose2D::y
double y
Definition:
t18_waypoints.cpp:15
BT::NodeStatus::SUCCESS
@ SUCCESS
BT_REGISTER_NODES
BT_REGISTER_NODES(factory)
Definition:
movebase_node.cpp:6
BT::NodeStatus::RUNNING
@ RUNNING
MoveBaseAction::onHalted
void onHalted() override
Definition:
movebase_node.cpp:43
MoveBaseAction::_completion_time
chr::system_clock::time_point _completion_time
Definition:
movebase_node.h:80
MoveBaseAction::onRunning
BT::NodeStatus onRunning() override
method invoked when the action is already in the RUNNING state.
Definition:
movebase_node.cpp:27
Pose2D::theta
double theta
Definition:
t18_waypoints.cpp:15
Pose2D::x
double x
Definition:
t18_waypoints.cpp:15
BT::NodeStatus
NodeStatus
Definition:
basic_types.h:33
MoveBaseAction::onStart
BT::NodeStatus onStart() override
Definition:
movebase_node.cpp:11
behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:17