Main Content

Get Image Data from TurtleBot at a Fixed Rate

This example shows how to get image data from the TurtleBot and display it at a fixed rate. ROS Toolbox Support Package for TurtleBot-Based Robots enables you to connect to TurtleBot hardware and get the color, grayscale, and depth images from it. In this example, use the getColorImage function to get color images off the TurtleBot to display them. To collect images at a fixed rate, use rateControl.

Connect to TurtleBot

Connect to your TurtleBot robot using its specific IP address. Your simulated or real TurtleBot must be on the same ROS network as the computer running MATLAB™. Specify the command velocity topic name.

ipaddress = ''; % IP address of your robot
tbot = turtlebot(ipaddress,11311);
tbot.Velocity.TopicName = '/cmd_vel';

Get the latest image from the TurtleBot and show it in a figure. This TurtleBot is simulated in Gazebo. For more information on the Gazebo simulator, see Get Started with Gazebo and Simulated TurtleBot.

img = getColorImage(tbot);

Create a rateControl object to control the execution rate of code. The desired rate is 2 Hz.

desiredRate = 2;
rate = rateControl(desiredRate);

Reset the rateControl object and start a loop to drive the robot in a circle for 10 seconds and capture images. In the loop, use setVelocity to command a linear and angular velocity of 0.1 m/s and 0.5 rad/s respectively. Then capture the latest image and display it. Wait for the desired rate at the end of each loop. The image shown is the final image after the 10 turns.

for i = 1:20
	img = getColorImage(tbot,0);

To save bandwidth on the network, disable the image subscriber now that it is no longer in use. On the ColorImage property of the robot, set Active to false. You can also disconnect from the robot by calling clear tbot.

tbot.ColorImage.Active = false;

See Also

| | | (Robotics System Toolbox)

Related Topics