Stream Images from NVIDIA Jetson Xavier NX using Robot Operating System (ROS)
This example shows you how to stream images captured from a webcam on NVIDIA Jetson Xavier NX board to the host computer using ROS communication interface.
Target Board Requirements
NVIDIA Jetson Xavier NX embedded board.
Ethernet crossover cable to connect the target board and host PC (if you cannot connect the target board to a local network).
Install the ROS package on the board For more information, see Install and Set Up ROS Package on NVIDIA Hardware.
A compatible Webcam
Review the Get Started with ROS example
Review the Get Started with ROS in Simulink® example.
Task 1 - Connect to NVIDIA Jetson Xavier NX
The support package uses an SSH connection over TCP/IP to execute commands on the NVIDIA Jetson Xavier NX. Connect the target platform to the same network as the host computer or use an Ethernet crossover cable to connect the board directly to the host computer. For information on how to set up and configure your board, see NVIDIA documentation.
To communicate with the NVIDIA hardware, create a live hardware connection object by using the
jetson function. You must know the host name or IP address, user name, and password of the target board to create a live hardware connection object. For example, when connecting to the target board for the first time, create a live object for Jetson hardware by using the command:
hwobj = jetson('jetson-xaviernx-name','ubuntu','ubuntu');
Task 2 - Connect Camera
Connect the USB camera to one of the USB ports on your NVIDIA Jetson Xavier NX.
Check if the camera is recognized by the Linux kernel by running the the following command on the MATLAB prompt:
Typical output will be:
Camera Name Video Device Available Resolutions ___________________ _____________ _____________________
"HP Webcam HD 4310" "/dev/video0" "(View resolutions)"
Task 3 - Configure and Run the Simulink Model
In this task you will create a ROS node publishing images captured from the camera attached to your NVIDIA Jetson Xavier NX.
1. Open the Publish Images Captured from a Webcam to /camera topic model.
2. Make sure that the camera name you determined in Task 1 matches to the 'Name' parameter specified on the Camera block mask. In this example, the 'Name' should be set to
'HP Webcam HD 4310' as it is the only available camera on the board.
3. Open the Modeling tab or press Ctrl+E to open Configuration Parameters dialog box. Go to Hardware Implementation > Hardware board and select Robot Operating System (ROS).
4. Go to ROS tab in the model and click on the
Deploy to drop-down list. Select
Manage Remote Device. Enter the Device address, Username and Password. Provide the ROS installation folder in the
ROS folder and the catkin workspace folder in
5. Start a ROS master on the host computer:
rosinit('NodeHost',<IP address of your computer>)
For example, if the IP address of your host computer is 10.10.10.2, use the following command:
6. In the model, click the Build & Run button on the toolbar to automatically generate a ROS node and run it on the NVIDIA Jetson Xavier NX.
NOTE The Publish Images Captured from a Webcam to /camera topic publishes the captured image at a relatively small size of 320x240 to keep network latency to a minimum when viewing images on the host computer. You can increase the image size and publish the image by modifying the Simulink model. Note however that this will usually introduce additional delay and use more CPU resources on the NVIDIA Jetson Xavier NX.
Task 4 - Verify the ROS Node
In this task, you verify the behavior of the newly-built ROS node using the MATLAB command line interface for ROS.
1. Publish Images Captured from a Webcam to /camera topic model publishes messages on the
/camera topic using
sensor_msgs/Image message. First, verify that a new topic called
/camera has been generated:
rostopic info /camera
You should see the IP address of your NVIDIA Jetson Xavier NX in the publishers list.
2. Create a ROS subscriber for the
s = rossubscriber('/camera')
std_msgs/Image message type to represent black and white images captured from a camera attached to NVIDIA Jetson board.
3. Create a callback function attached to the subscriber
s to automatically display images on your host computer as they are published by the NVIDIA Jetson Xavier NX:
s.NewMessageFcn = @(~,msg) imagesc(reshape(msg.Data,[240,320,3]));
As soon as you execute the command above, you should see a figure window pop-up displaying images published from NVIDIA Jetson Xavier NX.
4. To stop streaming images, execute the following on the MATLAB prompt:
Task 5 - Display Published Images Using Simulink
In this task, you will perform the same task as in Task 3 but this time using Simulink ROS Subscriber blocks.
1. Clear the ROS subscriber you created in Task 3:
2. Open the Receive Images from /camera topic model. Click on Play. Observe that images sent from NVIDIA Jetson Xavier NX is displayed on the SDL Video Display window. Also note that the image width, height and sequence number are displayed on the Simulink model.
This example showed you how to send images captured from a camera attached to NVIDIA Jetson Xavier NX to the host computer using ROS messaging interface.