How to write to PX4 in simulink?

29 vues (au cours des 30 derniers jours)
Mats
Mats le 24 Nov 2025 à 12:28
Modifié(e) : Arun Mathamkode le 27 Nov 2025 à 3:44
Hello there,
I am currently trying to learn how the PX4 blocks work in Simulink, and how to impliment them in a SIL model. I am currently trying to do a couple of things, but I can't seem to get them to work.
Simulink model:
Question 1.
Writing an accerleration to PX4. It doesn't have to be the acceleration, but I tried to make a simulation, where PX4 just read the gravity (sensor_accel), and then at some point it experienced a change in acceleration (which I would assume would be read on the sensor). The following screen shot is what I see in my Data Inspector:
I am applying a [0 0 100 ]stepfunction at t = 1, expecting to read a change on either the vehical acceleration or sensor acceleration, but I see nothing on either. I don't know why, thus my question, how do I do want I want?
Question 2.
I also watn to export the data preferably not using the Data Inspector but the out.workspace block, but when I tried to do this, the workspace output looked really weird in MATLAB:
I was expecting a long list of number, thus my question, is there a way to do this?
Question 3.
If I switch to Run on Board and run Monitor & Tune, I get the following plot from the Data Inspector:
It seems similar to question 2, but I am just really confused why I get these weird dips, when I am not varying the step function at all, i.e. after t=1, it should be constant at 100. So what is going on here?
thank you in advance for helping me learn!
  2 commentaires
Mats
Mats le 24 Nov 2025 à 14:25
Note:
With further experimentation it seems like the uORB Read VehicleAcceleration doesn't subscribe to the accerleration, or something along those lines. I can see (as shown in the provided picture) that this block doesn't actually read what I thought it would, making it even more confusing.
Mats
Mats le 24 Nov 2025 à 14:55
Modifié(e) : Mats le 24 Nov 2025 à 14:56
Update:
I went into QGroundControl and changed the following setting: SYS_HITL: SIH Enable -> HITL and SIH disable. This made it look like this (Connected I/O simulation):
But using Run on baord gave:
Which is more inline with what I am expecting from an acutal simulation. A bit of reasearch have led me to beleive that this settings tab (QGroundControl) allows for different types of simulation, what the differences are, I am not qoute sure.
But the question is now: Why doesn't the SensorAccel measure the change in acceleration?

Connectez-vous pour commenter.

Réponses (1)

Arun Mathamkode
Arun Mathamkode le 27 Nov 2025 à 3:21
Modifié(e) : Arun Mathamkode le 27 Nov 2025 à 3:44
I would encourage you to first understand about PX4 SITL, and PX4 SITL as SIH to get clarity on the questions you have.
In the context of PX4 SITL, you need to have a plant / physics model separately and that will communicate with the PX4 SITL to update all the sensor values. If you want to inject the accelerometer values you might need to do that from a plant/physics model in Simulink not in the model that you are running as SITL.You can have a look at this example to get some idea.
Now coming to your question 1 and 3. When you launch SITL from Simulink, by default it will be in SITL as SIH. What that mean is that the SITL executable already have some basic airframe physics included aand that will be used to calculate the sensor values. So the in-built physics code will be generating the sensor values and the estimator will be using those. When you write accelaration values from your model , it might momemntarily show up but immediately get overwritten from the physics code already running inside the SITL ( that too depnds upon what rate you write from Simulink). So if you want to modify the sensor values you need to do it where the plant/physics logic is there, you can't do that from the Simulink model that you are deploying as SITL.
Now regarding the confustion with sensor accelration and vehicle accelaration, you might need to first understand what these uORBs are for from its description. SenorAccel is directly from sensor and VehicleAccelaration is the computed by the estimator based on SensorAccel. Changes in VehicleAccelaration wont impact the SenorAccel.
Now coming to question 2. There are multiple options to choose from the two workspace block itself ( Structure with Time etc.). I could see in the screenshot you shared itself, it is a 1X1X7775 vector not a single value. You should be able to plot it or use it as an array.

Produits


Version

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by