Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef TREE_NODE_H
00015 #define TREE_NODE_H
00016
00017
00018 #ifndef _COLORS_
00019 #define _COLORS_
00020
00021
00022 #define RST "\x1B[0m"
00023 #define KRED "\x1B[31m"
00024 #define KGRN "\x1B[32m"
00025 #define KYEL "\x1B[33m"
00026 #define KBLU "\x1B[34m"
00027 #define KMAG "\x1B[35m"
00028 #define KCYN "\x1B[36m"
00029 #define KWHT "\x1B[37m"
00030
00031 #define FRED(x) KRED x RST
00032 #define FGRN(x) KGRN x RST
00033 #define FYEL(x) KYEL x RST
00034 #define FBLU(x) KBLU x RST
00035 #define FMAG(x) KMAG x RST
00036 #define FCYN(x) KCYN x RST
00037 #define FWHT(x) KWHT x RST
00038
00039 #define BOLD(x) "\x1B[1m" x RST
00040 #define UNDL(x) "\x1B[4m" x RST
00041
00042 #endif
00043
00044 #define DEBUG // uncomment this line if you want to print debug messages
00045
00046 #ifdef DEBUG
00047
00048 #define DEBUG_STDOUT(str) do { std::cout << str << std::endl; } while ( false ) // NOLINT(whitespace/braces)
00049
00050
00051 #else
00052 #define DEBUG_STDOUT(str)
00053 #endif
00054
00055
00056 #include <iostream>
00057 #include <unistd.h>
00058
00059 #include <string>
00060
00061 #include <thread>
00062 #include <chrono>
00063 #include <mutex>
00064 #include <condition_variable>
00065
00066
00067 #include <tick_engine.h>
00068 #include <exceptions.h>
00069
00070 namespace BT
00071 {
00072
00073
00074 enum NodeType {ACTION_NODE, CONDITION_NODE, CONTROL_NODE};
00075 enum DrawNodeType {PARALLEL, SELECTOR, SEQUENCE, SEQUENCESTAR, SELECTORSTAR, ACTION, CONDITION, DECORATOR};
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 enum ReturnStatus {RUNNING, SUCCESS, FAILURE, IDLE, HALTED, EXIT};
00086
00087
00088
00089
00090
00091
00092 enum FailurePolicy {FAIL_ON_ONE, FAIL_ON_ALL};
00093 enum ResetPolity {ON_SUCCESS_OR_FAILURE, ON_SUCCESS, ON_FAILURE};
00094
00095
00096
00097
00098
00099
00100 enum SuccessPolicy {SUCCEED_ON_ONE, SUCCEED_ON_ALL};
00101
00102
00103 class TreeNode
00104 {
00105 private:
00106
00107 std::string name_;
00108 bool has_parent_;
00109
00110
00111
00112
00113 protected:
00114
00115 bool is_state_updated_;
00116 ReturnStatus status_;
00117 ReturnStatus color_status_;
00118
00119
00120 std::mutex state_mutex_;
00121 std::mutex color_state_mutex_;
00122 std::condition_variable state_condition_variable_;
00123
00124 NodeType type_;
00125
00126 float x_shift_, x_pose_;
00127
00128 public:
00129
00130 std::thread thread_;
00131
00132
00133
00134 TickEngine tick_engine;
00135
00136
00137
00138
00139
00140 explicit TreeNode(std::string name);
00141 ~TreeNode();
00142
00143
00144 virtual BT::ReturnStatus Tick() = 0;
00145
00146
00147 virtual void Halt() = 0;
00148
00149
00150
00151
00152 void SetNodeState(ReturnStatus new_state);
00153 void set_color_status(ReturnStatus new_color_status);
00154
00155
00156
00157 ReturnStatus ReadState();
00158 ReturnStatus get_color_status();
00159 virtual int DrawType() = 0;
00160 virtual void ResetColorState() = 0;
00161 virtual int Depth() = 0;
00162
00163
00164
00165 void set_x_pose(float x_pose);
00166 float get_x_pose();
00167
00168 void set_x_shift(float x_shift);
00169 float get_x_shift();
00170
00171
00172
00173 ReturnStatus get_status();
00174 void set_status(ReturnStatus new_status);
00175
00176
00177 std::string get_name();
00178 void set_name(std::string new_name);
00179
00180 NodeType get_type();
00181 bool has_parent();
00182 void set_has_parent(bool value);
00183 };
00184 }
00185
00186 #endif // TREE_NODE_H