ROS 自定义地图加载和导航(turtlebot测试)

本文详细介绍了使用ROS与TurtleBot进行地图构建及自定义地图AMCL导航的过程,包括启动TurtleBot底盘、传感器、hector_slam、远程遥控、保存地图,以及解决地图显示不正确的常见问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、构建地图

  • 启动turtlebot底盘
roslaunch turtlebot_bringup minimal.launch 
  • 启动传感器(激光雷达和惯性导航)
roslaunch lms1xx LMS1xx.launch #启动激光雷达
  • 启动hector slam

roslaunch lms1xx hector_mapping_demo.launch

  • 启动远程遥控
roslaunch turtlebot_teleop keyboard_teleop.launch
  • 启动遥控xbox

    roslaunch turtlebot_teleop xbox360_teleop.launch
    ​
    ​
    #(1)<remap from="turtlebot_teleop_joystick/cmd_vel" #to="cmd_vel_mux/input/teleop"/>
    #(2) joy_node节点修改
    #<node pkg="joy" type="joy_node" name="joystick">
    #   <param name="dev" type="string" value="/dev/input/js0" />
    #   <param name="deadzone" value="0.12" />
    #  </node>
    
  • 保存地图

rosrun map_server map_saver -f ~/my_map

2、自定义地图amcl导航

  • 启动turtlebot底盘
roslaunch turtlebot_bringup minimal.launch
  • 启动激光雷达
roslaunch turtlebot_navigation lms1xx.launch 
  • 启动amcl导航

roslaunch turtlebot_navigation lab_amcl_nomap.launch #不带加载地图,单独加载

 

  • 加载地图

rosrun map_server map_server my_map.yaml

  • rviz查看

    roslaunch turtlebot_navigation view_robot.launch 

     

3、问题

  • (1)地图显示不正确

打开yaml文件

image: my_map.png
resolution: 0.050000
origin: [-51.224998, -51.224998, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196

注意:

图像像素值[0-255].

  • If negate is false, p = (255 - x) / 255.0. This means that black (0) now has the highest value (1.0) and white (255) has the lowest (0.0).

  • If negate is true, p = x / 255.0. This is the non-standard interpretation of images, which is why it is called negate, even though the math indicates that x is not negated. Nomenclature is hard.

一般negate为0。

p = (255 - x) / 255.0

  • If p > occupied_thresh(0.65,换算为灰度值,约为90,也就是说像素小于90为占用(障碍物)), output the value 100 to indicate the cell is occupied.

  • If p < free_thresh(0.196,换算为灰度值,约为205,也就是说像素大于205为空(自由空间站)), output the value 0 to indicate the cell is free.

  • Otherwise, output -1 a.k.a. 255 (as an unsigned char), to indicate that the cell is unknown.

我通过hector保存的图像自由空间的值为200,显示为障碍物,所以出现上面图像错误。

### ROS2 TurtleBot 安装教程 #### 准备工作环境 为了确保能够顺利安装并运行TurtleBot3,在开始之前需确认已正确设置了ROS2的工作空间。这通常涉及到创建一个Catkin工作区,并编译任何自定义包或依赖项。 对于TurtleBot3而言,初始化命令如下所示[^1]: ```bash source ~/catkin_ws/devel/setup.bash rosrun turtlebot3_bringup bringupMinimal.sh ``` 上述指令会加载必要的环境变量并将启动最小化的bringup节点集来使机器人上线。 #### 安装过程详解 按照官方文档指引完成硬件连接之后,接下来就是软件层面的操作了。这里假设读者已经具备一定的Linux操作技能以及对ROS有一定了解。具体步骤包括但不限于: - 更新系统软件源列表; - 添加Fast-RTPSRTI Connext DDS的密钥及仓库地址到APT中以便后续安装DDS实现; - 下载并安装ROS 2 Foxy Fitzroy版本; - 构建个人开发所需的额外功能包集合; 以上准备工作完成后,则可以继续针对特定型号(TB3-Burger, TB3-Waffle等)下载对应的固件文件并通过USB线缆刷入底板控制器内。 #### 使用指南概览 一旦成功部署好整个平台后,便可以通过多种方式操控TurtleBot3移动或是获取传感器数据流。例如利用`teleop_twist_keyboard`包来进行键盘遥控驾驶测试,或者订阅激光雷达话题查看周围障碍物分布情况。 另外值得注意的是,由于采用了新的中间件技术栈——eProsima Fast RTPS作为默认传输层协议,因此在网络设置方面可能需要做适当调整以适应不同场景下的通讯需求。 #### 示例代码展示 下面给出一段简单的Python脚本用于发布速度指令给TurtleBot3使其沿直线前进一段时间后再停止: ```python import rclpy from geometry_msgs.msg import Twist def main(args=None): rclpy.init(args=args) node = rclpy.create_node('move_forward') publisher = node.create_publisher(Twist, 'cmd_vel', 10) msg = Twist() duration = 5 try: end_time = rclpy.time.Time() + rclpy.duration.Duration(seconds=duration) while rclpy.ok() and rclpy.time.Time.now() < end_time: msg.linear.x = 0.2 publisher.publish(msg) # Stop the robot after moving forward msg.linear.x = 0.0 publisher.publish(msg) finally: node.destroy_node() rclpy.shutdown() if __name__ == '__main__': main() ``` 此段代码展示了如何通过ROS2接口向TurtleBot发送运动控制消息,实现了让其向前行驶指定秒数的功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值