Thank you @Eric-Katzfey ,for the confirmation with respect to the approach. Can you help me the code, maybe with providing a sample code.
I wrote a code to receive the data but the code was not connecting the Flight controller. I am providing the code here, Can you verify the code.
from pymavlink import mavutil
import time
import logging
logging.basicConfig(level=logging.INFO)
# Connection string for voxl-mavlink-server
connection_string = 'udp:192.168.8.1:14558'
# Function to send a heartbeat message
def send_heartbeat(mavlink_connection):
mavlink_connection.mav.heartbeat_send(
mavutil.mavlink.MAV_TYPE_GCS, # Type: Ground Control Station
mavutil.mavlink.MAV_AUTOPILOT_INVALID, # Autopilot: Not a specific autopilot
0, # Base mode
0, # Custom mode
mavutil.mavlink.MAV_STATE_ACTIVE # State: Active
)
logging.info("Heartbeat sent.")
def main():
try:
logging.info(f"Connecting to {connection_string}...")
# Establish MAVLink connection
mav = mavutil.mavlink_connection(connection_string)
# Send an initial heartbeat to register as a GCS
logging.info("Sending initial heartbeat...")
send_heartbeat(mav)
# Wait for heartbeat from the flight controller
logging.info("Waiting for heartbeat from the flight controller...")
mav.wait_heartbeat(timeout=10)
logging.info(f"Heartbeat received! System_ID: {mav.target_system}, Component_ID: {mav.target_component}")
# Request RC_CHANNELS data stream at 1 Hz
mav.mav.request_data_stream_send(
mav.target_system,
mav.target_component,
mavutil.mavlink.MAV_DATA_STREAM_RC_CHANNELS,
1, # Stream rate in Hz (1 Hz)
1 # Enable the stream
)
# Periodically send heartbeats to keep the connection alive
last_heartbeat_time = time.time()
while True:
# Send a heartbeat every 1 second
current_time = time.time()
if current_time - last_heartbeat_time > 1:
send_heartbeat(mav)
last_heartbeat_time = current_time
# Listen for incoming messages
msg = mav.recv_match(blocking=True)
if msg:
msg_type = msg.get_type()
logging.info(f"Received message: {msg_type}")
# If it's an RC_CHANNELS message, print the values
if msg_type == 'RC_CHANNELS':
logging.info(f"Channel 1: {msg.chan1_raw}")
logging.info(f"Channel 2: {msg.chan2_raw}")
logging.info(f"Channel 3: {msg.chan3_raw}")
logging.info(f"Channel 4: {msg.chan4_raw}")
except KeyboardInterrupt:
logging.info("Exiting program.")
except Exception as e:
logging.error(f"An error occurred: {e}")
if __name__ == "__main__":
main()
The following is the output I got and it was stuck here and not moving forward.
INFO:root:Connecting to udp:192.168.8.1:14559...
INFO:root:Sending initial heartbeat...
INFO:root:Heartbeat sent.
INFO:root:Waiting for heartbeat from the flight controller...
INFO:root:Heartbeat received! System_ID: 0, Component_ID: 0