twist_mux_diagnostics.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (CC BY-NC-SA 4.0 License)
00003  *
00004  *  Copyright (c) 2014, PAL Robotics, S.L.
00005  *  All rights reserved.
00006  *
00007  *  This work is licensed under the Creative Commons
00008  *  Attribution-NonCommercial-ShareAlike 4.0 International License.
00009  *
00010  *  To view a copy of this license, visit
00011  *  http://creativecommons.org/licenses/by-nc-sa/4.0/
00012  *  or send a letter to
00013  *  Creative Commons, 444 Castro Street, Suite 900,
00014  *  Mountain View, California, 94041, USA.
00015  *********************************************************************/
00016 
00017 /*
00018  * @author Enrique Fernandez
00019  */
00020 
00021 #include <twist_mux/twist_mux_diagnostics.h>
00022 #include <twist_mux/twist_mux_diagnostics_status.h>
00023 
00024 #include <diagnostic_updater/diagnostic_updater.h>
00025 
00026 namespace twist_mux
00027 {
00028 
00029 TwistMuxDiagnostics::TwistMuxDiagnostics()
00030 {
00031   diagnostic_.add("Twist mux status", this, &TwistMuxDiagnostics::diagnostics);
00032   diagnostic_.setHardwareID("none");
00033 }
00034 
00035 TwistMuxDiagnostics::~TwistMuxDiagnostics()
00036 {}
00037 
00038 void TwistMuxDiagnostics::update(const bool force_update)
00039 {
00040   if (force_update)
00041   {
00042     diagnostic_.force_update();
00043   }
00044   else
00045   {
00046     diagnostic_.update();
00047   }
00048 }
00049 
00050 void TwistMuxDiagnostics::updateStatus(const status_type::ConstPtr& status)
00051 {
00052   ROS_DEBUG_THROTTLE(1.0, "Updating status.");
00053 
00054   const bool has_status_changed =
00055     // @todo the comparison between vectors to lists is failing,
00056     // or for the internal elements!
00057     //*(status_.velocity_hs) != *(status->velocity_hs) ||
00058     //*(status_.lock_hs)     != *(status->lock_hs)     ||
00059      status_.priority    !=  status->priority;
00060 
00061   status_.velocity_hs = status->velocity_hs;
00062   status_.lock_hs     = status->lock_hs;
00063   status_.priority    = status->priority;
00064 
00065   update(has_status_changed);
00066 }
00067 
00068 void TwistMuxDiagnostics::diagnostics(diagnostic_updater::DiagnosticStatusWrapper& stat)
00069 {
00070   stat.summary(OK, "ok");
00071 
00072   for (const auto& velocity_h : *status_.velocity_hs)
00073   {
00074     stat.addf("velocity " + velocity_h.getName(),
00075               " %s (listening to %s @ %fs with priority #%d)",
00076               (velocity_h.isMasked(status_.priority) ? "masked" : "unmasked"),
00077               velocity_h.getTopic().c_str(),
00078               velocity_h.getTimeout(),
00079               static_cast<int>(velocity_h.getPriority()));
00080   }
00081 
00082   for (const auto& lock_h : *status_.lock_hs)
00083   {
00084     stat.addf("lock " + lock_h.getName(),
00085               " %s (listening to %s @ %fs with priority #%d)",
00086               (lock_h.isLocked() ? "locked" : "free"),
00087               lock_h.getTopic().c_str(),
00088               lock_h.getTimeout(),
00089               static_cast<int>(lock_h.getPriority()));
00090   }
00091 
00092   stat.add("current lock priority", static_cast<int>(status_.priority));
00093 
00094   ROS_DEBUG_THROTTLE(1.0, "Publishing diagnostics.");
00095 }
00096 
00097 } // namespace twist_mux


twist_mux
Author(s): Enrique Fernandez , Siegfried-A. Gevatter Pujals
autogenerated on Sat Jun 8 2019 20:13:46