Choosing the companion computer configuration
In weighing out my options as to whether to use either an Arduino or Raspberry Pi to talk to the Pixhawk, I had to implement both and see if there were any limitations on either platform. This meant I had to discover if I would be able to have the Arduino talk directly to the APM, and also familiarize myself with UV Radioroom on the Raspberry Pi.
Pixhawk <=> Raspberry Pi <and/or + Arduino>
The entire reason I wanted to use the Ardupilot/Pixhawk solution + ground control software was because it would allow me to update way-points using low overhead packets through sat modem in a fully supported and easy to implement solution. On first glance, its offerings showed I would be able to update navigation coordinates and access all the information from the autopilot sensors ig. GPS, Battery voltage, trip status etc. all without having to fuss with writing my own code, I just install and run the programs 🙂
My first step was to install UV Radioroom on the Rpi, which was pretty straightforward and only took a few hours. After wiring the Rpi serial ports to the Pixhawk, editing the radioroom.conf file, and rebooting everything, the Radioroom service connected and that was that. I didn’t have a Rockblock modem installed yet but everything seemed functional so I felt pretty comfortable with the solution till then. The next step in the process called for installing an instance of their AWS stack, but I didn’t get that far (although I did sign up for the free AWS offering) because once I began reading more about the AWS solution (and how it cannot be installed on ones own linux server) I felt that this solution was going to hit a roadblock if there were problems in the future.
Thinking about it further, I wondered about a possible issue for the UV Radioroom service to run simultaneously with pyRockblock (a simple library to get Rpi working with the Rock7 sat modem). Would there be a serial port access conflict when both programs try to use the satellite modem via serial? I would need the pyRockblock library to send environment data from the Rpi, but because Radioroom sends telemetry data at preset intervals, this could eventually cause a conflict with another send instance being conducted simultaneously from another background routine (such as the Rpi sending sensor and motor status updates to a webpage).
The more I thought about this, the more I realized that using the Rpi UV Radioroom solution and the pyRockblock library without some way to broker the usage of the sat modem between them, introduced too many unknowns into the design. For an autonomous vessel, I felt this was undesirable.
Pixhawk <=> Arduino
With a little more experience using radioroom under my belt, I switched to trying to get the Pixhawk-to-Arduino solution working…Just like any seasoned programmer (and by that I mean, I cant remember how to write my own ‘for expression’ from memory), I hit the google and looked up examples for how to do what I wanted to do with the Arduino solution, which was receive Mavlink data and send and update new way-points in the event that I needed to do that for whatever reason. Tons of hits come up, GREAT! Yet as I continued clicking, I just saw question after question, with snippets of code which weren’t working correctly. Optimism turned to a little worry, and then worry turned into a little bit of fear. Would I be able to get this working? I mean I guess I can just use the Rpi solution and force it to work, but that’s not really ideal.
Then, like a ray of sunshine on a cloudy day, I stumbled upon a post about using a Mavlink Arduino library and getting sensor data from it. And by golly gee whiz, it was exactly what I was looking for (https://discuss.ardupilot.org/t/mavlink-and-arduino-step-by-step/25566)! Actually, it was the ONLY resource I found of the like, and quite literally the only thing which allowed me to get Arduino Mavlink commands working with a Pixhawk.
It didn’t exactly outline how to do other things like initiate a new mission and upload new way-point’s/flight plans but it provided enough guidance in order for me to figure out how to use the library (I still haven’t really found a decent code usage documentation for the Mavlink Arduino library). Thanks Juan Pedro!
After I got familiar with his code, I was able to customize it enough to request data-streams from the Pixhawk which were relevant for my purposes. # of locked GPS satellites, Lat and Lon coordinates, voltage and battery information, and even ground speed could be obtained by the Arduino and stored in variables to be handled in whatever way I wanted.
I then spent the next THREE days trying to get a new flight plan uploaded as there is no working example of doing so with the library anywhere. It was only until after reading the Mavlink Mission Protocol Operations page where I realized I needed to implement a protocol in order to successfully send way-points to the autopilot. Four hours later, I had a working proof of concept! I was so overjoyed, I told everyone I was talking with (including my kids), and spent a day off from doing any further programming.
So that’s where I am now – I have a working Arduino companion computer which can send and receive telemetry data from the Pixhawk and I also have the ability to update flight plans in the event of a needed course adjustment. Although this hands on implementation took much longer than the Rpi test, it was completely worth every minute. This exercise allowed me to excise the Rpi from the total electronics suite, which reduces power consumption, streamlines communications, and allows the entire system to work as one.
The next steps…
I’ve gotten far enough along my priorities list to where I can safely say the control system im working on is feasible for me to build, with the only other missing piece of the electronics puzzle being the integration of satellite communications. Once I receive the hardware, ill need to write a function for the Arduino to differentiate between flight plan instructions and those which instruct the companion computer to run system maintenance functions.
To read more about how to use the Arduino Mavlink Library:
or, to update a flight plan on an Ardupilot using an Arduino: