nvidia_temp.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2010, Willow Garage, Inc.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of the Willow Garage nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 
35 ##\author Kevin Watts
36 ##\brief Publishes diagnostic data on temperature and usage for a Quadro 600 GPU
37 
38 from __future__ import with_statement, division
39 
40 PKG = 'pr2_computer_monitor'
41 import roslib; roslib.load_manifest(PKG)
42 
43 import rospy
44 
45 from diagnostic_msgs.msg import DiagnosticArray, DiagnosticStatus
46 from pr2_msgs.msg import GPUStatus
47 
48 import pr2_computer_monitor
49 
50 class NVidiaTempMonitor(object):
51  def __init__(self):
52  self._pub = rospy.Publisher('/diagnostics', DiagnosticArray, queue_size=10)
53  self._gpu_pub = rospy.Publisher('gpu_status', GPUStatus, queue_size=10)
54 
55  def pub_status(self):
56  gpu_stat = GPUStatus()
57  stat = DiagnosticStatus()
58  try:
59  card_out = pr2_computer_monitor.get_gpu_status()
60  gpu_stat = pr2_computer_monitor.parse_smi_output(card_out)
61  stat = pr2_computer_monitor.gpu_status_to_diag(gpu_stat)
62  except Exception as e:
63  import traceback
64  rospy.logerr('Unable to process nVidia GPU data')
65  rospy.logerr(traceback.format_exc())
66 
67  gpu_stat.header.stamp = rospy.get_rostime()
68 
69  array = DiagnosticArray()
70  array.header.stamp = rospy.get_rostime()
71 
72  array.status = [ stat ]
73 
74  self._pub.publish(array)
75  self._gpu_pub.publish(gpu_stat)
76 
77 if __name__ == '__main__':
78  rospy.init_node('nvidia_temp_monitor')
79 
80  monitor = NVidiaTempMonitor()
81  my_rate = rospy.Rate(1.0)
82  while not rospy.is_shutdown():
83  monitor.pub_status()
84  my_rate.sleep()
85 
86 


pr2_computer_monitor
Author(s): Kevin Watts (watts@willowgarage.com)
autogenerated on Tue Jun 1 2021 02:50:51