movebase_node.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 // Custom type
7 struct Pose2D
8 {
9  double x, y, theta;
10 };
11 
12 // Add this to you main() to register this function into JsonExporter:
13 //
14 // BT::JsonExporter::get().addConverter<Pose2D>();
15 
17 {
18  add_field("x", &pose.x);
19  add_field("y", &pose.y);
20  add_field("theta", &pose.theta);
21 }
22 
23 namespace BT
24 {
25 // This template specialization is needed only if you want
26 // to AUTOMATICALLY convert a NodeParameter into a Pose2D
27 // In other words, implement it if you want to be able to do:
28 //
29 // TreeNode::getInput<Pose2D>(key, ...)
30 //
31 template <>
33 {
34  // three real numbers separated by semicolons
35  auto parts = BT::splitString(key, ';');
36  if(parts.size() != 3)
37  {
38  throw BT::RuntimeError("invalid input)");
39  }
40  else
41  {
42  Pose2D output;
43  output.x = convertFromString<double>(parts[0]);
44  output.y = convertFromString<double>(parts[1]);
45  output.theta = convertFromString<double>(parts[2]);
46  return output;
47  }
48 }
49 } // end namespace BT
50 
51 namespace chr = std::chrono;
52 
53 // This is an asynchronous operation
55 {
56 public:
57  // Any TreeNode with ports must have a constructor with this signature
58  MoveBaseAction(const std::string& name, const BT::NodeConfig& config)
60  {}
61 
62  // It is mandatory to define this static method.
64  {
65  return { BT::InputPort<Pose2D>("goal") };
66  }
67 
68  // this function is invoked once at the beginning.
69  BT::NodeStatus onStart() override;
70 
71  // If onStart() returned RUNNING, we will keep calling
72  // this method until it return something different from RUNNING
73  BT::NodeStatus onRunning() override;
74 
75  // callback to execute if the action was aborted by another node
76  void onHalted() override;
77 
78 private:
80  chr::system_clock::time_point _completion_time;
81 };
BT
Definition: ex01_wrap_legacy.cpp:29
Pose2D
Definition: t18_waypoints.cpp:13
BT::TreeNode::config
const NodeConfig & config() const
Definition: tree_node.cpp:345
BT::StatefulActionNode::StatefulActionNode
StatefulActionNode(const std::string &name, const NodeConfig &config)
Definition: action_node.h:162
BT::StringView
std::string_view StringView
Definition: basic_types.h:59
BT_JSON_CONVERTER
BT_JSON_CONVERTER(Pose2D, pose)
Definition: movebase_node.h:16
MoveBaseAction
Definition: movebase_node.h:54
MoveBaseAction::_goal
Pose2D _goal
Definition: movebase_node.h:79
BT::PortsList
std::unordered_map< std::string, PortInfo > PortsList
Definition: basic_types.h:585
BT::convertFromString
Point3D convertFromString(StringView key)
Definition: ex01_wrap_legacy.cpp:32
action_node.h
BT::RuntimeError
Definition: exceptions.h:58
json_export.h
MoveBaseAction::MoveBaseAction
MoveBaseAction(const std::string &name, const BT::NodeConfig &config)
Definition: movebase_node.h:58
BT::splitString
std::vector< StringView > splitString(const StringView &strToSplit, char delimeter)
Definition: basic_types.cpp:348
Pose2D::y
double y
Definition: t18_waypoints.cpp:15
MoveBaseAction::providedPorts
static BT::PortsList providedPorts()
Definition: movebase_node.h:63
BT::TreeNode::name
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:296
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
BT::convertFromString< double >
double convertFromString< double >(StringView str)
Definition: basic_types.cpp:191
MoveBaseAction::onRunning
BT::NodeStatus onRunning() override
method invoked when the action is already in the RUNNING state.
Definition: movebase_node.cpp:27
BT::NodeConfig
Definition: tree_node.h:73
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
BT::StatefulActionNode
The StatefulActionNode is the preferred way to implement asynchronous Actions. It is actually easier ...
Definition: action_node.h:159


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Jun 28 2024 02:20:07