Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cpu temperature alarm #1217

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions alarm_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3

import rospy

from std_msgs.msg import Float32

global alarm_pub

def cpu_temp_callback(temp):

# Sets of cpu temp alarm
if float(temp.data) > 75:
rospy.logwarn(f"CPU TEMPERATURE EXCEEDS: {temp.data}")
alarm_pub.publish(True)

else:
alarm_pub.publish(False)



def cpu_temp_alarm():
global alarm_pub

# Initializing node
rospy.init_node('cpu_temp_alarm', anonymous=True)

rospy.Subscriber('cpu_temperature', Float32, cpu_temp_callback)
alarm_pub = rospy.Publisher('cpu_alarm', bool, queue_size=10)

rospy.spin()



if __name__ == '__main__':

try:
cpu_temp_alarm()
except rospy.InterruptedError:
pass
49 changes: 49 additions & 0 deletions cpu_temp_alarm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3

import psutil
import rospy
from std_msgs.msg import Float32


def get_cpu_temp():
# Checks computer sensors
temp = psutil.sensors_temperatures()
if 'coretemp' in temp:
return temp['coretemp'][0].current
else:
raise ValueError("Core temp not found!")



def cpu_temp_ROS():

# ROS initializing

rospy.init_node('cpu_temp_node', anonymous=True)
pub = rospy.Publisher('cpu_temperature', Float32, queue_size=18)
rate = rospy.Rate(1)

# Loops through and actively gets cpu temp

while not rospy.is_shutdown():
cpu_temp = get_cpu_temp()
rospy.loginfo("CPU TEMP: %f", cpu_temp)
pub.publish(cpu_temp)
rate.sleep()


if __name__ == '__main__':
try:
cpu_temp_ROS()

# For interruption failure

except rospy.ROSInterruptException:
pass







Loading