모든 MAVLink 구성 요소는 주기적으로 HEARTBEAT 메시지를 브로드캐스트하고 다른 시스템의 하트비트를 수신해야 합니다. 시스템은 다른 시스템에서 정기적으로 HEARTBEAT를 받는 한 자신이 다른 시스템에 연결된 것으로 간주합니다 .
메시지 는 생성된 Python 다이알렉트 파일의 HEARTBEAT메시지를 사용하여 보낼 수 있습니다 . MAVLink.heartbeat_send()메서드 정의는 다음과 같습니다.
defheartbeat_send(self,type,autopilot,base_mode,custom_mode,system_status,mavlink_version=3,force_mavlink1=False):''' The heartbeat message shows that a system is present and responding. The type of the MAV and Autopilot hardware allow the receiving system to treat further messages from this system appropriate (e.g. by laying out the user interface based on the autopilot). type : Type of the MAV (quadrotor, helicopter, etc.) (type:uint8_t, values:MAV_TYPE) autopilot : Autopilot type / class. (type:uint8_t, values:MAV_AUTOPILOT) base_mode : System mode bitmap. (type:uint8_t, values:MAV_MODE_FLAG) custom_mode : A bitfield for use for autopilot-specific flags (type:uint32_t) system_status : System status flag. (type:uint8_t, values:MAV_STATE) mavlink_version : MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version (type:uint8_t)'''
mavutil.mavlink_connection()에서 반환하는 the_connection 이라는 mavutil 링크를 사용한다고 가정하면 다음과 같이 하트비트를 보낼 수 있습니다.
하트비트를 전송해야 하는 속도는 채널에 따라 다르지만 일반적으로 1Hz입니다.
일반적으로 다른 모든 메시지와 동일한 스레드에서 보내야 합니다. 이는 스레드가 정상일 때만 하트비트가 게시되도록 하기 위한 것입니다.
Pymavlink 라이브러리는 이미 서명 메시지에 대해 예상되는 거의 모든 동작을 구현합니다. 비밀 키와 초기 타임스탬프를 제공하고 선택적으로 발신 메시지의 서명 여부, 링크 ID 및 수락할 서명되지 않은 메시지(있는 경우)를 결정하기 위한 콜백을 지정하기만 하면 됩니다.
이를 수행하는 방법은 mavutil을 사용하여 연결을 관리하는지 또는 MAVLink객체를 직접 사용하는지에 따라 다릅니다.
# Send heartbeat from a GCS (types are define as enum in the dialect file).
the_connection.mav.heartbeat_send(mavutil.mavlink.MAV_TYPE_GCS,
mavutil.mavlink.MAV_AUTOPILOT_INVALID, 0, 0, 0)
# Send heartbeat from a MAVLink application.
the_connection.mav.heartbeat_send(mavutil.mavlink.MAV_TYPE_ONBOARD_CONTROLLER,
mavutil.mavlink.MAV_AUTOPILOT_INVALID, 0, 0, 0)
# Create a MAVLink instance (in this case on a file object "f")
mav = mavlink.MAVLink(f)
if signing:
mav.signing.secret_key = chr(42)*32
mav.signing.link_id = 0
mav.signing.timestamp = 0
mav.signing.sign_outgoing = True
#Setup signing
def setup_signing(self, secret_key, sign_outgoing=True, allow_unsigned_callback=None, initial_timestamp=None, link_id=None)
# Disable signing (clear secret key and all the other settings specified with setup_signing)
def disable_signing(self):
bool allow_unsigned_callback(self, msgId)
# Assuming you already have a connection set up
the_connection = mavutil.mavlink_connection(...)
# Create a callback to specify the messages to accept
def my_allow_unsigned_callback(self,msgId):
#Allow radio status messages
if msgId==mavutil.mavlink.MAVLINK_MSG_ID_RADIO_STATUS:
return True
return False
# Pass the callback to the connection (here we also pass an arbitrary secret key)
secret_key = chr(42)*32
the_connection.setup_signing(secret_key, sign_outgoing=True, allow_unsigned_callback=my_allow_unsigned_callback)