How to write autonomous code and run?

Hi. I have a project that i need to process(on rpi4b or jetson) the image from camera(arducam) than move autonomously. How will i do these? Where and how to write the codes and than run the code?

I would like to process data in the vehicle but if it’s not possible than i can do it on the top computer.

Is it even possible?

Hi @erkamtb -
It is definitely possible! I would recommend breaking down your application into the following threads to research / discuss with large-language model AI

  1. Realtime video processing for pose estimation / simultaneous location and mapping
  2. Pymavlink control of ardupilot vehicles

Apologies, I think other forum users may have found your enquiry a bit vague and open ended. Can you share more specifics about your goals? What type of vehicle are you planning to control, and what types of motion would you like it to achieve? What motivates this work?

Hi @erkamtb,

Just to clarify a little, the autopilot is commanded using the MAVLink protocol, so as long as your program can establish a MAVLink connection with it then you should be able to provide control inputs to your vehicle.

If you provide more information about your system and the types of control you’re trying to achieve, we should be able to provide more targeted and meaningful advice.

Hi. I can show you my robot via a yt video. https://www.youtube.com/watch?v=l6zrEO71uFw&ab_channel=TÜBİTAKFENLİSESİ
Our robot is like that. We are using matek h743 wing v3 (we can go with pixhawk 2.4.8) with rpi4b and a arducam that can move up and down with a servo. Our goal is making a vision processing and track a cable like thing.

I am also trying to write code to run on board the vehicle that gets sensor data from the Ardupilot/Autopilot/BlueNavigator (I’m not sure what to call the thing that actually has the pitch/roll/compass data from the NavigatorHat and also runs the controllers to steer the vehicle using the NavigatorHat)
We have a Raspberry Pi 4 with NavigatorHat connected to GPS and thrusters. We have code for satellite communications and for decisionmaking running on the vehicle (in the same Pi with the Navigator), and it is written in C++.
My preference is to add interface code to my existing codebase. Thus, I have tried the C/C++ examples from MavSDK, navigator-lib, mavlinktorest(i.e. using curl) and a few other libs that I have forgotten about. All of them have surprised me with some problems, probably of my own making. Thus, I need clear direction about which library is mature, not-out-of-date, simple, and straightforward for onboard use. My example scenario is blinking the LED, printing attitude and leak-detector at 1 Hz for 1 minute, pulsing the thrusters a few times, adjusting some control parameters (e.g. WP_RADIUS), and changing to waypoint driving mode.
I got Navigator-lib example to work for LED and attitude, but only for 10 seconds. MavSDK examples sometimes did not ‘connect’. using curl was clean, but complicated to build libcurl.
In general, as I have read the documentation I did not find a metophorically lighted path that seemed to be geared toward onboard , c/c++ code.

Hi, @MikeFair

I have had good luck with mavlink2rest. It is integral to how BlueOS and extensions work, so IMHO it is well supported. If you can work with the existing MAVLink messages, then this is what I would choose.

Using MAVLink as your interface to the autopilot (and hardware) does have some caveats:

  • The message rates are controlled via several mechanisms, which can be tricky. See How to Request Messages/Set Message Rates · MAVLink Developer Guide for an overview.
  • The message rates are limited, e.g., the IMU is sampled at 200Hz (typically), and the max message rate is something like 50Hz, and so you will miss most IMU measurements.
  • Some data has been processed by ArduSub, e.g., filtering, dropping bad readings, etc. Double check the code path from driver to message sender if in doubt.

I hope this helps.

/Clyde

P.S. – be aware of this mavlink2rest limitation: Send messages received from rest api and websocket to others websocket clients · Issue #93 · mavlink/mavlink2rest · GitHub

Thanks for the guidance. What is the best method for using mavlink2rest to command actuators, leds, parameter changes, and autopilot modes?

Hi @MikeFair -
Using LUA scripts with Mavlink is also possible, and an easy way to link things like controller button presses to output actions. By setting a Servo#_Function parameter to RCIN#, and then putting a lua script like the one shared below (explanatory forum post coming soon) in the correct scripts directory as detailed here and here, lots of things become possible!

Lua_buttoncontrol.lua (2.8 KB)

1 Like

If you can work with the existing MAVLink messages…

This is a big if. MAVLink is a pretty rich set of messages, but it is not a complete API. I am still learning it.

What is the best method for using mavlink2rest to command actuators, leds, parameter changes, and autopilot modes?

There are some great examples here (in Python): Pymavlink · GitBook

Background on the parameter protocol: Parameter Protocol · MAVLink Developer Guide

Background on the command protocol: Command Protocol · MAVLink Developer Guide

I think this covers everything except LEDs, I haven’t tried to control these.

/Clyde

1 Like

The OP didnt specify much about languages. But for me, I strongly desire c++ solutions.

I am getting the impression that it is not possible to send any commands of any kind to the autopilot using mavlink2rest.

Hi @MikeFair -
You can find examples of controlling the autopilot in this example! It changes the autopilot mode to loiter, executes commands to control outputs based on inputs, and then resumes the mission in Auto mode! These examples also detail other ways this could be done, including loading waypoints for missions.

how to go forward with pymavlink commands?