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:=192.168.0.106
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 = '192.168.0.103'; % IP address of MATLAB host PC rosIP = '192.168.0.103'; % IP address of ROS enabled machine setenv('ROS_IP',matlabIP); setenv('ROS_MASTER_URI',['http://' rosIP ':11311']);
Initialize MATLAB global node and connect to the existing ROS network.
rosinit;
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.
subplot(2,1,1) rgbImg = readImage(rgbImgSub.LatestMessage); imshow(rgbImg) title('Color Image') subplot(2,1,2) depthImg = readImage(depthImgSub.LatestMessage); imshow(depthImg,[0 4]) title('Depth Image') drawnow;
Shutdown the MATLAB global node.
rosshutdown;