Common
common packages for kyubic
 
Loading...
Searching...
No Matches
filtered_logger.hpp
Go to the documentation of this file.
1
2#include <chrono>
3#include <iomanip> // std::setprecision用
4#include <iostream>
5
6#include "behaviortree_cpp/loggers/abstract_logger.h"
7
8class FilteredStdCoutLogger : public BT::StatusChangeLogger
9{
10public:
11 FilteredStdCoutLogger(const BT::Tree & tree) : BT::StatusChangeLogger(tree.rootNode()) {}
12
14 BT::Duration timestamp, const BT::TreeNode & node, BT::NodeStatus prev_status,
15 BT::NodeStatus status) override
16 {
17 // 1. 除外フィルタ(UpdateMode, CheckSensorStatus を無視)
18 if (
19 (status == BT::NodeStatus::SUCCESS || status == BT::NodeStatus::RUNNING ||
20 status == BT::NodeStatus::IDLE) &&
21 (node.name() == "UpdateMode" || node.name() == "CheckSensorsStatus" ||
22 node.name() == "RetryUntilSuccessful")) {
23 return;
24 }
25
26 // 2. 時刻の計算 (マイクロ秒 -> 秒)
27 double time_sec = std::chrono::duration<double>(timestamp).count();
28
29 // 3. 色の選択
30 const char * color_code = resetColor();
31 switch (status) {
32 case BT::NodeStatus::SUCCESS:
33 color_code = greenColor();
34 break;
35 case BT::NodeStatus::FAILURE:
36 color_code = redColor();
37 break;
38 case BT::NodeStatus::RUNNING:
39 color_code = yellowColor();
40 break;
41 case BT::NodeStatus::IDLE:
42 color_code = resetColor();
43 break;
44 case BT::NodeStatus::SKIPPED:
45 color_code = cyanColor();
46 break;
47 }
48
49 // 4. フォーマット出力
50 // [Time] [NodeName]: PREV -> NEW (Colorized)
51 std::cout << "[" << std::fixed << std::setprecision(3) << time_sec << "s] " << "["
52 << node.name() << "]: " << toStr(prev_status) << " -> " << color_code << toStr(status)
53 << resetColor() << std::endl;
54 }
55
56 void flush() override { std::cout << std::flush; }
57
58private:
59 // ANSIエスケープシーケンス定義
60 const char * redColor() { return "\033[31m"; }
61 const char * greenColor() { return "\033[32m"; }
62 const char * yellowColor() { return "\033[33m"; }
63 const char * cyanColor() { return "\033[36m"; }
64 const char * resetColor() { return "\033[0m"; }
65};
Definition: filtered_logger.hpp:9
void callback(BT::Duration timestamp, const BT::TreeNode &node, BT::NodeStatus prev_status, BT::NodeStatus status) override
Definition: filtered_logger.hpp:13
FilteredStdCoutLogger(const BT::Tree &tree)
Definition: filtered_logger.hpp:11
void flush() override
Definition: filtered_logger.hpp:56