sr_diagnosticer.cpp
Go to the documentation of this file.
1 
30 // ROS include
31 #include <ros/ros.h>
32 
33 // messages
34 #include <diagnostic_msgs/DiagnosticStatus.h>
35 #include <diagnostic_msgs/DiagnosticArray.h>
36 
37 // generic C/C++ include
38 #include <vector>
39 #include <string>
40 #include <map>
41 #include <sstream>
42 
43 #include <boost/smart_ptr.hpp>
44 
46 
47 using ros::Rate;
50 
51 namespace shadowrobot
52 {
53 
54 // 9 is the number of messages sent on the palm: used in
55 // converting rate to Hz
56  const double SRDiagnosticer::palm_numb_msg_const = 9.0;
57  const double SRDiagnosticer::palm_msg_rate_const = 4000.0;
58 
60 // CONSTRUCTOR/DESTRUCTOR //
62 
64  n_tilde("~"), publish_rate(0.0)
65  {
66  sr_articulated_robot = sr_art_robot;
67 
68  // set publish frequency
69  double publish_freq;
70  n_tilde.param("publish_frequency_diagnostics", publish_freq, 1.0);
71  publish_rate = Rate(publish_freq);
72 
73  // publishes /diagnostics messages
74  sr_diagnostics_pub = node.advertise<diagnostic_msgs::DiagnosticArray>("diagnostics", 2);
75 
76  hardware_type = hw_type;
77  }
78 
80  {
81  // if( shadowhand != NULL )
82  // delete shadowhand;
83  }
84 
86 // PUBLISH METHOD //
89  {
90  diagnostic_msgs::DiagnosticArray diag_msg;
91 
92  std::vector<diagnostic_msgs::DiagnosticStatus> vec_diag_msg;
93 
94  std::vector<DiagnosticData> diagnostics = sr_articulated_robot->getDiagnostics();
95 
96  std::stringstream ss;
97 
98  for (unsigned int i = 0; i < diagnostics.size(); ++i)
99  {
100  diagnostic_msgs::DiagnosticStatus diag;
101 
102  std::vector<diagnostic_msgs::KeyValue> keyvalues;
103 
104  diag.level = diagnostics[i].level;
105 
106  switch (hardware_type)
107  {
108  case sr_hand_hardware:
109  diag.name = "srh/" + diagnostics[i].joint_name;
110  break;
111  case sr_arm_hardware:
112  diag.name = "sr_arm/" + diagnostics[i].joint_name;
113  break;
114  default:
115  diag.name = diagnostics[i].joint_name;
116  break;
117  }
118 
119  diagnostic_msgs::KeyValue keyval;
120  keyval.key = "Target";
121 
122  ss.str("");
123  ss << diagnostics[i].target;
124  keyval.value = ss.str();
125  keyvalues.push_back(keyval);
126 
127  keyval.key = "Position";
128  ss.str("");
129  ss << diagnostics[i].position;
130  keyval.value = ss.str();
131  keyvalues.push_back(keyval);
132 
133  keyval.key = "Flags";
134  ss.str("");
135  ss << diagnostics[i].flags;
136  keyval.value = ss.str();
137  keyvalues.push_back(keyval);
138 
139  // get all the debug values
140  std::map<const std::string, const unsigned int>::const_iterator iter;
141  for (iter = debug_values::names_and_offsets.begin();
142  iter != debug_values::names_and_offsets.end(); ++iter)
143  {
144  keyval.key = iter->first;
145  ss.str("");
146  ss << diagnostics[i].debug_values[iter->first];
147  keyval.value = ss.str();
148  keyvalues.push_back(keyval);
149  }
150  if (diag.level == 0)
151  {
152  diag.message = "OK";
153  }
154 
155  diag.values = keyvalues;
156  vec_diag_msg.push_back(diag);
157  }
158 
159  // set the standard message
160  diag_msg.status = vec_diag_msg;
161  // publish the diagnostic data
162 
163  diag_msg.header.stamp = ros::Time::now();
164  sr_diagnostics_pub.publish(diag_msg);
165 
166  ros::spinOnce();
168  }
169 
170 } // namespace shadowrobot
171 
172 
173 /* For the emacs weenies in the crowd.
174 Local Variables:
175  c-basic-offset: 2
176 End:
177 */
178 
void publish(const boost::shared_ptr< M > &message) const
static const double palm_msg_rate_const
const to convert the rate data to Hz
Publisher sr_diagnostics_pub
The publisher which publishes the data to the \/diagnostics topic.
static const std::map< const std::string, const unsigned int > names_and_offsets
a map containing the names and offsets of the smart motor node
The Diagnosticer is a ROS publisher which publishes diagnostic data regarding the Dextrous Hand or th...
hardware_types hardware_type
store the hardware_type for this diagnosticer.
bool param(const std::string &param_name, T &param_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool sleep()
This is a parent class for the different types of Shadowhand we can have. It makes it possible to swa...
static const double palm_numb_msg_const
const to convert the rate data to Hz
SRDiagnosticer(boost::shared_ptr< SRArticulatedRobot > sr_art_robot, hardware_types hw_type)
boost::shared_ptr< SRArticulatedRobot > sr_articulated_robot
The shadowhand object (can be either an object connected to the real robot or a virtual hand)...
static Time now()
hardware_types
An enum containing the different types of hardware the diagnosticer is publishing data about...
Rate publish_rate
the rate at which the data will be published. This can be set by a parameter in the launch file...
ROSCPP_DECL void spinOnce()
NodeHandle node
ros node handle


sr_hand
Author(s): Ugo Cupcic
autogenerated on Tue Oct 13 2020 03:55:53