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

189 Downloads

Updated 18 Mar 2020

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 (103)

alan

islam dib

Ankur Bose,
Hello,
I've always a problem
one rotor stop to turn until I make an agressive manovrabilité and it star to turn for 5 seconds and then stop
how can I fix the problem ?

Ankur Bose

Hello All,
MATLAB R2020a is live now. The R2020a version of Embedded Coder Support Package for PX4 Autopilots provides you a way to deploy the PX4 Executable on the host and connect with the jMAVSim simulator. You can also run Processor-In-Loop (PIL) simulation for your Pixhawk hardware. The support package also contains a deployment solution for Crazyflie 2.0 which is a palm-sized drone.

Ankur Bose

Hello July,
Are you still facing the issue? Can you share the full build failure log?

R

Mrudit
You should add to your rc.txt mavlink protocol on telem1(ttyS1 on nuttx)
add this lines:

mavlink start -d /dev/ttyS1 -m config –x # for mavlink protocol -telem1 port
mavlink boot_complete

and dont forget in the simulink app, in the hardware configuration ,in the baudrate of s1 port , to configure it to 57600
that worked for me

I have been trying to run simulink files but unable to connect the Pixhawk to MATLAB over wifi using the esp8266 wifi module as it does not detect the port. I believe there is some Mavlink code missing/incorrect in the rc.txt file, as the Pixhawk connects to QGC over wifi perfectly without this file. I have tried all combinations of the code and 'serial port' options in the Configuration parameters>Hardware Implementation of Simulink, that i could find in the documentations.

Mavlink WIFI Bridge parameters:
WIFI_UDP_HPORT = 14550
WIFI_UDP_CPORT = 14555
UART_BAUDRATE = 57600

My rc.txt file has the following code:

#Copyright 2018 The MathWorks, Inc.
# This is the custom rc.txt which loads px4_simulink_app on start-up
usleep 1000
uorb start
usleep 1000
tone_alarm start
usleep 1000
px4io start
#gps start -f #Starts GPS driver and Fake a GPS signal (useful for testing)
usleep 1000
sh /etc/init.d/rc.sensors
usleep 1000
#Uncomment the below 2 lines to use LPE estimator
#attitude_estimator_q start
#local_position_estimator start
#Using EKF2 estimator by default as PX4 does build LPE on px4fmu-v2 due to a limited flash.
ekf2 start
usleep 1000
mtd start
usleep 1000
param load /fs/mtd_params
usleep 1000
rgbled start
usleep 1000
fmu mode_pwm # This is required for AUX PWM channels
usleep 1000
px4_simulink_app start
mavlink start -u 14550 -b 57600 -m onboard -r 80000
mavlink boot_complete
#exit #4-Jan-2019

even tried the following line:
mavlink start -d /dev/ttyS1 -b 57600 -m onboard -r 80000

July

What is wrong with it? How to solve it? Thanks!
### Build procedure for model: 'px4demo_Read_Parameter' aborted due to an error.
Error(s) encountered while building "px4demo_Read_Parameter":
### 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

Hi Erina Nesbit,
We are working to provide I2C support in future MATLAB release. Can you let us know what external sensors you are using?

Ankur Bose

Hi Benyamin Krisna,
Are you able to read the GPS data over the serial port? It is possible that the area you are working in is not receiving GPS values. Try connecting the GPS sensor to a raw serial port, in the Simulink model, loopback the serial data to another serial port and observe the values

Abhishek GS

Hello Erina,

We are working on supporting I2C channels through Simulink and it is planned for a future release. Could you please let us know what external sensors are you looking forward to using?

July

islam dib

Hello,
Please, where can I found the PID parameters to control the attitude and altitude ?
Is it possible to change this parameters online, e.i while rotors turn?

Does anyone know if this package supports the i2c channels? Most of my external sensors are connected via the i2c only.

Hi Ankur,
yeah, I got that part figured out. Do you know the problem with the GPS? And is there another way to control the LEDs then?

Ankur Bose

Hi Benyamin Krisna,
Because both MAVLink and External mode require the same USB serial port to work, only one of them can work at a time. Enabling MAVLink on the USB serial port in rct.txt will cause External mode to not work.

Hi Ankur,
it seemed that the error occurred when I modified the mavlink command in the rc.txt data. After I changed it back it went to normal.
Nevertheless I still couldn't access the GPS data. I used the px4_readGPS blocks: the status seems to be 1 (on) but no GPS data were retrieved. I tried this with several GPS (I have a Pixhawk 2.1 Cube and a Pixhawk 4 with different GPS modules), but neither worked.

