如何在matlab中绘制障碍物,Turtlebot与Matlab入门教程-避开障碍物
說明:
如何使得Turtlebot向前移動并且當存在障礙物時改變其方向
步驟:
在turtlebot端:
[turtlebot] 啟動Turtlebot
roslaunch turtlebot_bringup minimal.launch
[turtlebot] 啟動雷達
roslaunch rplidar_ros rplidar.launch
在Matlab端:
運行avoiding_obstacles.m文件
運行循環以向前移動機器人并計算與機器人最近的障礙物。 當障礙物在distanceThreshold的界限內時,機器人轉動。 該循環在運行時間20秒后停止。
代碼如下:
rosshutdown
ipaddress = '192.168.0.14';
rosinit(ipaddress);
robot = rospublisher('/mobile_base/commands/velocity');
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
總結
以上是生活随笔為你收集整理的如何在matlab中绘制障碍物,Turtlebot与Matlab入门教程-避开障碍物的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python同心圆怎么运行_怎么用pyt
- 下一篇: bug分析报告模模版