Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "pr2_mechanism_diagnostics/controller_diagnostics.h"
00037
00038
00039 using namespace pr2_mechanism_diagnostics;
00040 using namespace std;
00041
00042
00043 ControllerStats::ControllerStats(string nam, bool disable_warnings) :
00044 name(nam),
00045 timestamp(0),
00046 running(false),
00047 num_overruns(0),
00048 last_overrun_time(0),
00049 disable_warnings_(disable_warnings)
00050 { }
00051
00052 bool ControllerStats::update(const pr2_mechanism_msgs::ControllerStatistics &cs)
00053 {
00054 if (name != cs.name)
00055 {
00056 ROS_ERROR("Controller statistics attempted to update with a different name! Old name: %s, new name: %s.", name.c_str(), cs.name.c_str());
00057 return false;
00058 }
00059
00060 timestamp = cs.timestamp;
00061 running = cs.running;
00062 max_time = cs.max_time;
00063 mean_time = cs.mean_time;
00064 variance_time = cs.variance_time;
00065 num_overruns = cs.num_control_loop_overruns;
00066 last_overrun_time = cs.time_last_control_loop_overrun;
00067
00068 updateTime = ros::Time::now();
00069
00070 return true;
00071 }
00072
00073 boost::shared_ptr<diagnostic_updater::DiagnosticStatusWrapper> ControllerStats::toDiagStat() const
00074 {
00075 boost::shared_ptr<diagnostic_updater::DiagnosticStatusWrapper> stat(new diagnostic_updater::DiagnosticStatusWrapper);
00076
00077 stat->name = "Controller (" + name + ")";
00078
00079 if (running)
00080 stat->summary(diagnostic_msgs::DiagnosticStatus::OK, "Running");
00081 else
00082 stat->summary(diagnostic_msgs::DiagnosticStatus::OK, "Stopped");
00083
00084 if (!disable_warnings_ && num_overruns > 0)
00085 {
00086 if ((ros::Time::now() - last_overrun_time).toSec() < 30)
00087 stat->summary(diagnostic_msgs::DiagnosticStatus::WARN, "!!! Broke Realtime, used more than 1000 micro seconds in update loop");
00088 else
00089 stat->summary(diagnostic_msgs::DiagnosticStatus::OK, "!!! Broke Realtime, used more than 1000 micro seconds in update loop");
00090 }
00091
00092 stat->add("Avg Update Time (usec)", (int)(mean_time.toSec() * 1e6));
00093 stat->add("Max Update Time (usec)", (int)(max_time.toSec() * 1e6));
00094 stat->add("Variance Update Time (usec)", (int) (variance_time.toSec() * 1e6));
00095 stat->add("Percent of Cycle Time Used", (int) (mean_time.toSec() / 0.00001));
00096 stat->add("Number of Control Loop Overruns", num_overruns);
00097 stat->add("Timestamp of Last Overrun (sec)", last_overrun_time.toSec());
00098
00099 return stat;
00100 }
00101