@ -45,7 +45,7 @@ from . import mavlinkObject as mo
from . utils import setup_logger
logger = setup_logger ( os . path . basename ( __file__ ) )
MODULE_VER = " 2. 1 0"
MODULE_VER = " 2. 5 0"
FC_ROS_DOMAIN_ID = " 0 "
NODE_KEYS = ( " status_publisher " , " command_service " , " rtcm_relay " )
@ -76,6 +76,7 @@ class PublishRateController:
' vfr_hud ' : 0.0 , # VFR HUD (地速 空速 絕對高度 爬升率 航向 油門)
' mode ' : 0.0 , # 飛行模式 (已經在 summary 裡 未來移除)
' summary ' : 0.0 , # 載具摘要 (sysid 飛行模式 解鎖上鎖 gps狀態)
' system_diagnostics ' : 0.0 , # SYS_STATUS 系統診斷
# 在這裡新增更多 topics...
}
# 記錄每個 topic 的最後發布時間 {(sysid, topic): timestamp}
@ -186,6 +187,7 @@ class VehicleStatusPublisher(Node):
self . _publish_vfr_hud ( sysid , status )
self . _publish_mode ( sysid , status )
self . _publish_summary ( vehicle )
self . _publish_system_diagnostics ( sysid , status )
# 在這裡新增更多 publish 方法調用...
def _get_or_create_publisher ( self , sysid : int , topic : str , msg_type , qos : int = 1 ) :
@ -439,11 +441,7 @@ class VehicleStatusPublisher(Node):
' armed ' : status . armed if status . armed is not None else False ,
# 'mode_custom': status.mode.custom_mode if status.mode.custom_mode else 0,
' mode_name ' : status . mode . mode_name if status . mode . mode_name else " UNKNOWN " ,
# 'latitude': status.position.latitude if status.position.latitude else 0.0,
# 'longitude': status.position.longitude if status.position.longitude else 0.0,
# 'altitude': status.position.altitude if status.position.altitude else 0.0,
# 'battery_percent': status.battery.remaining if status.battery.remaining else 0,
# 'gps_fix': status.gps.fix_type if status.gps.fix_type else 0,
' mav_status ' : status . system_status if status . system_status is not None else 0 ,
' connection_type ' : vehicle . connected_via . value ,
' last_update ' : component . packet_stats . last_msg_time if component . packet_stats . last_msg_time else 0.0 ,
}
@ -452,6 +450,37 @@ class VehicleStatusPublisher(Node):
msg . data = json . dumps ( summary )
publisher . publish ( msg )
def _publish_system_diagnostics ( self , sysid : int , status : mvv . ComponentStatus ) :
""" 發布 SYS_STATUS 系統診斷資訊 """
if not self . rate_controller . should_publish ( sysid , ' system_diagnostics ' ) :
return
diag = status . sys_diag
if diag . sensors_install_mask is None :
return
publisher = self . _get_or_create_publisher (
sysid , ' system_diagnostics ' , fcmsg . SystemDiagnosticsRaw
)
if publisher . get_subscription_count ( ) == 0 :
return
msg = fcmsg . SystemDiagnosticsRaw ( )
msg . stamp = self . get_clock ( ) . now ( ) . to_msg ( )
msg . sensors_install_mask = int ( diag . sensors_install_mask )
msg . sensors_enabled_mask = int ( diag . sensors_enabled_mask or 0 )
msg . sensors_health_mask = int ( diag . sensors_health_mask or 0 )
msg . mcu_load = int ( diag . mcuLoad or 0 )
msg . bus_error_rate = int ( diag . busErrorRate or 0 )
msg . bus_error_count = int ( diag . busErrorCount or 0 )
msg . errors_count1 = int ( diag . errors_count1 or 0 )
msg . errors_count2 = int ( diag . errors_count2 or 0 )
msg . errors_count3 = int ( diag . errors_count3 or 0 )
msg . errors_count4 = int ( diag . errors_count4 or 0 )
publisher . publish ( msg )
# ═══════════════════════════════════════════════════════════════
# 【新增 Topic 位置 3/4】
# 若要新增 topic, 請在此處實作對應的發布方法