Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MAVProxy in testing of a custom MAVLink message #3390

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions en/middleware/mavlink.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ There are several approaches you can use to view MAVLink traffic:
It is much easier to generate a wireshark plugin and inspect traffic in Wireshark, than to rebuild QGroundControl with your dialect and use MAVLink Inspector.
:::

- Use [MAVProxy](https://ardupilot.org/mavproxy/) with an updated [Pymavlink](https://mavlink.io/en/mavgen_python/) that contains your custom messages.
This is easy because updating pymavlink is just a matter of copying in your headers and rebuilding the package.
It easier than building QGroundControl and similar effort to using WireShark (once tested with MAVProxy, you can still proceed to building QGroundControl if required).

Instructions for the update process and how to view your custom message are given below in [Updating MAVProxy](../middleware/mavlink.md#updating-mavproxy)

- [Log uORB topics](../dev_log/logging.md) associate with your MAVLink message.
- View received messages in the QGroundControl [MAVLink Inspector](https://docs.qgroundcontrol.com/master/en/qgc-user-guide/analyze_view/mavlink_inspector.html).
You will need to rebuild QGroundControl with the custom message definitions, [as described below](#updating-qgroundcontrol)
Expand Down Expand Up @@ -519,3 +525,55 @@ However if you use your own dialect then it should include ArduPilotMega.xml (or
### Updating MAVSDK

See the MAVSDK docs for information about how to work with [MAVLink headers and dialects](https://mavsdk.mavlink.io/main/en/cpp/guide/build.html).

### Updating MAVProxy

[MAVProxy](https://ardupilot.org/mavproxy/) is UAV ground station software package for MAVLink based systems written in Python.
While not optimized for PX4 or widely promoted in the PX4 community, we mention it here because it is one of the easiest ground stations to update with custom messages, and is therefore one of the easiest ways to test that your custom messages are being sent.

[MAVProxy](https://ardupilot.org/mavproxy/) depends on [Pymavlink](https://mavlink.io/en/mavgen_python/).
The approach described below is to install MAVProxy, remove the default-installed Pymavlink, and then rebuild Pymavlink with the new messages.

The steps are:

1. Install MAVproxy using the command:

```sh
python -m pip install mavproxy
```

1. Remove the Pymavlink package installed with MAVProxy:

```sh
python -m pip uninstall pymavlink
```

1. Clone the MAVLink repository (which also contains Pymavlink)

```sh
git clone https://github.com/mavlink/mavlink.git --recursive
cd mavlink
```

1. Copy your custom message XML into the [message_definitions/v1.0](https://github.com/mavlink/mavlink/tree/master/message_definitions/v1.0) folder
1. Generate the headers:

```sh
python3 -m pymavlink.tools.mavgen --lang=C --wire-protocol=2.0 --output=generated message_definitions/v1.0/your_dialect.xml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wasaybaig Are you sure you need this step?
This builds the C headers in mavlink/mavlink, not Python headers so I don't think this would be used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hamishwillee it works this way also but we can change the language to Python. But it is important to generate the headers with your new message or MAVProxy will not be able to understand the message.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But MAVProxy uses Python so this is a null operation - you haven't built anything that MAVProxy can use.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'll have to try it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. setup.py pulls any xml files in the parent definitions folder and builds them. Tested.

```

1. Install Pymavlink using

```sh
cd pymavlink
sudo python setup.py install
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% certain this will work. Normally Pymavlink package is built with the ArduPilot fork of mavlink/mavlink headers.
What makes me think it probably does work is:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hamishwillee yes I have tested it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running this with sudo is asking to mess up your Python dependencies. I don't think that's something we should have in the docs.

What are we trying to do here? And why can't we just use upstream pymavlink?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this does indeed screw up your installation - as I have just verified. I can get this to "work" (somewhat) but I can't undo it. Will have to delete my installation and start again :-(

What we are trying to do, ultimately, is have an easy way to test a custom message, since building QGC with a custom dialect is a bit of a pain.

The solution described here is to install mavproxy and then delete the pymavlink that it depends on. Then rebuild pymavlink from the mavlink repo clone with your new xml definitions added. This step is easy because you just copy the xml files in and run setup.py and it creates a new installation/.egg with the .py files for the definitions.
Mavproxy can then display the message if it is received.

  1. We definitely don't need the step above building the files from the definitions. the setup.py does that for you.
  2. This still doesn't work though due to the error MAV_TYPE_VTOL_DUOROTOR not defined. That is correct - it has been removed from Mavlink, but it seems that mavproxy expects it in https://github.com/ArduPilot/MAVProxy/blob/master/MAVProxy/modules/mavproxy_link.py#L744
    • @wasaybaig How did you work your way around that? It's a bug in mavproxy.
  3. I presume we can completely avoid all use of sudo if we install mavproxy and run setup from inside a virtual env?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, let's see if we can get MAVProxy to update ArduPilot/MAVProxy#1470

```

1. Connect your autopilot to MAVProxy by following the [MAVProxy docs](https://ardupilot.org/mavproxy/index.html).

1. In the MAVProxy shell, you can use the `watch` command to display messages.
For example, to display/test that a custom message is being sent you could use the command below:

```sh
watch custom_message_name
```
Loading