PX4 Simulink

Hello guys,

I wonder if I can modify the firmware using Simulink. I know there is a px4-simulink library but I never used it.
My questions are:

  1. Have you ever use that library and what are its benefit compared to conventional code development in C++?
  2. Are there any materials to start developing new flight modes with simulink?

I would appreciate any suggestions.

What are you talking about? Are you talking about the PSP?

IN CASE YOU ARE NOT AWARE:

There is a PX4 support package for Simulink. This is what they claim it can do:

Capabilities and Features

Using Pixhawk support for Embedded Coder®, you can generate ANSI/ISO C from Simulink® models specifically tailored for the Pixhawk FMU (flight management unit) using the Pixhawk Toolchain. You can customize algorithms that leverage onboard sensor data and other calculations at runtime.
Support highlights include:

  • The ability to simulate and test different airframe models and control system designs in Simulink and deploy designs onto the PX4 automatically.
  • An example included in the support package, which demonstrates attitude controls for a quad/hex set up.
  • Integration of the Pixhawk CMAKE build system with Embedded Coder
  • A sensor/peripheral block library for inertial measurements, GPS, vehicle estimation, LED, speakers, PWM output, and ADC and serial Rx/Tx. This can be extended to support other sensors/peripherals.
  • The ability to view the value of signals and tune parameters in real time so you can interactively test the behavior of the generated code.
  • Capabilities to log and record flight data of sensors, actuators, or any part of your Simulink control model for test and analysis.
  • The ability to read and write uORB topics as well as enabling asynchronous tasking with uORB.

What version of Matlab/Simulink are you using? The latest support package requires Windows 10 or Linux(with arm-none-eabi-gcc, Python and CMake).

If we are still talking about the PSP, then no. I didn’t get to. At first, it wasn’t compatible with my Matlab. Then they released an update to fix that and now it’s not compatible with my OS (Windows 7). Mathwork’s page on this thing has a misleading line saying:

Platform and Release Support
This support package is available for 64-bit Microsoft® Windows® and Linux. This version of the support package is compatible with MATLAB R2017a and R2017b. It also works in MATLAB R2018a with limitations to External Mode functionality.

When my attempt at installing it failed and I asked around, I finally understood that when they say "64-bit Microsoft Windows, they mean 64-bit Microsoft Windows 10! They could have mentioned that fact somewhere BEFORE you install things. The installation kinda crashed and burned for me but it gave me access to some helpful documentation which I couldn’t find elsewhere. One of them is Pixhawk_Pilot_Support_Package v 3.04.pdf (2.0 MB)
detailing the installation process and some quick examples. It’s a very useful document you can take a look at if this is what you were seeking.

I am preparing this windows 10 machine and an ubuntu machine right now to see what this package is like.

As for your question about the advantages over C++, well, what if the researcher doesn’t know C++? Consider someone who builds flight sims in Simulink. wouldn’t it be majorly advantageous to not have to get out of that environment and get to directly target a given hardware and ?

  1. Are there any materials to start developing new flight modes with simulink?

I don’t think so but it’s possible I’m wrong.

Hello, yes I was talking about the PSP. I’d like to know how to use it to create my flight mode based, already developed in Simulink. I’m working with Windows 10, Matlab/Simulink 2016b. I wonder if someone has used PSP and could provide support/suggestions on how to exploit PSP to compile/build and deploy user-made firmware.

Check the PDF manual I attached to the previous post. It will give you some idea.

Hello @Safat.

I wonder if you have tested the PSP. We were able to compile and deploy the default attitude controller. Unfortunately, the controller seems not working as it sets all the pwm out signal to 2000us. Did you make some test on this package?

I did
Flying quadrotor with pitch , roll and yaw control loops written in simulink and then compiled to pixhawk with PSP
It works , much easier than writing c code , but still requires some learning curve
There are several technical documentations of mathworks to help beginners.

I did but it don’t work correctly
Can u please, share your code ?

@R.G Can you please share your simulink model of the control loops? I have one but it is still based on the release 1.9 structure before the velocity control changed to commanding acceleration setpoints.