Ankur Bose

Hi Benyamin Krisna,
I believe that you are facing 2 separate problems.
1. External Mode fails with the "timed-out" error.
2. Unable to send data using PWM or control LEDs

Regarding 1, do you see the issue with all models or just for some particular models?
Regarding 2, you cannot control the LEDs in Pixhawk Cube 2.1 using uORB topic, but you can definitely send PWM values. Have you completed the SD card process as mentioned in the doc?
https://de.mathworks.com/help/supportpkg/px4/ug/px4-system-startup-sdcard.html

You could also reach out via technical support channel.

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

Ankur Bose

Hi mehmet enes avcu,
What is the Pixhwak board you are using? Can you share the steps you did when you got the error?

Hi everyone l have little problem like this
'Board can accept larger flash images (2080768 bytes) than board config (1032192 bytes). Please use the correct board configuration to avoid lacking critical functionality.'
how do ı solve this problem?

Hey, I'm having the issue that I couldn't send any outputs. I can read sensor datas and all, but I couldn't use the PWM output block, or light up the LEDs.
I use the Pixhawk Cube 2.1. The Building and flashing is alright, the diagnostic viewer said
'Error occurred while executing External Mode MEX-file 'ext_comm':
Timed-out waiting for second connect response packet

Ankur Bose

Hi Yuichi Tadokoro,
Thanks for reporting the issue. You don't need to be in the same folder as your PX4 in Simulink. It looks like an issue with being unable to change directory to the PX4 in WSL. Where is your PX4 firmware located? Also, from R2019b, we officially support the Cygwin toolchain in Windows as that is the one that is maintained by PX4 ecosystem. The support for WSL would be deprecated in a future release.

Ankur

I found that the following error occurs if the simulink model is not in the same drive as 'mypx4' folder. Hope this will be fixed in the next release.

FYI, I'm using MATLAB 2019a and PX4 Support Package v19.1.3 with WSL on Windows 10, and I have set SwitchPath to 1.

```
"### Created: ../mdl_px4_quad_velocity_control.pre.o"
"### Invoking postbuild tool "Invoke Make" ..."
"Making Firmware "
make: *** No rule to make target 'px4fmu-v3_default'. Stop.
gmake: *** [postdownload_preexecute] Error 2
D:\example-quad-lqr\mdl_px4_quad_velocity_control_ert_rtw>echo The make command returned an error of 2
The make command returned an error of 2
D:\example-quad-lqr\mdl_px4_quad_velocity_control_ert_rtw>exit 1
### Creating HTML report file mdl_px4_quad_velocity_control_codegen_rpt.html
```

hello
The model that you are trying to run in External mode does not match the application running on your target. Checksum test (TARGET_CONNECT) failed. The host model's structural checksum is [2135821802, 2341299805, 4186466913, 885981311] and the target application's structural checksum is [3959188552, 3115388892, 3377675010, 1540357901]. Rebuild the model, run it on your target, and start External mode simulation again.

I even deleted old folders of the program and save the model

Hello everyone,
I'm wondering how to set up return home mode while using
Embedded Coder Support Package for PX4 Autopilots.
I didn't find the topic including the publisged message to set up that

best

Hello again,

I solved my problems on pixhawk 2. Flashing with mission planner works but doesn't solve the port change problem on my computer. When i do in that manner, port problem doesn't affects control software and successfully connects, but because of ports, matlab upload fails.
So shortly, if you come up to advanced port settings via windows device manager, change com port and make both changable port numbers same, you can by-pass the problem. However port definitions change, numbers are same and windows be trickked. Build, upload processes could be done in Simulink PSP. However, in that approach, i fail to connect control softwares. I will also need to try Qground upload approach.

My other problems reason is incorrect sdcard settings, i fix that.
regards...

Hello everyone,
I'm wondering how to set up return home mode while using
Embedded Coder Support Package for PX4 Autopilots.
I didn't find the topic including the publisged message to set up that

best

hello Burak Yörük
I have solved the same Problem on pixhawk 1.
Did you flash the firmware using missing planner?
If yes, you should flash it with Qground contol, then you have just one fixed com port. then you can upload firmware in setting up PX4 support package.
best

