Using REST to Send Mavlink Messages on BlueROV2

Hello!

I am working with a BlueROV2, and I am running python programs on the Raspberry Pi on the BlueROV2 to make the robot move.

I have recently upgraded to BlueOS and I am struggling to get the passing of Mavlink Messages to work. The old system used under the old OS involved creating a master in the python programs, and then calling that master to send the appropriate Mavlink messages. This methodology is not working under BlueOS, as the master fails to send any Mavlink messages - the program gets stuck when no heartbeat is detected, and if the check for heartbeat is removed, the code runs, but does not do what it needs to do since Mavlink messages are not being sent.

I have turned to using REST to send Mavlink messages to the Pixhawk in order to send data to and receive data from the Pixhawk. I have followed the format detailed at the following GitHub repository written by patrickelectric: GitHub - patrickelectric/mavlink2rest: mavlink2rest creates a REST server that provides mavlink information from a mavlink source . This format is working well for Mavlink messages which involve requesting that the Pixhawk send data to the Pi, such as SCALED_IMU, as using GET in my python programs returns the desired data consistently. However, for Mavlink messages which involve sending data from the Pi to the Pixhawk, such as RC_CHANNELS_OVERRIDE and MANUAL_CONTROL, it is not working. I have used POST in the way that the GitHub repository does in order to send these Mavlink messages, but as seen in the picture below, all that happens when I make a POST request in the BlueOS terminal is that the terminal prints “Ok”. Nothing happens on the BlueROV, even though the Mavlink message was supposed to turn the motors on.

The following is a description of how I tried to use POST to send data from the Pi to the Pixhawk via Mavlink messages:

Following the format in patrickelectric’s GitHub repository, I used GET to request a template for the appropriate format for sending the Mavlink message MANUAL_CONTROL over REST.

I then made a POST request using this format, but the terminal just printed “Ok” and the robot did nothing:

I made another POST request following this format, but changed the system_id and component_id to 1, since these were the values that I used when successfully using GET to send Mavlink messages such as SCALED_IMU in my python programs, but once again the terminal just printed “Ok” and the robot did nothing.

I followed this same pattern again, but for the Mavlink message RC_CHANNELS_OVERRIDE, and the results were identical.

My question is (1) What am I doing wrong to cause the POST requests not to work, and (2) Is there an easier way of sending Mavlink messages to the Pixhawk under BlueOS which would avoid this issue entirely? Any help would be greatly appreciated. If there is some key information missing from what I have provided here, let me know and I can share it.

Hi @erikjagnandan, welcome to the forum :slight_smile:

I don’t have much experience with sending messages via MAVLink2REST, but our DVL extension sends positioning data to the autopilot via POST requests, so perhaps that is a useful reference.

You should be able to use Pymavlink instead of MAVLink2REST, but you may need to set up an additional MAVLink Endpoint to connect to (requires Pirate Mode).

I’d recommend copying the “Pymavlink” endpoint example but with the loopback IP (127.0.0.1) (since you’re running your code on the onboard raspberry pi), in which case you should be able to connect with

from pymavlink import mavutil

master = mavutil.mavlink_connection('udpin:0.0.0.0:14770')
master.wait_heartbeat()
print('connection success!')

Hello Eliot,

Thank you very much for your help, and sorry for the late reply. I implemented the additional MAVLink Endpoint, and it worked - I can now power the motors on using the master connection and MAVLink message RC_CHANNELS_OVERRIDE. Thank you!!

Unfortunately, I am still having one related issue, which is that the MAVLink messages responsible for returning GPS data from the Pixhawk, such as GPS_RAW_INT and GLOBAL_POSITION_INT, do not appear to be working, either using the REST method or using the master associated with the new MAVLink endpoint. When using the REST method, the attempt to use GET immediately results in an error, and when using the master, the blocking call to send the message and return the associated data gets stuck and never returns, stalling the entire Python program which I am trying to run on the onboard Raspberry Pi. I have confirmed the GPS module is properly installed, and that this behavior still occurs when the ROV is outside and should be able to receive GPS communications.

Further investigation has suggested that GPS_RAW_INT and GLOBAL_POSITION_INT are not supported under Blue OS, as these messages do not show up when I enter 192.168.7.5:6040 into my browser (192.168.7.5 is the IP address of the onboard Pi) to get the page which lists the available MAVLink channels. As seen in the image below, this page does not include GPS_RAW_INT and GLOBAL_POSITION_INT, suggesting that these messages are not supported by Blue OS:

My questions are (1) Are GPS_RAW_INT and GLOBAL_POSITION_INT supported by Blue OS, and (2) Regardless of the answer to question 1, what can I do as a workaround to retrieve GPS data from the Pixhawk?

That’s ok - the forum is still here, and it’s not a problem if a support thread is inactive for a while, it just gives us more time for the rest of our work :slight_smile:

Great to hear! :smiley:

That’s definitely not the case - I receive both messages on a test system with a Pixhawk that doesn’t even have a GPS connected, and our MAVLink2Rest versions are the same:

Accordingly, my main ideas are:

  • There’s a difference in our ArduSub versions
  • There’s a difference in our parameters
  • There’s some issue with the way BlueOS’s MAVLink connections are set up, that mean the expected messages are not being sent to your IP
    • I’m not sure how that could be the case though, given the MAVLink2REST Endpoint is configured to loopback (127.0.0.1), which should be IP independent

Hi,

Check the parameter SR0_POSITION, that is responsible for setting the stream rate in hz for the positioning related messages.

1 Like