Main Content


Get color image from TurtleBot camera

Add-On Required: This feature requires the ROS Toolbox Support Package for TurtleBot-Based Robots add-on.



colorImg = getColorImage(tbot) waits for the next published color image message from the TurtleBot® connected through the interface object, tbot, and returns the image. If no message is received in five seconds, the function displays an error.

[colorImg,colorImgMsg] = getColorImage(tbot) also returns the received ROS image message.

[___] = getColorImage(tbot,timeout) waits for the next image for timeout seconds. If no new message is received in that time, the function displays an error. A timeout of zero returns the latest received message without waiting. If no message has been received, the function returns an empty matrix for colorImg and an empty message for colorImgMsg, if specified.


collapse all

Connect to the TurtleBot robot. Change '' to the IP address of the robot.

tbot = turtlebot('');

Get the latest color image from the TurtleBot.

colorImg = getColorImage(tb);

Input Arguments

collapse all

TurtleBot interface object, specified as a turtlebot object. The object contains properties for activating subscribers and accessing topic names relevant to the TurtleBot. The properties contain the topic name and active status of different subscribers for the TurtleBot. When you create the object with turtlebot, the properties available are:

tbot = turtlebot
tbot = 

  turtlebot with properties:

           Velocity: [1x1 struct]
         ColorImage: [1x1 struct]
          GrayImage: [1x1 struct]
         DepthImage: [1x1 struct]
         PointCloud: [1x1 struct]
          LaserScan: [1x1 struct]
           Odometry: [1x1 struct]
      OdometryReset: [1x1 struct]
                IMU: [1x1 struct]
    TransformFrames: {0x1 cell}
         TopicNames: {3x1 cell}

For properties with relevant ROS data messages, you can view the topic name and a subscriber’s active status. A specific subscriber is active for the given TopicName if Active equals 1.

ans = 

    TopicName: '/mobile_base/commands/velocity'
       Active: 1

Timeout for receiving an image, specified as a scalar in seconds. The function returns an error after timeout seconds. If timeout equals zero, the function returns the latest image. If the TurtleBot has no latest message, the function returns a blank image and blank image message.

Output Arguments

collapse all

Color image, returned as a matrix representing an RGB image or as an m-by-n-by-3 array, depending on the sensor image.

'sensor_msgs/Image' or 'sensor_msgs/CompressedImage' ROS image message, returned as an Image or CompressedImage object handle.

Version History

Introduced in R2016a