Hello everyone,
I have a problem about uploading the firmware in setting up PX4 support package. I'm beginning to tell in long way about what I did. First, I observed my port oddness which i think about that cause. In initial moment in USB connection, Device Manager shows "ProfiCNC CUBE F4 FMU(COM3)" but within 5 sec. it's changing to "Legacy FMU(COM6)".
I tested and found out Support package only can upload on ProfiCNC CUBE F4 FMU(COM3), Legacy defined COM6 useless for uploading, can't find. So I handle in a kind of way that begin uploading process within 5 sec. in connection. But after, getting Acc. Datas failed cause of that issue, uploading demo examples also stucked.
The first question is
"Attempting reboot on COM6 with baudrate=57600...
If the board does not respond, unplug and re-plug the USB connector"
I suppose the have to change baudrate(57600 to 115200) to overcome this problem. How can i change that baudrate ?

So, i tried another way, just generating code in Simulink via SP and building manually on bash. When building manually i had error message like
../../src/modules/px4_simulink_app/MW_PX4_TaskControl.h:61:1: fatal error: px4demo_LEDBuzzer_types.h: No such file or directory
#include MW_StringifyDefine(MW_StringifyDefineTypesX(MODEL))
^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
and I found that's about MODEL.h library, I can't solve it and build on bash. That's second question.
On the other hand if i try building on Simulink, it works, no errors. I flash .px4 build file via Mission Planner. But running px4_simulink_app nothing change on HW. Considering px4_LedBuzzer demo. That's third question.

I'm very tired guys, any help pls. I just want to see any activity on my pixhawk cube.

Windows 10 version 1809
using Pixhawk2 Cube with px4 v1.8.0
Cmake version 3.6.2
gcc version 7.3.0

Hello
I solve it.
To those who had encountered this issue, just add the file the Matlab path

I got the following errors on shell while using sd card :
nsh> param load /fs/mtd_params
ERROR [parameters] failed to open param file: /eeprom/parameters
ERROR [parameters] param save failed (-1)
ERROR [parameters] failed to open param file: /eeprom/parameters
ERROR [parameters] param save failed (-1)

nsh> param set RTL_LAND_DELAY 5
+ RTL_LAND_DELAY: curr: 10.0000 -> new: 5.0000
nsh> ERROR [parameters] failed to open param file: /eeprom/parameters
ERROR [parameters] param save failed (-1)

Dear p fontaine
Can you provide some clarification about wmic command. I have been looking on google but I didn't find that.

BEST

p fontaine

If you experienced the following error during installation :

Error using matlab.hwmgr.internal.hwsetup.launchHardwareSetupApp (line 18)

Change your system PATH variable if it contains %systemroot%
Replace %systemtoot% by the path to the windows install directory (usually C:\WINDOWS)
Otherwise the wmic command is not recognized (you can check that in a command shell)

Dear all
After loading the Simulink model to the pixhawk using the awsome 'Embedded Coder Support Package for PX4 Autopilots', I couldn't arm the motors and start the flight, I'm sure that there is something missing in the 'rc.txt' file in the SD card, but I do not know how to fix that, looking for your help
thanks
here is my rc,txt:
#Copyright 2018 The MathWorks, Inc.

# This is the custom rc.txt which loads px4_simulink_app on start-up
usleep 1000
uorb start
usleep 1000
#nshterm /dev/ttyACM0 & #Disable the USB serial console
usleep 1000
tone_alarm start
usleep 3000
px4io start
gps start # #gps start -f Starts GPS driver and Fake a GPS signal (useful for testing)
usleep 1000
sh /etc/init.d/rc.sensors
usleep 1000
#Uncomment the below 2 lines to use LPE estimator
#attitude_estimator_q start
#local_position_estimator start
#Using EKF2 estimator by default as PX4 does build LPE on px4fmu-v2 due to a limited flash.
ekf2 start
usleep 1000
mtd start
usleep 1000
param load /fs/mtd_params
usleep 1000
rgbled start
usleep 1000
fmu mode_pwm # This is required for AUX PWM channels
usleep 1000

#......... arming ....

mavlink start -d /dev/ttyACM0 -m config –x
px4_simulink_app start
nshterm /dev/ttyS6 & #this will make ttyS6 the serial console

mavlink boot_complete

#exit #4-Jan-2019

Ankur Bose
Thanks a lot for your answer regarding PIL. Really happy

Ankur Bose

mechali omar, Petar Labetic,
Which manual 'PX4 Autopilots Support from Embedded Coder' are you referring to? We had a manual for the pilot version of the support package till R2018a and the manual is not applicable from R2018b. The pilot version of the PX4 support package has been replaced by the official version from R2018b. Please refer to the official version of the support package documentation https://in.mathworks.com/help/supportpkg/px4/index.html for any help/troubleshooting

