turtlebot3-burger_150.png
turtlebot3-waffle-pi_150.png
turtlebot3-arm_150.png
walking-y2_150.png
turbot3-multi_150.png
turbot3-dl-ros1_150.png
turbot3-ai.png
turbot3-dl-ros2_150.png
turbot3-slam_150.png
turbot3-arm_150.png
turtlebot4-lite_150.png
turtlebot4-pro_150.png
turbot4-dl_150.png
turbot4-ai_150.png
aidriving-racebot_150.png
aidriving-autodrive_150.png
turtlebot-arm_150.png
openmanipulator-x_150.png
Home » Turtlebot3-Matlab教程 » Turtlebot3与Matlab入门教程-避开障碍物

Turtlebot3与Matlab入门教程-避开障碍物

纠错,疑问,交流: 请进入讨论区请点击进入页面,扫码加入微信群或Q群进行交流

获取最新文章: 扫一扫加入“创客智造”公众号

欢迎加入我们的turtlebot3交流群,微信扫描右侧二维码立即进群交流

群二维码

说明:

  • 如何使得Turtlebot3向前移动并且当存在障碍物时改变其方向

步骤:

在turtlebot3端:

  • [turtlebot3] 启动Turtlebot3
roslaunch turtlebot3_bringup turtlebot3_robot.launch

在Matlab端:

  • 运行avoiding_obstacles.m文件

  • 运行循环以向前移动机器人并计算与机器人最近的障碍物。 当障碍物在distanceThreshold的界限内时,机器人转动。 该循环在运行时间20秒后停止。

  • 代码如下:

rosshutdown
ipaddress = '192.168.0.93';
rosinit(ipaddress);
robot = rospublisher('/cmd_vel');
velmsg = rosmessage(robot);
laser = rossubscriber('/scan');
scan = receive(laser, 3);
figure;
plot(scan);

spinVelocity = 0.6;
forwardVelocity = 0.1;
backwardVelocity = -0.02
distanceThreshold = 0.6;

tic;
while toc < 20
    % Collect information from laser scan
    scan = receive(laser);
    plot(scan);
    data = readCartesian(scan);
    x = data(:,1);
    y = data(:,2);
    % Compute distance of the closest
    dist = sqrt(x.^2 + y.^2);
    minDist = min(dist);
    % Command robot action
    if minDist < distanceThreshold
        % If close to obstacle, back up slightly and spin
        velmsg.Angular.Z = spinVelocity;
        velmsg.Linear.X = backwardVelocity;
    else
        % Continue on forward path
        velmsg.Linear.X = forwardVelocity;
        velmsg.Angular.Z = 0;
    end
    send(robot,velmsg);
end

clear
rosshutdown

纠错,疑问,交流: 请进入讨论区请点击进入页面,扫码加入微信群或Q群进行交流

获取最新文章: 扫一扫加入“创客智造”公众号

欢迎加入我们的turtlebot3交流群,微信扫描右侧二维码立即进群交流

群二维码

标签: none