matlab 机器人 地图,ROS与Matlab语言入门教程-从距离传感器更新占有网格地图

该例程演示如何使用距离传感器的数据创建或更新地图,以及如何使用Robotics System Toolbox™中的转换函数(如“quat2eul”和“axang2rotm”)。该例程根据距离传感器的读数和机器人的已知位姿创建地图。出于本例程的目的,距离传感器记录和机器人位姿作为消息存储于rosbag文件,该文件由Gazebo仿真器中的仿真机器人TurtleBot生成。Gazebo仿真器还发布了机器人的位置到“gazebo/model_states”话题上,这在本例程中将作为地面真实机器人位姿的来源。

从rosbag(记录文件)导入传感器记录和机器人位姿

使用“rosbag”函数,根据已有的ROS包文件,创建一个“robotics.ros.BagSelection”对象:

filePath = fullfile(fileparts(which('MapUpdateUsingSensorDataExample')), 'data', 'rosbagWithSensorData.bag');

bag = rosbag(filePath);

从rosbag文件提取机器人的位姿和激光扫描仪的数据,在本例中,使用了一个文件助手“exampleHelperReadPoseAndSensorMsgs”。

[poses, laserRanges] = exampleHelperReadPoseAndSensorMsgs(bag);

定义空地图

定义一个高分辨率的地图以精确地捕捉传感器的读数,此处创建一个大小为,精度为每米20个网格的地图。

map = robotics.BinaryOccupancyGrid(16,16,20)

map =

BinaryOccupancyGrid with properties:

GridSize: [320 320]

Resolution: 20

XWorldLimits: [0 16]

YWorldLimits: [0 16]

GridLocationInWorld: [0 0]

定义原点作为地图的中心,当前,世界的限制是X和Y坐标的0到16米。设置左下角的网格为[-8,-8],以转换世界的原点为网格的中心。新的世界限制将是X和Y坐标的-8米到8米。

map.GridLocationInWorld = [-8 -8]

map =

BinaryOccupancyGrid with properties:

GridSize: [320 320]

Resolution: 20

XWorldLimits: [-8 8]

YWorldLimits: [-8 8]

GridLocationInWorld: [-8 -8]

显示空地图和它的边界:

show(map)

571e87a4163725d8dd10b944c610c177.png

基于传感器记录跟新地图

距离传感器用于探测障碍物,这可用于更新地图。传感器读数在机器人参考坐标系上,用户需要转换该读数到世界坐标系(即地图定义的坐标系)。为了转换机器人坐标系到世界坐标系,用户需要机器人的当前方向和位置,rosbag文件包含机器人位姿的记录。本例应用的rosbag文件,在机器人围绕原点旋转扫描环境过程中获取。因此,本例程中,用户只需要使用机器人的当前方向将传感器的读数从机器人坐标系旋转到世界坐标系中。

% Loop over all the messages

for j=1:length(poses)

% Define the Quaternion in a vector form

q = [poses{j}.Orientation.W poses{j}.Orientation.X poses{j}.Orientation.Y poses{j}.Orientation.Z];

% Convert the Quaternion into Euler angles

orientation = quat2eul(q, 'ZYX');

% The z-direction rotation component is the heading of the

% robot. Use the heading value along with the z-rotation axis to define

% the rotation matrix

rotMatrixAlongZ = axang2rotm([0 0 1 orientation(1)]);

% Convert sensor values (originally in the robot's frame) into the

% world coordinate frame. This is a 2D coordinate transformation, so

% only the first two rows and columns are used from the rotation matrix.

rangesInWorldFrame = rotMatrixAlongZ(1:2,1:2) * laserRanges{j}';

% Update map based on laser scan data in the world coordinate frame.

% Populate the map, using the setOccupancy function, by setting the

% obstacle location on the map as occupied for every sensor reading that

% detects obstacles

setOccupancy(map, rangesInWorldFrame', 1);

end

显示更新的地图,此时包含了所有传感器的读数。

show(map)

60acedf39bfa634afc6bba7de5659eb9.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值