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/joint_diagnostics.h"
00037 #include <limits>
00038
00039 #include <boost/accumulators/statistics/max.hpp>
00040 #include <boost/accumulators/statistics/min.hpp>
00041
00042 using namespace pr2_mechanism_diagnostics;
00043 using namespace std;
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 JointStats::JointStats(string nam) :
00059 needs_reset(true),
00060 name(nam),
00061 position(0),
00062 velocity(0),
00063 measured_effort(0),
00064 commanded_effort(0),
00065 is_calibrated(false),
00066 violated_limits(false),
00067 odometer(0),
00068 max_pos_val(-1 * numeric_limits<double>::max()),
00069 min_pos_val(numeric_limits<double>::max()),
00070 max_abs_vel_val(-1 * numeric_limits<double>::max()),
00071 max_abs_eff_val(-1 * numeric_limits<double>::max())
00072 { }
00073
00074 void JointStats::reset_vals()
00075 {
00076 needs_reset = false;
00077
00078 max_pos_val = -1 * numeric_limits<double>::max();
00079 min_pos_val = numeric_limits<double>::max();
00080 max_abs_vel_val = -1 * numeric_limits<double>::max();
00081 max_abs_eff_val = -1 * numeric_limits<double>::max();
00082 }
00083
00084
00085 boost::shared_ptr<diagnostic_updater::DiagnosticStatusWrapper> JointStats::toDiagStat() const
00086 {
00087 boost::shared_ptr<diagnostic_updater::DiagnosticStatusWrapper> stat(new diagnostic_updater::DiagnosticStatusWrapper);
00088
00089 stat->name = "Joint (" + name + ")";
00090
00091 if (is_calibrated)
00092 stat->summary(diagnostic_msgs::DiagnosticStatus::OK, "OK");
00093 else
00094 stat->summary(diagnostic_msgs::DiagnosticStatus::WARN, "Uncalibrated");
00095
00096 if ((ros::Time::now() - updateTime).toSec() > 3)
00097 stat->summary(diagnostic_msgs::DiagnosticStatus::ERROR, "No updates");
00098
00099 if (!is_valid(position) || !is_valid(velocity) ||
00100 !is_valid(measured_effort) || !is_valid(commanded_effort))
00101 {
00102 stat->summary(diagnostic_msgs::DiagnosticStatus::ERROR, "NaN Values in Joint State");
00103 }
00104
00105 stat->add("Position", position);
00106 stat->add("Velocity", velocity);
00107 stat->add("Measured Effort", measured_effort);
00108 stat->add("Commanded Effort", commanded_effort);
00109
00110 stat->add("Calibrated", is_calibrated);
00111
00112 stat->add("Odometer", odometer);
00113
00114 if (is_calibrated)
00115 {
00116 stat->add("Max Position", max_pos_val);
00117 stat->add("Min Position", min_pos_val);
00118 stat->add("Max Abs. Velocity", max_abs_vel_val);
00119 stat->add("Max Abs. Effort", max_abs_eff_val);
00120 }
00121 else
00122 {
00123 stat->add("Max Position", "N/A");
00124 stat->add("Min Position", "N/A");
00125 stat->add("Max Abs. Velocity", "N/A");
00126 stat->add("Max Abs. Effort", "N/A");
00127 }
00128
00129 stat->add("Limits Hit", violated_limits);
00130
00131 needs_reset = true;
00132
00133 return stat;
00134 }
00135
00136 bool JointStats::update(const pr2_mechanism_msgs::JointStatistics &js)
00137 {
00138 if (name != js.name)
00139 {
00140 ROS_ERROR("Joint statistics attempted to update with a different name! Old name: %s, new name: %s.", name.c_str(), js.name.c_str());
00141 return false;
00142 }
00143
00144 if (needs_reset)
00145 reset_vals();
00146
00147 if (js.is_calibrated)
00148 {
00149 max_pos_val = max(max_pos_val, js.max_position);
00150 min_pos_val = min(max_pos_val, js.min_position);
00151 max_abs_vel_val = max(max_abs_vel_val, js.max_abs_velocity);
00152 max_abs_eff_val = max(max_abs_eff_val, js.max_abs_effort);
00153 }
00154
00155 position = js.position;
00156 velocity = js.velocity;
00157 measured_effort = js.measured_effort;
00158 commanded_effort = js.commanded_effort;
00159 is_calibrated = js.is_calibrated;
00160 violated_limits = js.violated_limits;
00161 odometer = js.odometer;
00162
00163 updateTime = ros::Time::now();
00164
00165 return true;
00166 }
00167