%% Read A ROS Image Message In Simulink(R)
% This example requires Computer Vision Toolbox(R) and Robotics 
% System Toolbox(R).
%%
% Start a ROS network.
rosinit

%%
% Load sample messages to send including a sample image message, |img|. Create a 
% publisher to send a ROS |Image| message on the |'/image_test'| topic.
% Specify the message type as |'/sensor_msgs/Image'|. Send the image
% message.
imgcell = load('imgdata.mat','img');
img = imgcell.img;
pub = rospublisher('/image_test','sensor_msgs/Image');
send(pub,img)
%%
% Open the Simulink(R) model for subscribing to the ROS message and reading 
% in the image from the ROS.
%
% Ensure that the |Subscribe| block is
% subscribing to the |'/image_test'| topic. In the menu under
% *Tools* > *Robot Operating System* > *Manage Array Lengths*, verify the
% |Data| array has a maximum length greater than the sample image (921,600
% pixels).


open_system('read_image_example_model.slx')


%%
% Run the model. The |Video Viewer| shows the sample image.
%%
%
% <<../read_image_video_viewer.png>>
%
%%
% Stop the simulation and shut down the ROS network.
rosshutdown



%% 
% Copyright 2012 The MathWorks, Inc.