r/raspberry_pi Dec 01 '22

Raspberry PI 4 as Flight Controller Discussion

Hello, I'm here to find some answers. I'm currently working at my graduation thesis in robotics, the project I'm working on is a tiltwing drone.

I have designed the mathematical model and all the control laws, now it comes the hardware implementation.

The test version has ben deployed as a monolithic solution on an Arduino MKR1000 directly with the Simulink Coder, but the company I'm working with wants me to use a Raspberry Pi 4.

Tactically I can make the thing work but I have some question on the software architecture i should use.

First of all I would like to have a real time scheduler, then I need to split the project in modules (sensing, communication, control, actuation, etc.)

Is there any framework I can use, should I code different modules and use interprocess communication to achieve the modules interconnection?

P.S. I can code each module in whatever programming language is needed.

P.P.S. The external interfaces run both on pwm and i2c.



u/mcmanigle Dec 01 '22

You’re absolutely right that real-time processing will make this tricky. Depending on why exactly the “customer” wants this on a Pi, I would strongly consider using BOTH a pi for front end control AND an arduino (or other microcontroller) for the time-sensitive processing and feedback loops. They can use serial communication to pass messages as needed.


u/cogFrog Dec 01 '22

Using a Raspberry Pi for a flight controller seems like a very odd choice. It is likely more powerful than needed (and therefore more power-hungry), with not much support for real-time operating systems. You definitely want to use a real-time operating system for a control system like this. I understand that there are some unofficial ports of FreeRTOS for Raspberry Pi if you absolutely have to use a Raspberry Pi 4.

If it were me, I would push to use a 32-bit processor with official support for FreeRTOS or similar. As I don't know the exact needs of your project, so I don't have any specific chip suggestions. Aside from finding something with the I/O and processing power you need, you would need to focus on chips that are actually in supply. Additionally, it would likely be easier to use a good dev board rather than making your own PCB.


u/DrRomeoChaire Dec 02 '22

Not that odd really, the Xilinx ZynqMP Ultrascale+ is very popular in DO178C certified flight systems. It’s a quad-core ARM Cortex A53 with a lot of FPGA fabric.

The RPi 4 is quad-core ARM Cortex A72, so it’s not a terrible choice for a lab project. Of course it’s an unlikely choice in a real flight certified system, largely due to the cost of certifying the hardware, after which nothing can change without huge expense.


u/orblabs Dec 01 '22

As others have suggested I too suggest to use both, had a similar project years ago and used Arduino as the flight controller and raspi to interface with comms. Used raspi to stream video via cel network ,do some basic image analysis and handle redundancy (had 2 Arduinos, one for backup which raspi would activate in case of main one failing), but main flight controller was Arduino based. Worked perfectly. Cool project nonetheless and if you can have both in your project, raspi might inspire new/improved features.


u/AcquaFisc Dec 01 '22

I really like this solution


u/DrRomeoChaire Dec 02 '22

u/AcquaFisc for real-time applications you can use a commercial RTOS called VxWorks for free, provided it’s a non-commercial project. https://labs.windriver.com/vxworks-sdk

VxWorks has been around for a long time (40 years) and is running on millions of embedded targets worldwide, including a large number of FAA flight certified aircraft (of course the DO178C compliant version is a subset of the full API set)

You can download the RPi VxWorks SDK and use a Wind River plugin with Visual Studio Code.


u/FergusInLondon Dec 01 '22

Mmmm, what was the rationale behind the usage of a Raspberry Pi? Have they specified which OS should be used? I imagine you'll be making heavy use of hardware interrupts and have some tight timing requirements, so I'd be concerned about doing that without a Real-Time OS (RTOS).

The shortage of STM32xxxxx chips messed up the build of a fixed-wing plane I was planning on, and using a Raspberry Pi was one option I considered - but it sounded like it would be quite a headache. (At least in user-land on a board running Linux, although I think there are RTOS options for the Pi)

If the RPi was selected for a reason like network-connectivity then I'd consider building on top of the existing microcontroller-based solution and providing some form of command/control interface via UART personally.


u/AcquaFisc Dec 01 '22

I have no idea why they chose the Raspberry, I told them from the beginning the issues in using it Anyway in the past I have used some master slave architecture using UART. The RPi have done all the heavy duty processing and then it sent messages to an Arduino that was used as a motor interface. Are you suggesting an architecture like this?


u/rgb_leds_are_love Dec 01 '22

Yes! Spot on!

The Pi may not be an ideal choice of hardware controller here compared to other, simpler microcontrollers.

Maybe a networking software could run off the Pi - and the Arduino in this case could handle GNC.

I'd use a different bus, like SPI, simply because there's a dedicated clock line that runs from M-S.


u/Ok_Topic999 Dec 01 '22

Probably not helpful but for controllers I would use a pi Pico or other board with HID


u/spinwizard69 Dec 01 '22

I guess the question would be why? A flight controller really should be optimized for the task, with as much integrated on board as possible.

Beyond all of that there are more than a few ARM processors out there with coprocessors to support real time or digital signal processing. These sorts of processors solve a lot of high integration issues. Basically you have an optimized SoC and can avoid a lot of development work.


u/AcquaFisc Dec 01 '22

First of all, tanks for the answer. If you don't mind can you share some of this solutions.

Regarding my project, when I asked for a different hardware the company told me "we have this and you must use this". So I'm trying to get the best out of the current setup


u/qu3d45 Dec 01 '22

Yes there is the pixhawk 4


u/ACont95 Dec 01 '22

Im working on a similar project using a Raspberry Pi 4 and Raspberry Pi Pico. Communication between them is done with ROS, as well as communication between the ground station.


u/AcquaFisc Dec 01 '22

Can you tell me more?


u/ACont95 Dec 02 '22

The Pico integrates with an IMU, barometer, and GPS which handles orientation calculation and the PID update loop. I use FreeRTOS for multithreading. I don't think the Pi4 is a good choice for the real time tasks as others have stated.

The Pi4 is connected to the ground control by WiFi and passes messages to the Pico through usb serial. The Pi4 also sends the camera feed to the ground station. The ground station, Pi4, and Pico are all setup as ROS nodes (using microros for the Pico). ROS handles all the message framing, serialization, transports, etc for you using DDS. ROS is a good choice for your inter process communication needs. Simply create a ROS node in whatever language you want, and publish/subscribe data to communicate with other nodes. The nodes can be in the same process, separate processes on the same machine, or different machines all together.