PX4 development using Mathworks tools

Hello!
I saw on the Mathworks website that PX4 development is supported by Embedded Coder (using Simulink and Stateflow). Are there up to date models available with the same functionality as the latest hand coded builds? If so, who is doing the development, and where can I find them? Is there a separate forum for this work?
Thanks in advance.
Gordon

Hello. The developers are Mathworks employees, mainly Daren Lee I think. The repo for the Simulink version of the firmware is located at https://github.com/darenlee/PixhawkPSP_Firmware. I believe it is only buildable on Windows (have not tested on Linux, but formally only “supported” on Windows).

I have had some issues with this support package, which I can explain more thoroughly if you like, but in theory it should be very easy to use. You get blocks which interface attitude estimator, GPS, radio, buzzer, led, pwm outputs and generic topics.

The limitations which I don’t have time to go into right now, have made me start making my own Simulink interface to PX4, and use the “generic” code generator in Simulink. This works in Linux and Windows, and doesn’t provide these easy-to-use blocks, but regular input and output ports.

Reply if you would like to hear more about these limitations.

Many thanks for your reply.

Using Windows is not a problem for me!

When you have the time please post some more info regarding limitations. In the meantime I will attempt to have a look at Daren Lee’s repo.

Hi Glennbi,

Sounds promissing. Will this interface work on macOS as well ?

Best regards,
Michael

Hi Michael,

This interface will work on all OSes, because the application I’m writing basically only interfaces the generated Simulink functions. The generated Simulink functions are typically these:

ModelName.initialize(); // Called once before any of the other functions are called
ModelName.step()        // Called at solver frequency        
ModelNAme.terminate();  // Called at the end of the application

In addition, structs are generated as inputs and outputs, corresponding the inports and outports in the Simulink model.

Unfortunately, I’m under a NDA with regards to sharing the code, but as I’m developing it, I can provide the basic idea. I may also publish info about any of the pitfalls I encounter.

Hi Gordon,

The limitations I was talking about stem mainly from the source not being up to date with the latest PX4 firmware. There are also some issues with the generation tool in Simulink, but it is possible to work around them.

The main issue is with the message building system. In the original PX4 firmware, it is possible to generate multiple topics from a single message. This does not happen automatically from the Simulink firmware, and you have to create a separate .msg-file for every topic.

Another one is that the Makefile is quite different from what is found in the original firmware, so it is difficult to get community support with it.

I have also had some troubles with the git submodules after branching out.

The Simulink generation tool issue arises in certain configurations of the code optimization objectives, and generates a GUI-error. This is reported to the developers. The workaround is to only build code, and not build, while you are performing code checks for optimization, and turn off the optimization checks when you want to build.

I have also encountered an error in which a simple program (blinking the LED) was failing after around 3 minutes, but haven’t been able to reproduce it afterwards, so it might be that I’ve done something wrong, but it has made me a little cautious.

If none of these things concern you, and you would just like to create your own autopilot using the existing attitude estimators and blocks, and not create your own uORB topics, then this support package is very nice.

Hi Glenn
Thanks again. When I can find some free time I will investigate further.

Is there simulink model available for PX4 multicopter controller ?
Thanks