mavlink / MAVSDK-Python

MAVSDK client for Python.
https://mavsdk.mavlink.io
BSD 3-Clause "New" or "Revised" License
328 stars 221 forks source link

How to use mavsdk-python to send a heartbeat packet from the ground station to the flight controller? #577

Open larryteal opened 1 year ago

larryteal commented 1 year ago

I'm trying to make a ground station and need to send heartbeat packets to the flight controller, but I can't find the API?

JonasVautherin commented 1 year ago

If you run mavsdk_server manually, you need to set the address of the drone there. Something like this:

./mavsdk_server udp://192.168.1.12:14557

Where 192.168.1.12 is the IP of the drone and 14557 the port on which the drone is listening for MAVLink.

If you run the embedded mavsdk_server, you have to do it in the await drone.connect(...) call, as documented here:

drone = System()
await drone.connect(system_address="udp://192.168.1.12:14557")

Finally, note that the "usual" way with PX4 is that the drone broadcasts heartbeats (on 14550/udp) and the ground station picks it up, rather than what you are trying to do here (which is fine as well).

larryteal commented 1 year ago

Thank you, I can receive messages and send commands normally, but when I use the QGC ground station to connect to the flight controller, the buzzer of the flight controller will sound to indicate that the ground station is connected (there will be a difference sound when the connection is disconnected), but when I use mavsdk-python to connect to the flight control, the flight control will not make any sound. Then I searched some information and did some tests and confirmed that the ground station should send heartbeat packet to the flight control. I want to make a ground station with the same function as QGC based on mavsdk-python. I am new to the ground station. I can't confirm the purpose of the heartbeat packet sent by the ground station to the flight controller, but QGC does this. Unfortunately, I did not find an API for sending heartbeat packets in the documentation

JonasVautherin commented 1 year ago

So if MAVSDK detects the drone, it will automatically send back HEARTBEATS. The typical way is to have MAVSDK listen on 14550 or (by default) 14540 for heartbeats coming from the drone.

Now depending on your setup, it could be that the drone can send messages to MAVSDK, but messages coming back from MAVSDK do not reach the drone for some reason.

An easy way is to try MAVSDK with SITL first. For instance, run this (it will run SITL), and run one of the MAVSDK python examples.

I want to make a ground station with the same function as QGC based on mavsdk-python

Yes that should be feasible, MAVSDK is there for that :blush: :+1:

larryteal commented 1 year ago

MAVSDK automatically sends heartbeats not working for me, Other than that, I wanted to control the relay, but I couldn't find the API,I found MavlinkPassthrough in the documentation and it seems that only it meets my needs

JonasVautherin commented 1 year ago

If MAVSDK cannot send heartbeats to your drone, MAVSDK won't be able to send anything at all. Be it with mavlink-passthrough or not.

You need to understand why in your network topology messages can go from the drone to the MAVSDK (they do, right?) but not from MAVSDK to the drone.