6 PHM Hazard Rate Calculation Node 11 from std_msgs.msg
import String
12 from phm_msgs.msg
import HazardRate
17 Hazard Rate Calculation Node 20 Topic name = /gui_hazard_rate 24 Topic nane = /phm_hazard_rate 25 Message type = HazardRate 36 Hazard Rate Calculation Node Main Function 39 publisher_phm_hazard_rate = rospy.Publisher(
'/phm_hazard_rate', HazardRate, queue_size=10)
43 phm_hazard_rate = HazardRate()
45 while not rospy.is_shutdown():
47 ros_time = rospy.get_rostime()
49 publisher_phm_hazard_rate.publish(phm_hazard_rate)
56 Callback function of /gui_hazard_rate 64 Message function of the /phm_hazard_rate to be published 66 phm_hazard_rate = HazardRate()
68 module_names = list(hazard_rate_dict[
"System"].keys())
69 module_names.remove(
"Failure Rate")
71 system_hazard_rate_keys = list(hazard_rate_dict[
"System"][
"Failure Rate"].keys())
72 system_hazard_rate_keys.remove(
"Nominal")
74 phm_hazard_rate.stamp = ros_time
75 phm_hazard_rate.system_value = float(hazard_rate_dict[
"System"][
"Failure Rate"][
"Nominal"])
77 if system_hazard_rate_keys:
78 phm_hazard_rate.system_sensor_based_value = float(hazard_rate_dict[
"System"][
"Failure Rate"][
"Sensor Based"])
81 module_values = list()
82 module_sensor_based_values = list()
83 phm_hazard_rate.module_names = list(module_names)
85 for module
in module_names:
86 module_hazard_rate_keys = list(hazard_rate_dict[
"System"][str(module)][
"Failure Rate"].keys())
87 module_hazard_rate_keys.remove(
"Nominal")
89 current_module_value = float(hazard_rate_dict[
"System"][str(module)][
"Failure Rate"][
"Nominal"])
90 module_values.append(current_module_value)
92 if module_hazard_rate_keys:
93 current_module_sensor_based_value = float(hazard_rate_dict[
"System"][str(module)][
"Failure Rate"][
"Sensor Based"])
94 module_sensor_based_values.append(current_module_sensor_based_value)
97 module_sensor_based_values.append(float(0.0))
99 phm_hazard_rate.module_values = module_values
100 phm_hazard_rate.module_sensor_based_values = module_sensor_based_values
102 return phm_hazard_rate
105 if __name__ ==
'__main__':
106 rospy.init_node(
'phm_hazard_rate_calculation_node')
def phm_gui_hazard_rate_callback_func(self, phm_msg)
def set_hazard_rate_func(cls, hazard_rate_dict, ros_time)