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 thegetColorImage
function to get color images off the TurtleBot to display them. To collect images at a fixed rate, userateControl
.
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 therateControl
object and start a loop to drive the robot in a circle for 10 seconds and capture images. In the loop, usesetVelocity
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)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 theColorImage
property of the robot, setActive
to false. You can also disconnect from the robot by callingclear
tbot
.
tbot.ColorImage.Active = false;
turtlebot
|getColorImage
|setVelocity
|rateControl
(Robotics System Toolbox)