diagnostics.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10  ** Includes
11  *****************************************************************************/
12 
13 #include "../../include/kobuki_node/diagnostics.hpp"
14 
15 /*****************************************************************************
16 ** Namespaces
17 *****************************************************************************/
18 
19 namespace kobuki {
20 
21 /*****************************************************************************
22 ** Implementation
23 *****************************************************************************/
24 
26  switch ( status.level() ) {
27  case ( Battery::Maximum ) : {
28  stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "Maximum");
29  break;
30  }
31  case ( Battery::Healthy ) : {
32  stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "Healthy");
33  break;
34  }
35  case ( Battery::Low ) : {
36  stat.summary(diagnostic_msgs::DiagnosticStatus::WARN, "Low");
37  break;
38  }
39  case ( Battery::Dangerous ) : {
40  stat.summary(diagnostic_msgs::DiagnosticStatus::WARN, "Dangerous");
41  break;
42  }
43  }
44 
45  stat.add("Voltage (V)", status.voltage);
46  stat.add("Percent", status.percent());
47  stat.add("Charge (Ah)", (2.2*status.percent())/100.0);
48  stat.add("Capacity (Ah)", 2.2); // TODO: how can we tell which battery is in use?
49 
50  switch (status.charging_source ) {
51  case(Battery::None) : {
52  stat.add("Source", "None");
53  break;
54  }
55  case(Battery::Adapter) : {
56  stat.add("Source", "Adapter");
57  break;
58  }
59  case(Battery::Dock) : {
60  stat.add("Source", "Dock");
61  break;
62  }
63  }
64  switch ( status.charging_state ) {
65  case ( Battery::Charged ) : {
66  stat.add("Charging State", "Trickle Charging"); // i.e. fully charged
67  stat.add("Current (A)", 3.14); // TODO: what's the real value for our charger?
68  break;
69  }
70  case ( Battery::Charging ) : {
71  stat.add("Charging State", "Full Charging");
72  stat.add("Current (A)", 3.14); // TODO: what's the real value for our charger?
73  break;
74  }
75  case ( Battery::Discharging ) : {
76  stat.add("Charging State", "Not Charging");
77  stat.add("Current (A)", 0.0);
78  break;
79  }
80  default: break;
81  }
82 }
83 
85  if ( alive ) {
86  stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "Alive");
87  } else {
88  stat.summary(diagnostic_msgs::DiagnosticStatus::ERROR, "No Signal");
89  }
90 }
91 
93  if ( status ) {
94  stat.summary(diagnostic_msgs::DiagnosticStatus::WARN, "Cliff Detected!");
95  } else {
96  stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "All right");
97  }
98 
99  stat.addf("Left", "Reading: %d Cliff: %s", values.bottom[0], status & CoreSensors::Flags::LeftCliff?"YES":"NO");
100  stat.addf("Center", "Reading: %d Cliff: %s", values.bottom[1], status & CoreSensors::Flags::CenterCliff?"YES":"NO");
101  stat.addf("Right", "Reading: %d Cliff: %s", values.bottom[2], status & CoreSensors::Flags::RightCliff?"YES":"NO");
102 }
103 
105  if ( status ) {
106  stat.summary(diagnostic_msgs::DiagnosticStatus::WARN, "Wall Hit!");
107  } else {
108  stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "All right");
109  }
110 
111  stat.addf("Left", status & CoreSensors::Flags::LeftBumper?"YES":"NO");
112  stat.addf("Center", status & CoreSensors::Flags::CenterBumper?"YES":"NO");
113  stat.addf("Right", status & CoreSensors::Flags::RightBumper?"YES":"NO");
114 }
115 
117  if ( status ) {
118  stat.summary(diagnostic_msgs::DiagnosticStatus::WARN, "Wheel Drop!");
119  } else {
120  stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "All right");
121  }
122 
123  stat.addf("Left", status & CoreSensors::Flags::LeftWheel?"YES":"NO");
124  stat.addf("Right", status & CoreSensors::Flags::RightWheel?"YES":"NO");
125 }
126 
128  if ( std::max(values[0], values[1]) > 6 ) { // TODO not sure about this threshold; should be a parameter?
129  stat.summary(diagnostic_msgs::DiagnosticStatus::WARN, "Is robot stalled? Motors current is very high");
130  } else {
131  stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "All right");
132  }
133 
134  stat.addf("Left", "%d", values[0]);
135  stat.addf("Right", "%d", values[1]);
136 }
137 
139  if ( state == true ) {
140  stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "Motors Enabled");
141  } else {
142  stat.summary(diagnostic_msgs::DiagnosticStatus::WARN, "Motors Disabled");
143  }
144 
145  stat.addf("State", "%d", int(state));
146 }
147 
149  // Raw data angles are in hundredths of degree
150  stat.summaryf(diagnostic_msgs::DiagnosticStatus::OK, "Heading: %.2f degrees", heading/100.0);
151 }
152 
154  stat.summaryf(diagnostic_msgs::DiagnosticStatus::OK, "[%d, %d, %d, %d]",
155  status & 0x08?1:0, status & 0x04?1:0,
156  status & 0x02?1:0, status & 0x01?1:0);
157 }
158 
160  stat.summaryf(diagnostic_msgs::DiagnosticStatus::OK, "[%d, %d, %d, %d]",
161  values[0], values[1], values[2], values[3]);
162 }
163 
164 } // namespace kobuki
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: diagnostics.cpp:84
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: diagnostics.cpp:25
static const uint8_t RightWheel
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
Source charging_source
std::vector< double > values
void summary(unsigned char lvl, const std::string s)
static const uint8_t RightCliff
Level level() const
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
void addf(const std::string &key, const char *format,...)
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: diagnostics.cpp:92
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
void summaryf(unsigned char lvl, const char *format,...)
static const uint8_t CenterCliff
static const uint8_t LeftCliff
static const uint8_t LeftBumper
static const uint8_t CenterBumper
static const uint8_t LeftWheel
float percent() const
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
void add(const std::string &key, const T &val)
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
void run(diagnostic_updater::DiagnosticStatusWrapper &stat)
static const uint8_t RightBumper


kobuki_node
Author(s): Daniel Stonier, Younghun Ju, Jorge Santos Simon
autogenerated on Mon Jun 10 2019 13:45:13