Class DiagnosticStatusWrapper

Inheritance Relationships

Base Type

  • public diagnostic_msgs::msg::DiagnosticStatus

Class Documentation

class DiagnosticStatusWrapper : public diagnostic_msgs::msg::DiagnosticStatus

Wrapper for the diagnostic_msgs::msg::DiagnosticStatus message that makes it easier to update.

This class handles common string formatting and vector handling issues for filling the diagnostic_msgs::msg::DiagnosticStatus message. It is a subclass of diagnostic_msgs::msg::DiagnosticStatus, so it can be passed directly to diagnostic publish calls.

Public Functions

inline DiagnosticStatusWrapper()
explicit DiagnosticStatusWrapper(const DiagnosticStatusWrapper &other) = delete

Copy constructor Defined and marked explicit so that you don’t accidentally use a function<void(DiagnosticStatusWrapper)> where a function<void(DiagnosticStatusWrapper &)> is needed. Otherwise, it’s easy to accidentally create a DiagnosticTask that silently does nothing.

Parameters:

other – Reference to object to copy

inline void summary(unsigned char lvl, const std::string s)

Fills out the level and message fields of the DiagnosticStatus.

Parameters:
  • lvl – Numerical level to assign to this Status (OK, Warn, Err).

  • s – Descriptive status message.

inline void mergeSummary(unsigned char lvl, const std::string s)

Merges a level and message with the existing ones.

It is sometimes useful to merge two DiagnosticStatus messages. In that case, the key value pairs can be unioned, but the level and summary message have to be merged more intelligently. This function does the merge in an intelligent manner, combining the summary in *this, with the one that is passed in.

The combined level is the greater of the two levels to be merged. If both levels are non-zero (not OK), the messages are combined with a semicolon separator. If only one level is zero, and the other is non-zero, the message for the zero level is discarded. If both are zero, the new message is ignored.

Parameters:
  • lvl – Numerical level to of the merged-in summary.

  • s – Descriptive status message for the merged-in summary.

inline void mergeSummary(const diagnostic_msgs::msg::DiagnosticStatus &src)

Version of mergeSummary that merges in the summary from another DiagnosticStatus.

Parameters:

src – DiagnosticStatus from which to merge the summary.

inline void mergeSummaryf(unsigned char lvl, const char *format, ...)

Formatted version of mergeSummary.

This method is identical to mergeSummary, except that the message is an sprintf-style format string.

Parameters:
  • lvl – Numerical level to of the merged-in summary.

  • format – Format string for the descriptive status message for the merged-in summary.

  • ... – Values to be formatted by the format string.

inline void summaryf(unsigned char lvl, const char *format, ...)

Formatted version of summary.

This method is identical to summary, except that the message is an sprintf-style format string.

Parameters:
  • lvl – Numerical level to assign to this Status (OK, Warn, Err).

  • s – Format string for the descriptive status message.

  • ... – Values to be formatted by the format string.

inline void clearSummary()

clears the summary, setting the level to zero and the message to “”.

inline void summary(const diagnostic_msgs::msg::DiagnosticStatus &src)

copies the summary from a DiagnosticStatus message

Parameters:

src – StatusWrapper to copy the summary from.

template<class T>
inline void add(const std::string &key, const T &val)

Add a key-value pair.

This method adds a key-value pair. Any type that has a << stream operator can be passed as the second argument. Formatting is done using a std::stringstream.

Parameters:
  • key – Key to be added.

  • value – Value to be added.

inline void addf(const std::string &key, const char *format, ...)

Add a key-value pair using a format string.

This method adds a key-value pair. A format string is used to set the value. The current implementation limits the value to 1000 characters in length.

inline void clear()

Clear the key-value pairs.

The values vector containing the key-value pairs is cleared.

template<>
inline void add(const std::string &key, const bool &b)