MAVLink from companion computer to ground control station

1,241 views
Skip to first unread message

Munier Louis

unread,
Jan 9, 2019, 11:20:51 AM1/9/19
to MAVLink
Hello everyone,

I am sorry if the question is well answered somewhere, I did a lot of research and did not find an answer to it. I would like to know if it is possible to send custom messages from a companion computer to a ground control station through MAVLink. Actually the goal is to send a MAVLink message with a custom payload from a Raspberry Pi, connected in UART to a Pixhawk, to an UART port on my personnal computer.

I tried with the c_uart_interface_example (https://github.com/mavlink/c_uart_interface_example) and I easily recover data from the Pixhawk. But when I would like to send data over my radio link (two antenna wired in USB on my PC and on the Raspberry pi) I was not able to set it up properly. I am not sure but I think it is because with this setup I do not have any SysID and CompID on both the antenna (wire in UART).

The piece of code tried to send a message is the following one:

mavlink_message_t hello_world;
   mavlink_msg_param_request_read_pack(2, 1, &hello_world, 1, 1, "SYSID_SW_TYPE", -1);
   serial_port_radio.write_message(hello_world);

If someone have some idea to do it I will be delighted.


Louis

Hamish Willee

unread,
Jan 10, 2019, 4:26:08 PM1/10/19
to MAVLink
Hi Louis,

This is slightly confused because you talk about RaPi -> Pixhawk -> PC and then you talk about PC -> RaPi via antenna/USB and so I don't know what configuration you are trying to achieve.
Also, what flight stack are you running on the Pixhawk?

What you want to do is probably possible, but I have not personally done it. The main thing to consider (assuming the first case) is routing between interfaces. So if you send a message from RaPi to pixhawk you need to make sure that:
1. The message is then forwarded to whatever interface you are using to connect Pixhawk to PC. ON some flight stacks this might be automatic while on others you might need to explicitly enable forwarding.
2. All systems have a system id and component id. Even if you are sending messages over a wire, the protocol expects you to specify a sender.
3. The custom message is understood by the routing system - Pixhawk. In theory a system should route a message it does not understand but in practice it may not. 
4. The custom message is understood by the receiving system - QGC. QGC needs to know what to do with the message, so it must use a build that understands your dialect.

Regards
Hamish

Munier Louis

unread,
Jan 10, 2019, 7:13:56 PM1/10/19
to MAVLink
Hi Hamish,

Thank you for your answer and sorry for the confusion. My actual setup is Pixhawk - (by wiring, the same as in the tutorial http://ardupilot.org/dev/docs/raspberry-pi-via-mavlink.html) -> RaPi - (by antennas) -> PC and the communication between the RaPi and the PC is made by two antennas wiring in USB. I flashed the Pixhawk with the release 1.8.1 of PX4.
Currently I am able to recover, on the RaPi, some informations from the PX4 by UART communication with the c_uart_interface_example (https://github.com/mavlink/c_uart_interface_example). The goal is to interact on the data, on the RaPi, before sending them into a custom mavlink message to the PC.

Best regards,
Louis

Hamish Willee

unread,
Jan 10, 2019, 8:22:56 PM1/10/19
to MAVLink
Hi Louis,

Great. This should work because you are in control of most of the code - ie it is code on RaPi that you write which does routing.

So my understanding is that you can get information from Pixhawk. However when you try send a message to QGC you don't see it - is that correct? I assume the message you're sending is one of the ones in common? Something like STATUSTEXT?

YOu might want to start with something simpler than QGC as the receiver just to verify the link. e.g. dronekit or another instance of c_uart_interface_example. It is possible that QGC won't connect to your companion computer because it does not know what it is. In either case your RaPi instance will need a system and component Id. It may need to advertise other information to QGC to connect too. 

I suggest you repost this question on the PX4 discussion boards to get a broader audience: http://discuss.px4.io/c/mavlink
You will need to include symptoms you are seeing and the architecture info we discussed above:

Pixhawk running PX4 1.8.1 ---(cable)--->RaPi ---(telemetry_radio)---->PC running QGC.
RaPi listens for messages, modifies them, then sends to PC.

Munier Louis

unread,
Jan 10, 2019, 8:36:03 PM1/10/19
to mav...@googlegroups.com
This is exactly what I want to do. I would like to send STATUSTEXT and I think I am not so fare from the solution because I am able to open an UART communication from the RaPi to the USB port where the antenna is connected and did the same thing on the PC. 

As you say, I would like to firstly communicate with another instance of c_uart_interface_example. And I did it but receive only unreadable message on my PC with unanderstanding SysID. I do not know how to set correctly the SysID and the CompID, maybe is it just the mistake ?

--
Sie erhalten diese Nachricht, weil Sie in Google Groups E-Mails von der Gruppe "MAVLink" abonniert haben.
Wenn Sie sich von dieser Gruppe abmelden und keine E-Mails mehr von dieser Gruppe erhalten möchten, senden Sie eine E-Mail an mavlink+u...@googlegroups.com.
Weitere Optionen finden Sie unter https://groups.google.com/d/optout.

Hamish Willee

unread,
Jan 10, 2019, 9:22:15 PM1/10/19
to mav...@googlegroups.com
IMpossible to say, but the sys id of your companion can be any number between 1 and 255, provided it is not used by the autopilot or QGC. You could just use 200 and be fairly safe. The component id should be perhaps MAV_COMP_ID_ALL.

Most likely your reading code is a bit broken. Have you put your modified version of https://github.com/mavlink/c_uart_interface_example anywhere? I assume you have got it modified here https://github.com/mavlink/c_uart_interface_example/blob/master/mavlink_control.cpp#L246 to read and print STATUSTEXT?

Sie erhalten diese Nachricht, weil Sie in Google Groups ein Thema der Gruppe "MAVLink" abonniert haben.
Wenn Sie sich von diesem Thema abmelden möchten, rufen Sie https://groups.google.com/d/topic/mavlink/gFGjFex8u0I/unsubscribe auf.
Wenn Sie sich von dieser Gruppe und allen Themen dieser Gruppe abmelden möchten, senden Sie eine E-Mail an mavlink+u...@googlegroups.com.

Munier Louis

unread,
Jan 10, 2019, 10:15:02 PM1/10/19
to MAVLink
Thanks a lot to helping me !I did not set any sys id on my companion so I do not really know what it is.

I just created the GitHub to save the work done so fare for this project. I modify the mavlink_control.cpp to make two of it in these first tests. One mavlink_control_send.cpp where there is all the information to connect to both the Pixhawk and the USB port to he antenna and an other one "mavlink_control_receive.cpp" where I comment all the unneeded rows and add the following piece of code to show what I receive on the USB port:

// First try to read messages from the Raspberry Pi
mavlink_message_t
hello_world;
while(true){
   if(serial_port_radio.read_message(hello_world))
       printf("Received message with ID %d, sequence: %d from component %d of system %d", hello_world.msgid, hello_world.seq, hello_world.compid, hello_world.sysid);
}


Hamish Willee

unread,
Jan 10, 2019, 11:32:08 PM1/10/19
to mav...@googlegroups.com
The code doesn't look right for sending messages but I don't have time to work out why. 

Suggestions
- Then you might want to look at https://github.com/mavlink/mavlink/blob/master/examples/linux/mavlink_udp.c#L142 which shows how to pack and send a number of messages. You would pack a STATUSTEXT instead of these if you want to send hello text. 
- On the other side you can unpack messages similar to https://github.com/mavlink/c_uart_interface_example/blob/master/mavlink_control.cpp#L246 or https://github.com/mavlink/mavlink/blob/master/examples/linux/mavlink_udp.c#L166 - the first example shows how to get the actual message payload and unpack its "bits" while the second just shows how to get the message top layer, without unpacking the payload.


Munier Louis

unread,
Jan 11, 2019, 1:39:36 PM1/11/19
to mav...@googlegroups.com
Thank you for all these suggestions, I will take a look on all of them and give a feedback when I have some news about it.

Best regards,
Louis

Garanti sans virus. www.avast.com

Garanti sans virus. www.avast.com
Reply all
Reply to author
Forward
0 new messages