Main Content

Connecting to NSH Terminal for Debugging

After you deploy the model created using UAV Toolbox Support Package for PX4® Autopilots, you can use the NSH terminal for the debugging of Pixhawk® Series controllers.

NSH is accessed using MAVLink. Therefore, ensure that MAVLink is enabled over USB (for details, see Enabling MAVLink in PX4 Over USB).

Note

If you enable MAVLink over USB (/dev/ttyACM0), then you cannot use the External mode over USB. You can choose any other serial port (for example, /dev/ttyS6) to run the Simulink® model in External mode. However, in this case, you may need additional serial to USB convertor.

Accessing NSH from MATLAB

UAV Toolbox Support Package for PX4 Autopilots provides a pre-defined class named HelperPX4 that helps you to access NSH and perform certain actions.

Find the serial port on the host computer to which the PX4 Autopilot is currently connected and create a HelperPX4 object to access NSH. For example:

shellObj = HelperPX4('COM9');
Here COM9 value is used as an example. Change it to the actual host serial port.

The HelperPX4 class provides different methods to send NSH commands and obtain response.

The system method helps you to send the commands to NSH and get the shell response. To see the list of available NSH commands under system method, use the help command:

[shellResp, status] = shellObj.system('help')
The status value 1 indicates a successful execution.

If the listener command is listed, you can use it in the system method to listen to any uORB topic. For example:

[shellResp, status] = shellObj.system('listener vehicle_status')

The getFile method helps you to get the fault log or any other file in the SD card mounted on the PX4 Autopilot target, without removing SD card from the target. To do this (for fault logs):

  1. See the list of fault logs available in the SD card using the system method:

    shellObj.system('ls /fs/microsd')

  2. Observe the log list and decide which log file you want to copy to the host computer. Get the file to host computer using the getFile method. For example:

    shellObj.getFile('/fs/microsd/fault_2019_10_24_10_49_04.log');

Tip

You can use the getFile method to edit the startup script rc.txt that you have copied to the SD card (for details about rc.txt, see Performing PX4 System Startup from SD Card). In this case, you can also use the putFile method to copy the modified startup script back to the SD card.

After you make all the changes, you can delete the HelperPX4 object that you created:

delete(shellObj);

Accessing NSH Using QGroundControl (QGC)

For accessing NSH using QGroundControl (QGC), refer to this link.