PX4 Matlab External Mode Test

Hey all,

I have one more question about the external mode when I use the telemetry to establish the connection.
I have telemetry 1 connect to my PC at COM6,

and telemetry 2 connect to Pixhawk at TELE2(aka Serial 1) which is /dev/ttys1. So in the rc.txt, I set the following command:

px4_simulink_app start #disable automatic starting up of the model
nshterm /dev/ttyS1 & #this will make ttyS1 the serial console

and in the Simulink code generation mex -file augment: 1 6 57600 5

and in the target hardware resource, the Data Exchange Serial Port is ttyACM0, baud rate is 57600

But when I tried to connect the target, it failed. The error message is

Error occurred while executing External Mode MEX-file ‘ext_serial_win32_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.

Even when I tried to connect the PC with PX4 with the FTDI cable, same error occurred.

Anything wrong here?

Hello! @Amynannan

have you had problem using normal mode?

Hey Mario, thanks for your replying.

Yes the normal mode works fine, and I have fixed the external problem. It is the serial console problem. The telemetry 2 should connect to serial 4/5 on pixhawk, and the Data Exchange Serial Port should be ttyS6

Thanks for replying, @Amynannan

I am currently studying the modules mc_att_control and mc_pos_control, I want to design a controller, matlab was an option but when I compiled the example px4demo_attitude_system.slx, my pixhawk did not work properly, the lpe modules and attitude estimator disappeared, I need those modules because my pixhawk uses a mocap system.

Why did I get that error?

I think it’s due to the reboot system

Did you run it under normal mode or external mode? If it is running under normal mode, then the problem may come from the psp installation. You might want to re-install PSP and following the official guideline (Pixhawk Pilot Support Package User Guide)


I was running normal mode.

Ok I will re-install PSP. Did you install PSP in windows or linux?

hello Amynannan

could you please share the file rc.txt for the external mode, and please make some explanation on the connection : which port go to which port?