motor_states_temperature_decomposer.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from hrpsys_ros_bridge.msg import MotorStates
4 from jsk_rviz_plugins.msg import OverlayText
5 from sensor_msgs.msg import JointState
6 #from sensor_msgs.msg import JointState as MotorStates
7 from std_msgs.msg import Float32
8 import rospy
9 from urdf_parser_py.urdf import URDF
10 
11 
12 g_publishers = []
13 g_effort_publishers = {}
14 g_text_publisher = None
15 safe_color = (52, 152, 219) # ~50
16 warning_color = (230, 126, 34) # 50~
17 fatal_color = (231, 76, 60) # 70~
19  global g_publishers
20  if num > len(g_publishers):
21  for i in range(len(g_publishers), num):
22  pub = rospy.Publisher('temperature_%02d' % (i), Float32, queue_size=1)
23  g_publishers.append(pub)
25  global g_effort_publishers
26  for name in names:
27  if not g_effort_publishers.has_key(name):
28  g_effort_publishers[name] = rospy.Publisher('effort_%s' % (name), Float32, queue_size=1)
29 
31  global g_publishers, g_text_publisher
32  #values = msg.position
33  values = msg.temperature
34  names = msg.name
35  allocatePublishers(len(values))
36  max_temparature = 0
37  max_temparature_name = ""
38  for name, val, pub in zip(names, values, g_publishers):
39  pub.publish(Float32(val))
40  if max_temparature < val:
41  max_temparature = val
42  max_temparature_name = name
43  if max_temparature:
44  if max_temparature > 70:
45  color = fatal_color
46  elif max_temparature > 50:
47  color = warning_color
48  else:
49  color = safe_color
50  text = OverlayText()
51  text.fg_color.r = color[0] / 255.0
52  text.fg_color.g = color[1] / 255.0
53  text.fg_color.b = color[2] / 255.0
54  text.fg_color.a = 1.0
55  text.bg_color.a = 0.0
56  text.text = "%dC -- (%s)" % (int(max_temparature), max_temparature_name)
57  g_text_publisher.publish(text)
58 
60  global g_effort_publishers, robot_model
61  values = msg.effort
62  names = msg.name
64  for val, name in zip(values, names):
65  # lookup effort limit
66  candidate_joints = [j for j in robot_model.joints if j.name == name]
67  if candidate_joints:
68  if candidate_joints[0].limit:
69  limit = candidate_joints[0].limit.effort
70  else:
71  limit = 0
72  if limit != 0:
73  g_effort_publishers[name].publish(Float32(abs(val/limit)))
74 
75 if __name__ == "__main__":
76  rospy.init_node("motor_state_temperature_decomposer")
77  robot_model = URDF.from_xml_string(rospy.get_param("/robot_description"))
78  g_text_publisher = rospy.Publisher("max_temparature_text", OverlayText, queue_size=1)
79  s = rospy.Subscriber("/motor_states", MotorStates, motorStatesCallback, queue_size=1)
80  s_joint_states = rospy.Subscriber("/joint_states", JointState, jointStatesCallback, queue_size=1)
81  #s = rospy.Subscriber("joint_states", MotorStates, motorStatesCallback)
82  rospy.spin()


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Sat Mar 20 2021 03:03:18