31 from sr_robot_msgs.msg
import MechanismStatistics
32 from diagnostic_msgs.msg
import DiagnosticArray, DiagnosticStatus, KeyValue
36 d = DiagnosticStatus()
37 d.name =
'Controller (' + c.name +
')' 45 if (
not use_sim_time
and c.num_control_loop_overruns > 0):
46 d.message +=
' !!! Broke Realtime, used ' + \
47 str(int(c.max_time.to_sec() * 1e6)) + \
48 ' micro seconds in update loop' 49 if c.time_last_control_loop_overrun + rospy.Duration(30.0) > rospy.Time.now():
53 KeyValue(
'Avg Time in Update Loop (usec)', str(int(c.mean_time.to_sec() * 1e6))))
55 KeyValue(
'Max Time in update Loop (usec)', str(int(c.max_time.to_sec() * 1e6))))
57 KeyValue(
'Variance on Time in Update Loop', str(int(c.variance_time.to_sec() * 1e6))))
59 KeyValue(
'Percent of Cycle Time Used', str(int(c.mean_time.to_sec() / 0.00001))))
61 KeyValue(
'Number of Control Loop Overruns', str(int(c.num_control_loop_overruns))))
63 KeyValue(
'Timestamp of Last Control Loop Overrun (sec)', str(int(c.time_last_control_loop_overrun.to_sec()))))
66 rospy.init_node(
'controller_to_diagnostics')
67 use_sim_time = rospy.get_param(
'use_sim_time',
False)
68 pub_diag = rospy.Publisher(
'/diagnostics', DiagnosticArray)
70 last_publish_time = rospy.Time(0.0)
74 global last_publish_time
75 now = rospy.get_rostime()
76 if (now - last_publish_time).to_sec() > 1.0:
77 if len(msg.controller_statistics) == 0:
79 d.header.stamp = msg.header.stamp
80 ds = DiagnosticStatus()
81 ds.name =
"Controller: No controllers loaded in controller manager" 85 for c
in msg.controller_statistics:
87 d.header.stamp = msg.header.stamp
90 last_publish_time = now
92 rospy.Subscriber(
'mechanism_statistics', MechanismStatistics, state_cb)
def controller_to_diag(c)