主要内容

跟踪并关注对象Using aTurtleBot

This example shows how to track an object based on color using a TurtleBot®通过ROS网络连接的机器人。ROS工具箱支持包,用于金宝app基于海龟机器人的机器人使您能够捕获图像在环境中找到对象,并发送速度命令以导航到对象。要遵循对象,您使用getColorImagesetVelocityfunctions along with image processing techniques.

连接到机器人

使用其特定的IP地址连接到Turtlebot机器人。您的模拟或真正的海龟机器人必须与运行MATLAB的计算机在同一ROS网络上®.

ipaddress ='192.168.1.10';% IP address of your robottb = turtlebot(ipaddress);

Track Object

To detect the example object, a blue ball, you must specify some of its properties. You use these properties to process the images you capture. This example uses Image Processing Toolbox™ to run color and blob detection algorithms on each image to find the ball.

指定显示的球的属性,代替为环境调整的值。给出的值对于详细介绍的凉亭仿真是最佳的开始使用凉亭和模拟海龟机器人.

blueballparams.bluemax = 120;% Maximum permissible deviation from pure blue蓝球.darkMin = 30;%最低可接受的黑暗价值

Get an image off the TurtleBot.

最新img = getColorimage(tbot);

Use these two example helper functions to get and plot the location of the ball in the image. These functions use地区企业from Image Processing Toolbox to get the location and size of the ball. The first image is the output from the TurtleBot with the object location overlaid on it. The second image is the binary image,ballImage,用于基于图像中的蓝色蓝球. If the ball does not show up as white with limited background in this binary image, try tuning the蓝球values.

[位置,〜,ballimage] = examplehelperturtlebotfindblueball(最新IMG,blueballparams);examplehelperturtlebotplotobject(最新IMG,BALLIMAGE,位置);

Follow Object Using Velocity Commands

After you tune the tracking of the object in the image, you can set up a basic control algorithm for sending commands to the TurtleBot. This example uses basic logic with singular linear and angular velocity commands to get the robot to follow the ball. For a more advanced control scheme, see跟踪并关注对象.

Get a new image and store the image size. Recalculate the position and size of the object.

最新img = getColorimage(tbot);[高度,宽度] = size(最新IMG);[position,~] = exampleHelperTurtleBotFindBlueBall(latestImg,blueBallParams);

Generate angular and linear velocities based on the position and size of the ball. If no object is found, spin and search for the ball (positive angular velocity only).

  • If the ball is on the far left side of the screen, the robot needs to turn left (positive angular velocity). The same is true for the right side (negative angular velocity).

  • If the ball is too small in the image, the robot must move closer (positive linear velocity). If the ball is too large, the robot must move farther away (negative linear velocity).

最后,使用使用线性和角速度setVelocity暂停等待命令发送。迭代100个循环以测试跟踪。

球位置和大小的%参数Horizo​​ntalTolerance = 20;sizegoal = 70;sizetolerance = 5;fori = 1:100% Get latest image, ball postion, and ball size.最新img = getColorimage(tbot);[高度,宽度] = size(最新IMG);[位置,ballsize] = examplehelperturtlebotfindblueball(最新IMG,blueballparams);%将速度初始化为零。线性= 0;angularVel = 0;%左右控件ifISEMPTY(位置)Angularvel = 0.5;线性= 0;elseif(位置(1)>(宽度/2)-Horizo​​ntalTolerance)Angular = 0.2;elseif(position(1) < (width/2)+horizontalTolerance) angularVel = -0.2;end% Forward and back controlifisempty(ballsize)Angularvel = 0.5;线性= 0;elseifballSize > sizeGoal + sizeTolerance linearVel = - 0.1;elseifballSize < sizeGoal - sizeTolerance linearVel = 0.1;end%发送速度命令并等待命令发送。固定性(TBOT,线性,角度)暂停(0.2)end

To verify the algorithm is successful, capture an image and use the help functions to track and plot the position once more. The TurtleBot focuses on the ball, assuming it found the ball during its search. Based on the Gazebo simulated world in this example, a final image capture shows the ball right in front of the robot.

最新img = getColorimage(tbot);[c,ballsize,ballimage] = examplehelperturtlebotfindblueball(最新IMG,blueballparams);examplehelperturtlebotplotobject(最新IMG,Ballimage,c);

Improvement Suggestions

This example uses simple sensor feedback and control parameters for tracking and following an object. It works well in a simulated environment due to its low level of risk to hardware and real environments. However, it does not factor in the bump or clip sensors, which can help with collisions or terrain changes. Dynamically adjusting the velocity commands and factoring in previous states can improve the movements of the TurtleBot.

为了改善现实世界应用程序的示例,请考虑使用更高级的传感和控制方法对具有更强大处理传感器数据的真实机器人进行控制。看跟踪并关注对象对于使用PID控制器和其他机器人传感器的更高级示例。

看Also

||

相关话题