Ankur Bose

mechali omar
PIL is not supported in the PX4 support package in R2019b. The support for PIL in the PX4 support package will be available in R2020a

Ankur Bose

mechali omar
PIL is not supported in the PX4 support package in R2019b. The support for PIL in the PX4 support package will be available in R2020a

Ankur Bose

Petar Labetic,
PIL is not supported in the PX4 support package in R2019b. The support for PIL in the PX4 support package will be available in R2020a

Ankur Bose

Petar Labetic,
Can you tell us how did you install the support package? From the error log you shared, it looks like the installation of the support package is not correct.

Petar Labetic
have you finished installing Embedded Coder Support Package for PX4 Autopilots?
have you finished installing toolchine?

Balaji Kartikeyan Chandrasekaran
have you finished the set up of SD card? because the rc.txt file in the Sd card will start the Simulink model you uploaded to the pixhawk

Hi all, I am new to using pixhawk support in embedded coder. I followed everything as per setup. I tried to run the log file example and matlab loads it into px4 but px4 doesn’t do anything I.e. No log file. I tried to pair px4 with qgroundcontrol to make sure the sensors were working and it did. I even connected to px4 using MAVLink . It seems that it fails only when using simulink model. Can someone help me out or facing similar issues? I am using MATLAB 2019a

Hi Omar. Yes I have followed the manual but the error occurs in the first step when I click on the setup option in the Add-ons manager for setting up the hardware.

Petar Labetic, have you followed the manual 'PX4 Autopilots Support from Embedded Coder' ?
In which step are you struggling?

Hi. I keep getting an error every time I try to setup the support package. I see people have been already asking but no answer. I also ran the command system('wmic os get Caption') and got:
Caption
Microsoft Windows 7 Ultimate

ans =

0
I am running MATLAB R2019b and the error goes as followed:
Error using matlab.hwmgr.internal.hwsetup.launchHardwareSetupApp (line 24)
Error launching Hardware Setup App.
Details: Error launching Hardware Setup workflow Hardware Setup App for PX4 Autopilots for base code
PX4AUTOPILOTS
Details: Undefined function 'codertarget.pixhawk.hwsetup.SetupCygwin' for input arguments of type
'matlab.hwmgr.internal.hwsetup.register.PX4Workflow'.

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:413)
at com.mathworks.mvm.exec.FutureFevalResult.getInternal(FutureFevalResult.java:49)
at com.mathworks.mvm.exec.FutureResult.get(FutureResult.java:263)
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 launching Hardware Setup App.
Details: Error launching Hardware Setup workflow Hardware Setup App for PX4 Autopilots for base code PX4AUTOPILOTS
Details: Undefined function 'codertarget.pixhawk.hwsetup.SetupCygwin' for input arguments of type 'matlab.hwmgr.internal.hwsetup.register.PX4Workflow'.
Error in ==> C:\Program Files\MATLAB\R2019b\toolbox\shared\hwmanager\hwsetup\launch\+matlab\+hwmgr\+internal\+hwsetup\launchHardwareSetupApp.m>launchHardwareSetupApp at 24
Error in ==> C:\Program Files\MATLAB\R2019b\toolbox\shared\supportpkgservices\installservices\+matlabshared\+supportpkg\+internal\+ssi\openHwSetupForBaseCodes.p>openHwSetupForBaseCodes at 0

My friends do we need to set a target for the pixhawk to enable PIL simulation , or it's already set? of it's exists, what's the appropriate 'hw', and 'tgt' name since we need that in
pil = addNewPIL(tgt,'MyPIL');
map(tgt,hw,pil,'My Serial Interface');

and others commands

Guys, it is solved. the error is due to that I make several copies of the parent model in different directories. I deleted all of them, and I just set up the COM port, and it's good.

Hello Ankur Bose,
Thanks, the problem has been solved just today. but how, I don't know hhh
I'm using MatLab R2019b.

Another thing, I', trying to deploy the attitude control model to pixhawk but I'm getting this error "Hardware board settings must be the same for all models in the Model Reference hierarchy. To inspect these settings, open the model Configuration Parameters and select the Hardware Implementation pane"
We are kindly looking for a precise tutorial which show exactly the steps to be followed, including hardware setting.

Ankur Bose

Hi mechali omar,
What is the MATLAB version you are using?

Ankur

. Currently only v1.8.0 version of PX4 is supported. If the version is less than v1.8.0, the firmware
build may fail in further screens. If the version is greater than v1.8.0, the functionalities may not
work as expected. We recommend you to specify a PX4 firmware directory with version v1.8.0.

