Simulink ROS Kinetic Gazebo Turtlebot image always black

8 views (last 30 days)
Hello, I want to use Simulink to display image from virtual Turtlebot camera inside Gazebo environment. I use ROS Kinetic on Ubuntu 16.04 and Gazebo 7.9 with Turtlebot model (i launch it with roslaunch turtlebot_gazebo turtlebot_world.launch)
I have all my ROS environment running and configured correctly. I can connect Matlab/Simulink to ROS without any issue. I start ros master on the Ubuntu machine then in matlab i type:
d = rosdevice
and i see all my ROS information, i configured everything in Simulink and everything works as intended, i can type
rostopic list
in Matlab and it matches what i see in Ubuntu with ROS, i can run a Simulink model that sends messages to topic /mobile_base/commands/velocity and Turtlebot inside Gazebo reacts to commands, all perfect.
The issue starts when I'm trying to display in Simulink image from camera by subscribing to /camera/rgb/image_raw topic. The displayed image is all black and block "Read Image" shows error code 1.
I checked in Ubuntu/ROS the image using rosrun image_view image_view image:=/camera/rgb/image_raw/ and it shows correct image all right.
I thought maybe something is wrong with my model so i decided to do this example step by step, exactly as described (including the step where i set max array size to be greater than 921,600 pixels) and yet in the end the image output is also all black.
Help will be appreciated.

Answers (1)

MathWorks Robotics and Autonomous Systems Team
As mentioned by you, you are noticing an error code of 1, as per documentation:
ErrorCode 1 means, wrong image encoding set on the block.
Double-click the block icon in your model > then select the topics using a separate window from the Block mask by clicking on "Configure using ROS ..."
This displays a list of image/ compressed image topics on your ROS network, and then when you select the topic, it auto-updates the image encoding setting on the block.
Confirm the image encoding, on your Linux machine, on the topic by printing the "rostopic info /camera/rgb/image_raw/encoding"
For e.g.,
user@ubuntu:~/Documents$ rostopic echo -n 1 /camera/depth/image_raw/encoding 32FC1 ---
Which means, in the ReadImage block the encoding needs to be 32FC1 to be able to process it correctly.
Using the "Configure using ROS ..." will help you pick the topic and encoding in one go.
Multiplexer on 7 Dec 2017
Edited: Multiplexer on 7 Dec 2017
I just switched encoding to 32FC1 and issue still persists.
Additionally, there is no /camera/depth/image_raw/encoding nor /camera/rgb/image_raw/encoding
This is list of topics on my ubuntu machine with ROS:
Also, switching encoding to 32FC1 in the documentation example did not solve the issue either, in there, doing instructions step by step, the video output is also all black.
And the "Configure using ROS" option displays this but its not active and cant select anything attachment
deelaka dheeraratne
deelaka dheeraratne on 3 Mar 2020
I had the same issue my image came out black when using Simulink ReadImage block and I found out that the length of the data given out from the ROS image topic was limited to 128 in Simulink. This was because under the simulation tab, the VariableSize Messages the maximum length was set to 128. I increased it to the length of the RGB image HxWx3 and it worked it’s worth checking this.

Sign in to comment.


Find more on Network Connection and Exploration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!