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).
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
/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
object to access NSH. For
shellObj = HelperPX4('COM9');
COM9value is used as an example. Change it to the actual host serial port.
HelperPX4 class provides different methods to send NSH commands
and obtain response.
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
[shellResp, status] = shellObj.system('help')
statusvalue 1 indicates a successful execution.
listener command is listed, you can use it in the
system method to listen to any uORB topic. For
[shellResp, status] = shellObj.system('listener vehicle_status')
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):
See the list of fault logs available in the SD card using the
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
getFilemethod. For example:
You can use the
getFile method to edit the startup script
rc.txt that you have copied to the SD card (for
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
Accessing NSH Using QGroundControl (QGC)
For accessing NSH using QGroundControl (QGC), refer to this link.