Upload custom flight controller on Pixhawk 4 via simulink, and flight tests

Hello.

I developed my flight controller in simulink, and i tested it In SIL, HITL following the matlab examples Deploy PX4 on Host Computer with PX4 Host Target (PX4 Software-in-the-loop or SITL) - MATLAB & Simulink - MathWorks Italia https://it.mathworks.com/help/supportpkg/px4/setup-and-configuration_mw_06fa168c-661f-4e54-b3b0-197c970f0ac9.htm . Now i want try to perform the flight test with my fligth controller. Now, there isn’t any examples about perform real fligth tests. So, I uploaded the firmware following the HIL procedure:

Build the firmware and upload

  • Default startup script
  • Design flight controller in simulink
  • Boardo Pixhawk 4, whit px4_fmu-v5_default
  • Check that i’m not in HIL mode

Then after these passages i Build Start and deploy my fligth controller into Pixhawk 4.

Now if i try to connect my drone with Qground cotnrol station, all the sensors, frame, GPS, ecc… are ok. So I armed the drone and command the take off, but the motors didn’t start to spinn. I also tried with the example in matlab “px4demo_HardwareInLoopWithSimulinkPlantStart”, but even this dind’t work. I alredy cheked that all the wires are connected.

I also tried to upload the px4demo_PWM and it works, ( basiccally two engine spinn and other two doesn’t move).
But now, if instead to use a constat value 1 (bool) to arm the PWM block, i use the uORB message actuator armed, it doesn’t work.
Basically

  • I have all the stuffs in Qground control that are ok
  • I arm the drone, then the engine start to spinn for 1 second
  • After this second they stop, but the drone is still armed

I saw that the actuator_armed message is true, so the drone is armed.

Does anyone have an experience about upload firmware via Simulink and test it?
Thanks in adavce.

Hi there! I am also having the same issue (also deploying from Simulink and using the PWM block). Did you find a solution for it?

1 Like

Hi, unfortunally no. Did you have some probem with software in the loop also?

Ah that’s unfortunate to hear, I will keep you posted if I find a solution.

As far as SITL, I was able to compile and run it, but my simulator was excruciatingly slow (I am using the built in Mechanics Explorer in MATLAB with Simscape for the plant model). I have pretty complex plant dynamics so I wasn’t surprised…

Thanks so much.
One suggestion I can give you is to use a switch on the RC transmitter to arm the block, putting an if, and setting a threshold. In this way the PWM block is armed and you can use it, but in this case I was unable to send commands from QGround control statio, and I drove it manually. If you are interested I can explain better.

What do you use to transmit data in SITL? because I use the block present in the example, but the values ​​received from the dynamics model do not correspond to those sent by the controller, it is as if there is a data loss, and therefore nothing works. In my case normal simulation works, software in the loop doesn’t work due to the above problem, and hardware in the loop simualtion works.

I do currently have a switch on the RC transmitter arming the block and basically mapping to a boolean 0/1. I have currently abandoned SITL altogether and am just trying to deploy on hardware to test on a testing rig. What I have been noticing is that the motors will arm and even spin for about a second, and then it appears that they are disarming. I have verified that this is from some interference with PX4 as I have done bench testing with the I/O mode in Simulink and all the motors spun as expected. Here is a graph from an example flight:


In the Radio inputs, the flight mode is going from takeoff to landing, but you can see in the outputs graph that the motors only arm for 0.5 - 1 sec. I have checked all the failsafe and auto disarming and none of them seem to be the cause.

I also maybe thought the arming signal needed to be a pulse train so I tried that, but that didn’t seem to be the case either.

I get it. even my engines after arming, after a second they take on the value of disarmament in my case 900us. I also tried different solutions going to change the baud rate of communication but nothing.

For anyone else who comes along this post with the same problem implementing a controller from Simulink into PX4, I was able to solve my problem by disabling the QGC arm and kill features (remove any switches for arming in the QGC flight modes panel and map the kill feature to an unused channel. As a result of removing the QGC arm data, the logger won’t start by default. If you want to still collect log data, you need to change SDLOG_MODE to something suitable for your application), and integrating the arm and kill features/switches in my built out controller.

1 Like