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 Robotsenables you to connect to TurtleBot hardware and get the color, grayscale, and depth images from it. In this example, use thegetColorImagefunction to get color images off the TurtleBot to display them. To collect images at a fixed rate, userateControl.

连接到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 ='192.168.192.130';% IP address of your robottbot = 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, seeGet Started with Gazebo and a Simulated TurtleBot.

img = getColorImage(tbot); imshow(img)

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

desiredRate = 2; rate = rateControl(desiredRate);

Reset therateControlobject and start a loop to drive the robot in a circle for 10 seconds and capture images. In the loop, usesetVelocityto 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.

reset(rate)fori = 1:20 setVelocity(tbot,0.01,0.5) img = getColorImage(tbot,0); imshow(img) waitfor(rate);end

To save bandwidth on the network, disable the image subscriber now that it is no longer in use. On theColorImageproperty of the robot, setActiveto false. You can also disconnect from the robot by callingcleartbot.

tbot.ColorImage.Active = false;

See Also

|||(Robotics System Toolbox)

Related Topics