Main Content

Connect to the Kinova Gen3 Robot and Initiate Required ROS Nodes to Acquire Image Data from Vision Sensor

Open the terminal from the catkin workspace containing ros_kortex ROS packages in the host computer or VM where ROS is installed. Execute the following command in the terminal to launch required ROS nodes. Also, replace the IP address of the robot based on the actual hardware setup. For more information on the roslaunch command, see GitHub page of KINOVA Robotics.

roslaunch kinova_vision kinova_vision.launch device:=

If the hardware setup and provided IP address are correct, a message 'The stream has started' displays on the terminal window for color and depth sensors.

Connect to the ROS Network

Set MATLAB® and ROS IP addresses in the environment variable. For more information on environment variables, see Connect to a ROS Network. Execute these commands sequentially in the MATLAB to connect to the existing ROS network.

matlabIP = ''; % IP address of MATLAB host PC
rosIP = '';    % IP address of ROS enabled machine
setenv('ROS_MASTER_URI',['http://' rosIP ':11311']); 

Initialize MATLAB global node and connect to the existing ROS network.


Create a subscriber for RGB and depth images.

rgbImgSub = rossubscriber('/camera/color/image_rect_color/compressed');
depthImgSub = rossubscriber('/camera/depth/image');

Read RGB and depth images and plot them in a single subplot.

rgbImg = readImage(rgbImgSub.LatestMessage); 
title('Color Image')
depthImg = readImage(depthImgSub.LatestMessage);
imshow(depthImg,[0 4])
title('Depth Image')

Shutdown the MATLAB global node.