Hi
I got the following error Firmware validation failed: No matching files were found.
MATLAB 2019b
it 's asking me to provide a file for firmware version v1.8.0

Hi Ankur,
Thanks for the info. There is no specific reason, the project is just currently using 1.9 and we want to avoid porting everything back to 1.8, as porting the generated code to 1.9 is probably less work.

Ankur Bose

Hi Daniel Frank,
The upgrade of the firmware support to the newer PX4 firmware versions is on the roadmap. Can you let us know why you are interested in the 1.9 or 1.10 version? What trouble you are facing with v1.8.0?

Hi,
I need to use this together with PX4 firmware 1.9 or the upcoming 1.10. I was able to port the generated code to these newer versions but some things are still causing trouble.
Before spending any more time on this I would like to ask if any upgrade to a newer firmware version is planned in the near future?

Ankur Bose

Hello All,
The Embedded Coder Support Package for PX4 Autopilots is now available in R2019b. The support for Cygwin Toolchain for Windows has been added in R2019b. If you are working in R2019b in Windows, you can now use the Cygwin Toolchain to build the PX4 firmware instead of using WSL.

andyfl

Problem was that I didn't perform PX4 System Startup from SD Card

-> https://de.mathworks.com/help/supportpkg/px4/ug/px4-system-startup-sdcard.html

Ankur Bose

Hi andyfl, Yu-Ru chien,
Please reach out to us through Technical support channel so that we can help you better.
https://www.mathworks.com/support/contact_us.html

Yu-Ru chien

Hi,Ankur Bose,
Yes, I did. But the error stil occured.
I even changed my matlab version from R2018b to R2019a,and finished the Hardware setup again.
However, it didn't work for fixing the error.
it's very weird that I am able to use COM3 aka /dev/ttyACM0 to upload firmware by Hardware Setup screen, but can not use COM3 to connect PX4 Pixhawk 1 on running External mode.
please help.

Btw, if somebody uploaded your firmware successfully, can you share me waht you have done form start to finish please ...

andyfl

Hey, I have the same issue and can't manage to get rid of it. I'm using MATLAb 2018b and Pixhawk 1. I also tried several Baudrates and the command
setenv('MW_PX4_WIN10_BUILDCMD', 'cmd /c start cmd /k "C:/Windows/Sysnative/bash.exe -cli "make $(CMAKEMAKECONFIG) " 2> MWPX4BuildLog.txt & echo MW_BUILD_COMPLETE >> MWPX4BuildLog.txt " ');
The commands you suggested
setenv('MW_PX4_WIN10_BUILDCMD','')
setpref('MW_PX4_WSLBuildPath','SwitchPath', 1)
don't work either.
My px4_read_demo file contains a 'uORB Read'-Block and several 'Display's as sinks. MAVLink's been disabled all time. I tried it on Windows 18362 and Ubuntu 18.04 with the same result.

### Successful completion of build procedure for model: px4_read_demo
### Creating HTML report file px4_read_demo_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.
Component:Simulink | Category:Block diagram error
Unable to connect to the 'PX4 Pixhawk 1' target for 'px4_read_demo'.

Could somebody help me please?

Ankur Bose

Hi Yu-Ru chien,
Did you disable MAVLink over USB port?

Yu-Ru chien

I have changed the External setting for using USB port on Hareware Implementatoiin >> External mode
But the error was still occur :

Verify : [ ] 1.0%
Verify : [====================] 100.0%
Rebooting.

### Successful completion of build procedure for model: px4_control_system_ver4
Build process completed successfully
action: EXT_CONNECT
Component:Simulink | Category:Model
Error occurred while executing External Mode MEX-file 'ext_comm':
Failed to connect to the target. A time-out occurred while waiting for the connection response from the target. Possible reasons for the time-out:
a) The target is not switched on.
b) The target is not connected to your host machine.
c) The application for the model is not running on the target. You might have clicked the Stop button. If the Run button is not dimmed, click it. Otherwise, click the Build button, which downloads and runs your application on the target.
Component:Simulink | Category:Block diagram error
Unable to connect to the 'PX4 Pixhawk 1' target for 'px4_control_system_ver4'.

I tried to change baudrate to 9600, 57600, 115200, 921600 on Hardware Implementation >> /dev/ttyACM0 ,but the error still can not fix.
please help

Yu-Ru chien

