When launching any graphical application on NVIDIA Jetson using MATLAB, MATLAB needs to access the local Display server session.
To access the local Display server MATLAB requires two things:
- Setting the proper display environment using the $DISPLAY environment variable
- Using proper authentication information (xauth cookies)
To set up the two requirements, follow the below steps,
1. To get the display environment, on the Jetson board, in your shell, execute the command,
echo $DISPLAY
The command outputs the hostname (the machine where the Display server is running) followed by the display environment number, for example,
:1.0
The application must use the same display environment as the Jetson board. In the Simulink model, open the Configuration Parameters dialog. On the Hardware Implementation pane, in the Target Hardware Resources section, in the Build Options tab, set the Display model configuration parameter to the value output by your board, which for the example shown above is ‘1.0’.
This can also be done programmaticaly using the 'setDisplayEnvironment' method of the Hardware Object as shown in the below command,
hwobj = jetson('IPAddress','username','password');
hwobj.setDisplayEnvironment('1.0');
2. When you log in to the Jetson board, the environment variable $XAUTHORITY points to the file containing the authentication information required to access the local Display server. To view the contents of the $XAUTHORITY environment variable, use the below command:
echo $XAUTHORITY
If the output of the above command is different than '~/.Xauthority' which is what MATLAB expects, then the authentication files need to be merged using the below command:
xauth -f ~/.Xauthority merge $XAUTHORITY &> /dev/null
The authentication information updates every time the user logs in to the Jetson device hence, the above command should be run at each new login. To automate this, the above-mentioned command can be added to the end of the file ‘~/.profile’.
