Clarification of PX4 utility

30 visualizaciones (últimos 30 días)
Mats
Mats el 17 de Nov. de 2025 a las 12:15
Editada: Mats el 20 de Nov. de 2025 a las 8:42
Hello there!
I am working a project where I am to implement a PX4 flight controller. I've read some of the documentation from both the fine folks at PX4 and MATLAB but I am not sure if my understanding is correct, so if any one can help me calrify some of my questions that I have, that would be much appriciated. (I've already asked this on the PX4 forum, but since this is also a MATLAB question I though I would ask it here as well PX4 forum Question).
If my questions aren't that clear I will try to explain exactly what I am trying to do:
My main objective as of now is to create a simulated version of a real drone that will use PX4 as the flight controller. Some of the things I want to simulate are stuff such as path following. My main question is how do I implement this as a part of MATLAB, since I want to have a simulation as 'theory', and then later run it on a PixHawk device to see if chip is capable of doing the calculations aswel. Hence the following questions:
  1. What is the difference between a PX4 Host Target and something like PixHawk 6x when simulating?
  2. In MATLAB / Simulink, I can chose some blocks like PX4 Actuator Write where it seems like I can write to some motors. Is the idea that I can build a model of my drone in Simulink, then use these PX4 blocks to write to something like a PixHawk 6x, or are the blocks for simulation purposes?
  3. As far as I understand, PX4 is ment as an autopilot flight controller, so how would I use this in MATLAB / Simulink, to control my drone in simulation?
  4. I am unsure how to exactly phrase this: I want to design a controller for the drone, I know that PX4 has some auto tuning to get you started, would I have to rebuild this in simulink / matlab, or how do I convert a controller designed in simulink to PX4, and vice versa?
  5. What is the difference between the two following options?
In advance, thank you for taking your time to read this and help me learn!

Respuestas (1)

Ankur Bose
Ankur Bose el 18 de Nov. de 2025 a las 6:56
PX4 Host Target:This refers to running PX4 firmware on your development computer (host machine) instead of on actual hardware. It’s mainly used for Software-In-The-Loop (SITL) simulation.
  • PX4 runs as a process on your PC.
  • You can connect it to Gazebo or Simulink for simulation.
  • No physical hardware is involved.
Pixhawk 6x (or similar boards):This is the actual flight controller hardware. When you deploy to Pixhawk, you’re doing Hardware-In-The-Loop (HITL) or real flight tests.
  • PX4 runs natively on the Pixhawk board.
  • You can still simulate sensors and actuators via HITL before flying.
Summary:
  • Host Target = SITL (pure software)
  • Pixhawk = HITL or real flight (hardware)
PX4 blocks in Simulink serve both purposes, depending on your workflow:
  • In SITL, they interface with PX4 running on your PC.
  • In HITL or deployment, they generate code and communicate with Pixhawk hardware.
For example:
PX4 Actuator Write block:
  • In SITL: Sends actuator commands to the PX4 process on your PC.
  • In HITL: Sends commands to Pixhawk hardware via MAVLink or serial.
When you generate code for a Simulink model that contains the PX4 Actuator Write block and deploy it either on PX4 Host target or actual hardware like Pixhawk 6x, it would write to the motor. In case of Host Target, the motors are virtual and hence you should see the motors spinning and drone flying in QGC. In case of actual hardware, the PWM pins would output the values you are writing to the PX4 Actuator write in the Simulink model.
You can model your flight controller in Simulink and deploy the generated code on hardware. The workflow is:
  1. Model your flight controller in Simulink (see the UAV Toolbox Support Package for PX4 AutoPilots controller examples).
  2. Use PX4 SITL using the PX4 Support Package to validate your controller.
  3. Once you are happy with the performance of your controller in SITL, you can deploy to actual hardware
I recommend trying out the examples in the UAV Toolbox Support Package for PX4 Autopilots for a detailed understanding of the capabilities.
In Run on board mode, code is generated and deployed on hardware. This is required for real-time behaviour. For Connected IO mode, the data is fetched via IO protocol. No code is generated, but the data is not real time.
  2 comentarios
Mats
Mats hace alrededor de 23 horas
Thank you so much! This was a really good and useful explination.
Mats
Mats hace alrededor de 22 horas
Editada: Mats hace alrededor de 22 horas
I do have a single follow up question. I have modeled my drones physical characteristics (propeller length, inertia, etc.), which I intent on using for simulations purposes. So lets say I then impliment a PID controller for my drone, and I am happy with how it works then:
How do I incorporate the PX4 blocks with my design?
Some of the blocks are actuators, and some are sensors. I would assume I could run them in parallel with my simulink model. This is the one step I am a bit stuck on. I am familiar with how to model and design a PID controller in simulink, but I am unsure how to combine my model with the PX4 blocks.
(Edit: By parallel, I mean take the values I calculate for the motor values for my simulink model and use the values [maybe converted to the correct format] for the PX4 blocks aswel.)

Iniciar sesión para comentar.

Productos


Versión

R2025b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by