forked from tka-andrew/learning_BehaviourTreeCPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial04_nodes.cpp
55 lines (46 loc) · 1.63 KB
/
tutorial04_nodes.cpp
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
#include "tutorial04_nodes.h"
#include "tutorial04_interface.h"
#include <chrono>
#include <thread>
namespace T04DummyNodes
{
BT::NodeStatus CheckBattery()
{
std::cout << "[ Battery: OK ]" << std::endl;
return BT::NodeStatus::SUCCESS;
}
BT::NodeStatus SaySomething::tick()
{
BT::Optional<std::string> msg = getInput<std::string>("message");
// Check if optional is valid. If not, throw its error
if (!msg)
{
throw BT::RuntimeError("missing required input [message]: ",
msg.error());
}
// use the method value() to extract the valid message.
std::cout << "Robot says: " << msg.value() << std::endl;
return BT::NodeStatus::SUCCESS;
}
BT::NodeStatus MoveBaseAction::tick()
{
T04Interface::Pose2D goal;
if (!getInput<T04Interface::Pose2D>("goal", goal))
{
throw BT::RuntimeError("missing required input [goal]");
}
printf("[ MoveBase: STARTED ]. goal: x=%.f y=%.1f theta=%.2f\n",
goal.x, goal.y, goal.theta);
_halt_requested.store(false);
int count = 0;
// Pretend that "computing" takes 250 milliseconds.
// It is up to you to check periodicall _halt_requested and interrupt
// this tick() if it is true.
while (!_halt_requested && count++ < 25)
{
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
std::cout << "[ MoveBase: FINISHED ]" << std::endl;
return _halt_requested ? BT::NodeStatus::FAILURE : BT::NodeStatus::SUCCESS;
}
}