Hi Ankur Bose,
Beacuse I enabled MAVLink over USB port.
Should I use other port for enabling MAVlink and run External mode on USB port ?

Ankur Bose

Hi Yu-Ru chien,
Can you tell us why you are using Serial 5 on Pixhawk 1 for External mode instead of using the USB port aka /dev/ttyACM0 ?

Yu-Ru chien

I have completed the SD card setup and inserted in Pixhawk 1 flight controller.
But when I run my own firmware on external mode( /dev/ttyS5 aka Serial 5 ), a error occured on connecting the Pixhawk 1 and said the following :

Program: [=================== ] 99.8%
Program: [====================] 100.0%

Verify : [ ] 1.0%
Verify : [====================] 100.0%
Rebooting.

### Successful completion of build procedure for model: px4_control_system_ver4
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 Series' target for 'px4_control_system_ver4'.

However, I could use putty to connect the controller by serial 5.
Can somebody help me fix the error ?

p.s. I set the baudrate of Serial 5 at 57600

dale

Hi Ankur Bose
thank you for replying to my comments.
The command setpref('MW_PX4_WSLBuildPath','SwitchPath', 1) didn't work .
and setpref('MW_PX4_WSLBuildPath','SwitchPath', 0) won't work either ,because the command i need is 'setenv('MW_PX4_WIN10_BUILDCMD', 'cmd /c start cmd /k "C:/Windows/Sysnative/bash.exe -cli "make $(CMAKEMAKECONFIG) " 2> MWPX4BuildLog.txt & echo MW_BUILD_COMPLETE >> MWPX4BuildLog.txt " ')',,not antything else.
The command 'setpref('MW_PX4_WSLBuildPath','SwitchPath', 1) ' won't help me get the correct setenv command i need.

Ankur Bose

Hi Dale,
Have you looked at the below documentation? This should solve your problem of setting the environment variable every time.
https://in.mathworks.com/help/supportpkg/px4/ug/troubleshooting-px4-build-model-windows.html

dale

I met the same two issues
1、Unable to locate build tool "GNU PX4 Archiver": echo
I found a command to settle the problem temporarily

setenv('MW_PX4_WIN10_BUILDCMD', 'cmd /c start cmd /k "C:/Windows/Sysnative/bash.exe -cli "make $(CMAKEMAKECONFIG) " 2> MWPX4BuildLog.txt & echo MW_BUILD_COMPLETE >> MWPX4BuildLog.txt " ')

you should run the command everytime before you want to build the simulink model,but,anyhow,this method solved my problem.
2.Unable to connect to the 'PX4 Pixhawk 1' target
i have not solve the problem yet.

when i was trying to solve the first problem,i found the command line in the file“C:\ProgramData\MATLAB\SupportPackages\R2018b\toolbox\target\supportpackages\px4\+codertarget\+pixhawk\+internal\setupBuildEnvironment.m”

i read the code ,and i found that there might be something wrong.

i tried every possible setenv('MW_PX4_WIN10_BUILDCMD',‘string’) command in the file to test which is the correct one,
finally i found that only the command i mentioned above is appropriate

Here comes the problem:
my windows version is 18362(i got the windows version after i ran the command “codertarget.pixhawk.internal.getWindows10Version()”),
i also checked getpref('MW_PX4_WindowsToolchain','UseCygwin') command the result is 0
so the 'setenv' command i might get at last is
"setenv('MW_PX4_WIN10_BUILDCMD', 'C:/Windows/Sysnative/bash.exe -cli "make $(CMAKEMAKECONFIG) "') ;"
or
"setenv('MW_PX4_WIN10_BUILDCMD', 'C:/Windows/System32/bash.exe -cli "make $(CMAKEMAKECONFIG) "') ;"
however ,i tried the two command above but they didn't work.

so i guess there might be something wrong in the way we set the MW_PX4_WIN10_BUILDCMD.

Ankur Bose

Hi Daniel,
The mixers are usually defined in the PX4 Firmware for each airframe. In PX4 v1.8.0, the mixers are defined at https://github.com/PX4/Firmware/tree/v1.8.0/ROMFS/px4fmu_common/mixers
The mixer defined in motor_mixer in px4demo_attitudeSystem model is actually a MATLAB function for a hexacopter. If you want to bring a mixer for your airframe in MATLAB, create a MATLAB function for your mixer as listed in the above link.

Regarding the External MOde issue can you please confirm if you have completed the SD card step as described in hardware setup screens and your Pixhawk 1 has an SD card connected inside?

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

Greg Drayer

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