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, you use
rateControl (Robotics System Toolbox).
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®.
ipaddress = '192.168.1.10'; % IP address of your robot tbot = turtlebot(ipaddress);
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 a Simulated TurtleBot.
img = getColorImage(tbot); imshow(img)
rateControl object to control the execution rate of
code. The desired rate is 2 Hz.
desiredRate = 2; rate = rateControl(desiredRate);
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.
reset(rate) for i = 1:20 setVelocity(tb,0.1,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 the
of the robot, set
You can also disconnect from the robot by calling
tbot.ColorImage.Active = false;