File Exchange

image thumbnail

Embedded Coder Support Package for PX4 Autopilots

Automatically build and deploy flight control algorithms to PX4 Autopilots using Simulink and Embedded Coder

146 Downloads

Updated 15 Aug 2019

Using Embedded Coder™ Support Package for PX4® Autopilots, you can generate C++ code, build, and deploy Simulink® models on Pixhawk® flight controllers. The support package uses the PX4 toolchain to compile and deploy algorithms tailored specifically for Pixhawk flight management units and lets you customize algorithms to incorporate onboard sensor data and other PX4-specific services. PX4 is a trademark of Lorenz Meier.

Comments and Ratings (35)

Daniel

Quick question:

Can you point me in a direction to understand how the mixers are implemented in matlab? I don't seem to understand the motor mixer block.

Thanks. Sorry i'm sending many messages. Its so that when you eventually read this, you can just address all of them at once.

Thanks once again.

Daniel

Hi support team,

I have installed the suport package on Ubuntu 16.04. I was able to build the firmware successfully, and upload. However, I am unable to read accelerometer values from the Pixhawk1 (the device I am targeting).

Secondly, when I try to run the example models (i've tried about 3 now), it builds fine, but then gets to a point and says the following (copied from diagnostic window):

Build process completed successfully
host endian mode: Little
Component:Simulink | Category:Model
byte swapping required: false
Component:Simulink | Category:Model
action: EXT_CONNECT
Component:Simulink | Category:Model
Error occurred while executing External Mode MEX-file 'ext_comm':
Timed-out waiting for second connect response packet.
Component:Simulink | Category:Block diagram error
Unable to connect to the 'PX4 Pixhawk 1' target for 'px4demo_Read_Parameter'.

Please help. I tried to do some googling and similar error occured for Arduino users as a result of baudrate issues in non-original boards. I tried to reduce the default baudrate on the 'target hardware resources' in the setup to 57600 which I know to work with 'screen' on DTFI cable. That didn't work. I reduced it further 38400, still didn't work. Please help.

Thank you.

Ankur Bose

Hi John Jahadi,
the wmic command is a windows API and it should be present in all Windows 10 PC. Please check your Windows 10 path environment variable.

john Jahadi

Hi Ankur Bose,
I did it and the response is :
'wmic' is not recognized as an internal or external command,
operable program or batch file.
ans =
1
Now what should I do?
Thanks for responses

Ankur Bose

Hi John Jahadi,
Please execute the below command in MATLAB command window and let us know the output.
system('wmic os get Caption')

john Jahadi

Hi,
I reinstall matlab and Install this pakage too.
I have these error
Error using matlab.hwmgr.internal.hwsetup.launchHardwareSetupApp (line 18)
Error instantiation matlab.hwmgr.internal.hwsetup.register.PX4Workflow. Details Error while checking windows
version

Error in matlabshared.supportpkg.internal.ssi.openHwSetupForBaseCodes

Error using matlab.hwmgr.internal.hwsetup.launchHardwareSetupApp (line 18)
Error instantiation matlab.hwmgr.internal.hwsetup.register.PX4Workflow. Details Error while checking windows
version

Error in matlabshared.supportpkg.internal.ssi.openHwSetupForBaseCodes

com.mathworks.mvm.exec.MvmExecutionException: matlabshared.supportpkg.internal.ssi.openHwSetupForBaseCodes
at com.mathworks.mvm.exec.NativeFutureResult.nativeGet(Native Method)
at com.mathworks.mvm.exec.NativeFutureResult.get(NativeFutureResult.java:62)
at com.mathworks.mvm.exec.FutureResult.getInternal(FutureResult.java:404)
at com.mathworks.mvm.exec.FutureFevalResult.getInternal(FutureFevalResult.java:49)
at com.mathworks.mvm.exec.FutureResult.get(FutureResult.java:262)
at com.mathworks.hwsmanagement.OpenHardwareSetupAction.perform(OpenHardwareSetupAction.java:60)
at com.mathworks.addons.action.PerformAdditionalAction.perform(PerformAdditionalAction.java:28)
at com.mathworks.addons.ActionHandler.dispatch(ActionHandler.java:27)
at com.mathworks.addons.AddonsCommunicator$1.handle(AddonsCommunicator.java:37)
at com.mathworks.connector.message_service.impl.MessageServiceJSONImpl.handlePublishRequest(MessageServiceJSONImpl.java:29)
at com.mathworks.connector.message_service.impl.AbstractMessageService.handlePublishRequest(AbstractMessageService.java:58)
at com.mathworks.connector.message_service.impl.JniMessageServiceAdaptorImpl.doHandlePublish(JniMessageServiceAdaptorImpl.java:59)
at com.mathworks.connector.message_service.api.JniMessageServiceAdaptor.fromNative(JniMessageServiceAdaptor.java:21)
Caused by: com.mathworks.mvm.exec.MvmRuntimeException: Error instantiation matlab.hwmgr.internal.hwsetup.register.PX4Workflow. Details Error while checking windows version
Error in ==> D:\MATLABR18\R2018b\toolbox\shared\hwmanager\hwsetup\launch\+matlab\+hwmgr\+internal\+hwsetup\launchHardwareSetupApp.m>launchHardwareSetupApp at 18
Error in ==> D:\MATLABR18\R2018b\toolbox\shared\supportpkgservices\installservices\+matlabshared\+supportpkg\+internal\+ssi\openHwSetupForBaseCodes.p>openHwSetupForBaseCodes at 0

john Jahadi

Hi Ankur Bose,
I am using Matlab R2018b and my windows version is Win 10
Thanks

Ankur Bose

Hi John Jahadi,
Can you tell us what is the MATLAB version (R2018b or R2019a) that you are using? What is the Windows version(Windows 7, 8.1 or 10) on which you are running MATLAB? Also, can you let us know the output of the below command when you run it in MATLAB command window?
system('wmic os get Caption')

Ankur

john Jahadi

hi,
I am using this toolbox to modify the pix-hawk controller.
in simulink configuration parameters >Hardware implementation > when I click on change CMake configuration
I have this ERROR :
ERROR while checking windows version.
please Help me.
Thanks

Ankur Bose

Hello lulu chen,
Can you please tell us more about the issue? Are you facing it for example models or just for px4demo_PWM?

Yuhui Liu

ge dew

Hello,
After following all instructions, and successfull firmware upload and readout of the accellorator values in hardware setup screen I ran into following problems with the DEMO: 'px4demo_adc'

### Generating code into build folder: C:\Users\root\Documents\MATLAB\px4_SDCard_logging_ert_rtw
### Invoking Target Language Compiler on px4_SDCard_logging.rtw
### Using System Target File: C:\Program Files\MATLAB\R2018b\rtw\c\ert\ert.tlc
### Loading TLC function libraries
......
### Initial pass through model to cache user defined code
..
### Caching model source code
..........................................
### Writing header file px4_SDCard_logging_types.h
### Writing source file px4_SDCard_logging.cpp
### Writing header file px4_SDCard_logging_private.h
### Writing header file px4_SDCard_logging.h
### Writing header file rtwtypes.h
.
### Writing header file multiword_types.h
### Writing source file px4_SDCard_logging_data.cpp
### Writing header file rtmodel.h
### Writing source file ert_main.cpp
### TLC code generation complete.
### Generating TLC interface API.
.............
### Creating data type transition file px4_SDCard_logging_dt.h
.### Evaluating PostCodeGenCommand specified in the model
Removing old px4_simulink_app directory: C:\px4_cygwin\home\Firmware\src\modules\px4_simulink_app.
Build path: C:\Users\root\Documents\MATLAB\px4_SDCard_logging_ert_rtw
### Using toolchain: GNU Tools for PX4 Autopilots v7.2.1 | gmake (64-bit Windows)
### 'C:\Users\root\Documents\MATLAB\px4_SDCard_logging_ert_rtw\px4_SDCard_logging.mk' is up to date
### Building 'px4_SDCard_logging': "C:\PROGRA~1\MATLAB\R2018b\bin\win64\gmake" -f px4_SDCard_logging.mk postdownload_preexecute all

C:\Users\root\Documents\MATLAB\px4_SDCard_logging_ert_rtw>cd .

### Invoking postbuild tool Invoke Make ...
Making Firmware
0 [main] sh 208 sync_with_child: child 12060(0x1D0) died before initialization with status code 0xC0000142
43219 [main] sh 208 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
gmake: *** [postdownload_preexecute] Error 128
...
C:\Users\root\Documents\MATLAB\px4_SDCard_logging_ert_rtw>echo The make command returned an error of 2
The make command returned an error of 2

C:\Users\root\Documents\MATLAB\px4_SDCard_logging_ert_rtw>An_error_occurred_during_the_call_to_make
'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
operable program or batch file.
### Creating HTML report file px4_SDCard_logging_codegen_rpt.html
Warning: Validation warning(s):
Skipped the existence check for 'GNU PX4 C Compiler'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo gcc'.
Skipped the existence check for 'GNU PX4 Pre-Linker'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo gcc'.
Skipped the existence check for 'GNU PX4 C++ Compiler'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo g++'.
Skipped the existence check for 'GNU PX4 C++ Pre-Linker'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo gcc'.
Skipped the existence check for 'Invoke Make'. Cannot determine the utility that needs to be checked for existence from the build tool command '$(call CALLPX4MK)'.
### Build procedure for model: 'px4_SDCard_logging' aborted due to an error.
Error(s) encountered while building "px4_SDCard_logging":
### Failed to generate all binary outputs.

lulu chen

lulu chen

When I run a sample, the following error occurs.

### Successful completion of build procedure for model: px4demo_PWM
### Creating HTML report file px4demo_PWM_codegen_rpt.html
Build process completed successfully
host endian mode: Little
Component:Simulink | Category:Model
byte swapping required: false
Component:Simulink | Category:Model
action: EXT_CONNECT
Component:Simulink | Category:Model
Error occurred while executing External Mode MEX-file 'ext_comm':
Timed-out waiting for second connect response packet.

Ankur Bose

Hello zjwrj,
The official fix for this issue is now available through support package updates in R2018b. Please update your support package. After the support package is updated, execute the below commands in MATLAB command window and try building the model again.
setenv('MW_PX4_WIN10_BUILDCMD','')
setpref('MW_PX4_WSLBuildPath','SwitchPath', 1)

Ankur Bose

Hello zjwrj,
This was an issue that we have fixed and official bug fix will be available soon. If you wait for some more days, you can upgrade the current support package and get the bug fix. If you need it urgently, please let me know your email-id so that I can reach you and help you in getting the issue resolved.

Thanks,
Ankur

zjwrj

Hello AnKur Bose,Thank you for your response
I did what you said,Still have errors
The error message is as follows:
"### Created: ../px4_uorb.pre.o"
"### Invoking postbuild tool "Invoke Make" ..."
"Making Firmware "
'/run-console_Simulink.bat' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
gmake: *** [postdownload_preexecute] Error 1

C:\Users\EFY\Desktop\px4test\px4_uorb_ert_rtw>echo The make command returned an error of 2
The make command returned an error of 2

C:\Users\EFY\Desktop\px4test\px4_uorb_ert_rtw>An_error_occurred_during_the_call_to_make
'An_error_occurred_during_the_call_to_make' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
### Creating HTML report file px4_uorb_codegen_rpt.html
警告: Validation warning(s):
Skipped the existence check for 'GNU PX4 C Compiler'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo gcc'.
Skipped the existence check for 'GNU PX4 Pre-Linker'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo gcc'.
Skipped the existence check for 'GNU PX4 C++ Compiler'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo g++'.
Skipped the existence check for 'GNU PX4 C++ Pre-Linker'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo gcc'.
Skipped the existence check for 'Invoke Make'. Cannot determine the utility that needs to be checked for existence from the build tool command '$(call CALLPX4MK)'.
### Build procedure for model: 'px4_uorb' aborted due to an error.
Error(s) encountered while building "px4_uorb":
### Failed to generate all binary outputs.
Caused by:
Validation error(s):
### Validating other build tools ...
Unable to locate build tool "GNU PX4 Archiver": echo

Ankur Bose

Hello zjwrj,
Please execute the below two commands in your MATLAB command window to resolve the issue:
setenv('MW_PX4_WIN10_BUILDCMD','')
setpref('MW_PX4_WSLBuildPath','SwitchPath', 1)

After you have execured the above commands in R2018b command window, try building the Simulink model again.

zjwrj

Hello Abhishek GS
1, MATLAB Version :matlab2018b
2, I am using Windows Subsystem for Linux toolchain
3,Hardware Setup Screens is ok
4,An error occurs when run the model
5,The error message is as follows
"### Created: ../px4_uorb.pre.o"
"### Invoking postbuild tool "Invoke Make" ..."
"Making Firmware "
系统找不到指定的路径。
'bash' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
gmake: *** [postdownload_preexecute] Error 1

C:\Users\EFY\Desktop\px4test\px4_uorb_ert_rtw>echo The make command returned an error of 2
The make command returned an error of 2

C:\Users\EFY\Desktop\px4test\px4_uorb_ert_rtw>An_error_occurred_during_the_call_to_make
'An_error_occurred_during_the_call_to_make' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
### Creating HTML report file px4_uorb_codegen_rpt.html
警告: Validation warning(s):
Skipped the existence check for 'GNU PX4 C Compiler'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo gcc'.
Skipped the existence check for 'GNU PX4 Pre-Linker'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo gcc'.
Skipped the existence check for 'GNU PX4 C++ Compiler'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo g++'.
Skipped the existence check for 'GNU PX4 C++ Pre-Linker'. Cannot determine the utility that needs to be checked for existence from the build tool command 'echo gcc'.
Skipped the existence check for 'Invoke Make'. Cannot determine the utility that needs to be checked for existence from the build tool command '$(call CALLPX4MK)'.
### Build procedure for model: 'px4_uorb' aborted due to an error.
Error(s) encountered while building "px4_uorb":
### Failed to generate all binary outputs.
Caused by:
Validation error(s):
### Validating other build tools ...
Unable to locate build tool "GNU PX4 Archiver": echo

Abhishek GS

Hello zjwrj,
Can you provide the below information?
1. MATLAB Version
2. Operating system
3. If windows, Can you let us know if you are using the Cygwin toolchain or Windows Subsystem for Linux toolchain?
4. Were you able to successfully complete the Hardware Setup Screens?
5. Complete error log.

You could also reach out via technical support channel.

https://www.mathworks.com/support/contact_us.html

zjwrj

Error(s) encountered while building "px4_readGPS":
### Failed to generate all binary outputs.
Caused by:
Validation error(s):
### Validating other build tools ...
Unable to locate build tool "GNU PX4 Archiver": echo
What is the reason?

Ankur Bose

Hello All,
The Embedded Coder Support Package for PX4 Autopilots is now available in R2018b. If you are working in R2018b, you can try downloading the support package and start working with it.

Abhishek GS

Hello Bart,

You could also reach out via technical support channel.

https://www.mathworks.com/support/contact_us.html

Ankur Bose

Hello Bart Slinger,
Can you please provide more details about the issue you are facing? If you have any use-case or feature that you would like to be present in the support package, you can let us know. If it helps, you can share your email-id and we can follow up with you about the pain you are facing?

Does not work out of the box. Option Prepare to Run not available.

Abhishek GS

Refer the below link to understand the capabilities of the support package.
https://www.mathworks.com/hardware-support/pixhawk.html

Ankur Bose

Abhishek GS

MATLAB Release Compatibility
Created with R2018b
Compatible with R2018b to R2019a
Platform Compatibility
Windows macOS Linux