< >
Home » TurtleBot-Matlab教程 » Turtlebot与Matlab入门教程-打印里程计数据

Turtlebot与Matlab入门教程-打印里程计数据

说明:

  • 介绍如何在Turtlebot运动时从中获取、存储和显示里程数据

步骤:

在turtlebot端:

  • [turtlebot] 启动turtlebot
roslaunch turtlebot_bringup minimal.launch

在Matlab端:

  • 运行plot_turtlebot_odometry.m文件

  • 使用setvelocity,turtlebot将向前驱动2秒,并且会获取里程计数据

  • 循环运行20次,使得turtlebot慢慢前进

  • turtlebot停止前行,绘制里程计数据

  • 代码如下:

%Connect to Robot
ipaddress = '192.168.0.93'; % IP address of your robot
tb = turtlebot(ipaddress);

%Get Odometry Data
odom = getOdometry(tb);
resetOdometry(tb)
setVelocity(tb,0.5,'Time',2)
odom = getOdometry(tb)

%Plot Odometry Data Points
odomList = zeros(20,2);
resetOdometry(tb)
for i = 1:20
    odom = getOdometry(tb);
    odomList(i,:) = [odom.Position(1) odom.Position(2)];
        
    if i < 10
        setVelocity(tb,0.25,0.15)
    else
        setVelocity(tb,0.25,-0.15)
    end
    pause(1);
end
plot(odomList(:,1),odomList(:,2))
rosshutdown;

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: none