Custom Matlab System Objects for use with PX4 Architecture (PX4 Serial Receive)

6 vues (au cours des 30 derniers jours)
riley
riley le 11 Fév 2025
Commenté : riley le 20 Fév 2025
Custom Matlab System that is modified copy of the PX4 Serial Receive Block wont build.
In an effort to change the way that the base PX4 serial receive block handles my incoming serial messages, I have found myself editing the very source code that makes this Matlab system object exist. Namely the px4.internal.block.SCIRead internal module. I have actually had great success in making a custom matlab system object that handles my messages the way that is needed for variable length data packets. However, this system object only runs in Connected I/O. I have made the neccesary edits to my code such that each component is compatible with simulink however I keep running into an issue with building the firmware. It will get through the entire process only to fail at the end and give me the error below which I have followed but to no avail.
Is there a way that a custom matlab system object for use in the PX4 simulink model can be used and built? I have a feeling it has something to do with some interdependencies somewhere else in the firmware. If the ability to create custom MATLAB System did exist it would give users an incredible level of power and customizability for custom flight code. I have attached my custom Matlab system, perhaps even the placement of this file in a special directory is all that is needed.The code I provided uses many of the same modules as the original PX4SCIRead and may be the reason I am running into this issue.
The location of the original matlab system reference for the PX4 Serial Receive block is located in:
C:\ProgramData\MATLAB\SupportPackages\R2023b\toolbox\target\supportpackages\px4\+px4\+internal\+block
ERROR:
Top model targets built:
Model Action Rebuild Reason
============================================================================
TEST_BED Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Build duration: 0h 1m 16.031s
Error:Error copying generated code into Pixhawk firmware directory. Delete the files in the folder C:\PX4\home\Firmware\src\modules\px4_simulink_app manually and try building again.

Réponses (1)

Ankur Bose
Ankur Bose le 20 Fév 2025
Can you tell us why you needed to modify the source code for Serial block? If it was to read variable length buffer, I just posted a response to another question that you asked
  1 commentaire
riley
riley le 20 Fév 2025
The output partial data option had no appearence of working effectively with the signal that I was sending. The data length of each data packet was no where near what was expected and caused a great deal of error regardless of what I approach I tried.
As a result I felt the need to somehow modify the blocks source code to include a more effective buffer.
In accordance with Community Guidlines, I used Chat GPT o1 to help me with the syntax of the PX4SCIRead.m MATLAB System file and make the neccesary modifications. Ive never made a mod like this before but I got it to work!
I have answered the above question on my own and discovered that there was a slight syntax error associated with the last portion of the code. Quite a bit was added to the existing code and it could probably be more efficient. It processes the signal into a vector that can just be demuxed into normal signals and also outputs a buffer value signal that will tell me the buffer length. This helps when matching data so as to avoid latency between systems during post process.
Im impressed by the current state of AI and its ability to help solve dynamic problems like this. The ability to readily modify an existing PX4 or really any matlab system block is immensely powerful and is something I intend to keep in my quiver in the future.
Not sure what the guidlines are about posting a working modded code from a toolbox, but I can provide the final version if needed.

Connectez-vous pour commenter.

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by