Simulink ROS Kinetic Gazebo Turtlebot image always black

1 view (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:
rosinit('<master_ip>')
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) https://www.mathworks.com/help/robotics/ug/_mw_5e2d4386-0dfb-42f6-999a-0be47c23dc68.html 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:
https://www.mathworks.com/help/robotics/ref/readimageblock.html#output_argument_d119e68481
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.
Thanks
  3 Comments
Multiplexer
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:
/camera/depth/camera_info
/camera/depth/image_raw
/camera/depth/points
/camera/parameter_descriptions
/camera/parameter_updates
/camera/rgb/camera_info
/camera/rgb/image_raw
/camera/rgb/image_raw/compressed
/camera/rgb/image_raw/compressed/parameter_descriptions
/camera/rgb/image_raw/compressed/parameter_updates
/camera/rgb/image_raw/compressedDepth
/camera/rgb/image_raw/compressedDepth/parameter_descriptions
/camera/rgb/image_raw/compressedDepth/parameter_updates
/camera/rgb/image_raw/theora
/camera/rgb/image_raw/theora/parameter_descriptions
/camera/rgb/image_raw/theora/parameter_updates
/clock
/cmd_vel_mux/active
/cmd_vel_mux/input/navi
/cmd_vel_mux/input/safety_controller
/cmd_vel_mux/input/switch
/cmd_vel_mux/input/teleop
/cmd_vel_mux/parameter_descriptions
/cmd_vel_mux/parameter_updates
/depthimage_to_laserscan/parameter_descriptions
/depthimage_to_laserscan/parameter_updates
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/set_link_state
/gazebo/set_model_state
/joint_states
/laserscan_nodelet_manager/bond
/mobile_base/commands/motor_power
/mobile_base/commands/reset_odometry
/mobile_base/commands/velocity
/mobile_base/events/bumper
/mobile_base/events/cliff
/mobile_base/sensors/bumper_pointcloud
/mobile_base/sensors/core
/mobile_base/sensors/imu_data
/mobile_base_nodelet_manager/bond
/odom
/rosout
/rosout_agg
/scan
/tf
/tf_static
Also, switching encoding to 32FC1 in the documentation example https://www.mathworks.com/help/robotics/ug/_mw_5e2d4386-0dfb-42f6-999a-0be47c23dc68.html 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
Hi,
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.

Categories

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!