trijinx
trijinx

Reputation: 1

use mavlink without qgroundcontrol

I'm trying to conect my PX4Flow sensor to a raspberry pi. It seems that nearly everybody is using qgroundcontrol to access and control it. But as I'd like to integrate it into some bigger program, I'd like to control it with some self-written simple python code, if possible. My aim is to:

I don't need the ultra sonic sensor.

I found out that I can use MAVlink for the communication between the px4flow sensor and the raspberry pi. I cloned the git repository and followed the steps on https://github.com/mavlink/mavlink until the generation of header file (python -m mavgenerate). With that, I can generate a new python file. I don't know if this is correct, and I don't know what to do with that python file. No more file (header files) are copied or generated. How do I go on? How do I use the library? How do I even test the connection?

Upvotes: 0

Views: 579

Answers (2)

numan
numan

Reputation: 93

the link you posted is for mavlink repo, which defines mavlink messages and used to generate libraries for desired language. For more info you can refer to mavlink docs it is generally used when you add new messages and generate new libs. other wise you would use an existing library. Qgrounds mavlink libs sits here

As you can see in the first link, there are lots of mavlink libraries. Some of them are generated with mavgen and some of them has other changes. For example mavsdk is a high level library that handles low level functionality itself and exposes high level functions. you can check out examples to see how to use it. Both python and cpp libs are avaliable

If you want low level control (ie want to set individual fields of messages) or mavsdk does not suit your needs, you can use generated mavlink messages. an example for python is here

In my experience, best way to use low level libs is to search existing libraries (for example qground or px4) or examples to see how a message is used. You also have to keep in mind your particalor autopilot implementation as there might be slight implementation detail differences. So it is a good idea to check the code of your ap. Also mavlink message definitions and micro service definitions are good places to start and refer to.

if you are already has ros or ros2 in your system mavros might also be a good alternetive. once you start the node, you will see mavlink messages as seperate topics, and you can send mavlink messages using relevant services

Finally mavlink is an active community with their own forums and discord. you can ask this question or search for it in mavlink or px4 forums or dronecode discord

Upvotes: 0

Keven Sun
Keven Sun

Reputation: 41

If I understand you correctly, you want to make a module to communicate with PX4Flow.

I have some experience in building a ground control station with ardupilot. I think the procedure is roughly the same:

  1. Generate the proper mavlink library, what you have done by using mavgenerate. Read some guidance of mavlink communication procedure.
  2. Read the source code in PX4Flow communication module https://github.com/PX4/Flow/blob/master/src/modules/flow/communication.c, which shows what kind of messages have been sent to client side (e.g. your communication module)
  3. Start write the module code to communicate with PX4Flow. You may need to start with HEARTBEAT msg first to establish connections between your module and PX4Flow. Note that you can always receive HEARTBEAT messages from PX4Flow. You can start with decoding these ones.
  4. Implement your other functionalities.

You can read sources code of QGourndControl during step 3 and step 4. Make sure to find the right module in its repo.

My communication module is built using JavaScript https://github.com/kvenux/nodegcs, if it helps.

Upvotes: 0

Related Questions