movebase_node.h
Go to the documentation of this file.
1 #ifndef MOVEBASE_BT_NODES_H
2 #define MOVEBASE_BT_NODES_H
3 
5 
6 // Custom type
7 struct Pose2D
8 {
9  double x, y, theta;
10 };
11 
12 inline void SleepMS(int ms)
13 {
14  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
15 }
16 
17 namespace BT
18 {
19 // This template specialization is needed only if you want
20 // to AUTOMATICALLY convert a NodeParameter into a Pose2D
21 // In other words, implement it if you want to be able to do:
22 //
23 // TreeNode::getParam<Pose2D>(key, ...)
24 //
25 template <>
27 {
28  // three real numbers separated by semicolons
29  auto parts = BT::splitString(key, ';');
30  if (parts.size() != 3)
31  {
32  throw std::runtime_error("invalid input)");
33  }
34  else
35  {
36  Pose2D output;
37  output.x = convertFromString<double>(parts[0]);
38  output.y = convertFromString<double>(parts[1]);
39  output.theta = convertFromString<double>(parts[2]);
40  return output;
41  }
42 }
43 }
44 
45 // This is an asynchronous operation that will run in a separate thread.
46 // It requires the NodeParameter "goal". If the key is not provided, the default
47 // value "0;0;0" is used instead.
48 
50 {
51  public:
52  // If your TreeNode requires a NodeParameter, you must define a constructor
53  // with this signature.
54  MoveBaseAction(const std::string& name, const BT::NodeParameters& params)
55  : AsyncActionNode(name, params)
56  {
57  }
58 
59  // It is mandatory to define this static method.
60  // If you don't, BehaviorTreeFactory::registerNodeType will not compile.
61  //
63  {
64  static BT::NodeParameters params = {{"goal", "0;0;0"}};
65  return params;
66  }
67 
68  BT::NodeStatus tick() override;
69 
70  virtual void halt() override;
71 
72  private:
73  std::atomic_bool _halt_requested;
74 };
75 
76 #endif // MOVEBASE_BT_NODES_H
double convertFromString< double >(const StringView &str)
Definition: basic_types.cpp:92
static const BT::NodeParameters & requiredNodeParameters()
Definition: movebase_node.h:62
The AsyncActionNode a different thread where the action will be executed.
Definition: action_node.h:110
void SleepMS(int ms)
Definition: movebase_node.h:12
double x
Definition: movebase_node.h:9
std::vector< StringView > splitString(const StringView &strToSplit, char delimeter)
std::unordered_map< std::string, std::string > NodeParameters
Definition: tree_node.h:33
nonstd::string_view StringView
Definition: basic_types.h:58
double theta
Definition: movebase_node.h:9
Pose2D convertFromString(const StringView &key)
Definition: movebase_node.h:26
std::atomic_bool _halt_requested
Definition: movebase_node.h:73
MoveBaseAction(const std::string &name, const BT::NodeParameters &params)
Definition: movebase_node.h:54
NodeStatus
Definition: basic_types.h:28
double y
Definition: movebase_node.h:9


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 04:01:53