controller_diagnostics.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2009, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the Willow Garage nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
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 // Controller statistics
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 


pr2_mechanism_diagnostics
Author(s): Kevin Watts
autogenerated on Mon Dec 2 2013 13:13:06