一文安装配置cartographer,gazebo中跑cartographer建图 & 导航

解决问题思维

  1. 明确自己想要的(编译安装cartographer);准备号基本的依赖环境确认版本直接编译即可(出错时,根据报错,缺什么解决什么即可)
  2. (github加速,非必须)如果有梯子,在终端运行该命令可以让终端走代理,使得github拉项目十倍速以上(最后的ip端口填写自己代理的ip端口即可,此处是在本机开的代理):git config --global http.proxy http://domain.local\vsilva:Passw0rd@127.0.0.1:7890

最简单方式——直接使用该脚本安装即可,想要看看详细的可以看后续的配置安装过程

#!/bin/bash
echo "delete cartographer_ws..."
sudo rm -rf ~/cartographer_ws/
mkdir -p ~/cartographer_ws/src 
echo "add git proxy..."
read -p "please enter http_proxy addr and its port(eg. 127.0.0.1:7890):" HTTP_PROXY
git config --global http.proxy http://domain.local\vsilva:Passw0rd@$HTTP_PROXY

cd ~/cartographer_ws/src && git clone https://github.com/googlecartographer/cartographer_ros.git && git clone https://github.com/googlecartographer/cartographer.git

echo "install deps..."
sudo apt install -y  libgflags-dev libgoogle-glog-dev liblua5.2-dev libsuitesparse-dev ninja-build stow 

echo "install ceres-1.14.0..."
cd ~/cartographer_ws/ && git clone https://github.com/ceres-solver/ceres-solver.git && cd ceres-solver/ && git checkout 1.14.0 && mkdir build && cd build && cmake .. && make -j$proc && sudo make install


echo "install abseil.."
bash ~/cartographer_ws/src/cartographer/scripts/install_abseil.sh 

echo "make cartographer.." 
cd  ~/cartographer_ws/ && catkin_make_isolated --install --use-ninja 
source install_isolated/setup.bash

一. 配置安装Cartographer

  1. 安装基本依赖库(默认大家均已安装ROS、Cmake)

sudo apt-get update &&
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblua5.2-dev libsuitesparse-dev

  1. 创建catkin_ws拉取相关项目功能包(以下工作空间可以自己选,此处是code/ws/slam下创建)

cd ~/code/ws && mkdir -p slam/cartographer_ws/src && cd ~/code/ws/slam/cartographer_ws/src
git clone https://github.com/googlecartographer/cartographer.git && git clone https://github.com/googlecartographer/cartographer_ros.git

  1. 安装ceres-1.14.0

cd ~/code/ws/slam/ && git clone https://github.com/ceres-solver/ceres-solver.git
cd ceres-solver && git checkout 1.14.0
mkdir build && cd build && cmake … && make -j$proc && sudo make install

  1. 安装absl(使用cartographer下的脚本安装即可)

sudo apt-get install stow -y
cd ~/code/ws/slam/cartographer_ws/src/cartographer/scripts && ./install_abseil.sh

  1. 安装protobuf-3.6.1(版本过高会报错)
  2. 直接编译即可,遇到错再说(只要依赖库版本没有问题就不会出错)

cd ~/code/ws/slam/cartographer_ws/
catkin_make_isolated -DPYTHON_EXECUTABLE=/usr/bin/python3
ps.上面这句指定python3编译只在装了conda时候用即可,未装则可不指定

  1. 成功安装(核心:找对依赖库版本)

  2. 使用官方数据包测试

source devel_isolated/setup.bash
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag

二. 在gazebo仿真环境中使用cartographer算法建图并在建好的地图导航

  1. 编译cartographer(见教程一)

  2. 下载turtlebot并编译:

  • cd ~/code/ws/slam/cartographer_ws/src
  • git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
  • git clone https://github.com/ROBOTIS-GIT/turtlebot3.git
  • git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
  • cd …
  • catkin_make_isolated -DPYTHON_EXECUTABLE=/usr/bin/python3
  1. 设置环境变量:
  • echo “export TURTLEBOT3_MODEL=burger” >> ~/.bashrc
  • source ~/.bashrc
  • source /devel_isolated/setup.bash
  1. 修改launch文件
  • catkin_ws/src/turtlebot3/turtlebot3_slam/launch/turtlebot3_cartographer.launch文件,把$(arg configuration_basename)更改为turtlebot3_lds_2d_gazebo.lua
  1. 打开仿真gazebo仿真环境:
  • source devel_isolated/setup.bash
  • roslaunch turtlebot3_gazebo turtlebot3_world.launch
  1. 使用cartographer算法建图
  • roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer
  1. 使用键盘控制Turtlebot3运动
  • source devel_isolated/setup.bash
  • roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
  1. 保存地图
  • rosrun map_server map_saver -f ~/map
  1. 点击2D Nav Goal,设置目标点,导航

参考教程

SUM:

  1. 遇到一些版本不符,只是API名称的一个改变什么的,切换版本不行的话,最简答的办法是直接修改源代码和当前版本契合即可。
### 关于CartographerGazebo仿真环境中TF数据重复的问题 在Gazebo仿真环境下使用Cartographer进行时,可能会遇到TF数据重复的问题。这种现象通常是由于多个节点发布了相同的TF变换信息所致[^1]。具体来说,在Gazebo中模拟机器人时,默认情况下,Gazebo插件会发布机器人的TF树,而Cartographer也会基于其配置文件独立生成并发布TF树的部分。如果两者发布的TF名称存在冲突,则会导致TF数据重复。 #### 解决方案 以下是针对该问题的些常见解决方案: 1. **修改Cartographer的TF发布设置** 在Cartographer配置文件(如`.lua`文件)中,可以通过调整参数来控制是否由Cartographer发布某些特定的TF变换。例如,禁用Cartographer对base_link或其他已由Gazebo发布的TF的重新定义。这可以在配置文件中通过如下代码实现: ```lua options = { map_frame = "map", tracking_frame = "base_footprint", -- 修改为不与Gazebo冲突的frame_id published_frame = "odom", -- 设置为Gazebo已有的frame_id use_odometry = true, provide_odom_frame = false, -- 不提供额外的odometry frame publish_frame_projected_to_2d = true, } ``` 2. **禁用Gazebo中的部分TF发布功能** 如果确认不需要Gazebo插件发布某些特定的TF变换,可以直接编辑Gazebo的世界文件或URDF/XACRO描述文件,移除不必要的插件模块。例如,关闭IMU传感器或激光雷达插件自动发布的TF信息。以下是个示例XACRO片段: ```xml <gazebo reference="laser"> <plugin name="gazebo_ros_laser" filename="libgazebo_ros_laser.so"> <!-- 移除此处的<tf_prefix>标签 --> </plugin> </gazebo> ``` 3. **统命名空间管理** 使用ROS命名空间隔离不同组件之间的TF树结构。例如,将整个Cartographer运行在个单独的命名空间下,从而避免与其他节点共享相同的名字前缀。启动脚本可以这样编写: ```bash roslaunch cartographer_ros my_carto.launch __ns:=/my_robot ``` 4. **调试工具辅助排查** 利用`rviz`和`tf_echo`命令行工具检查当前系统中存在的所有TF关系及其频率。例如: ```bash rosrun tf tf_echo /base_link /odom ``` 这有助于快速定位哪些节点正在广播冗余的数据流,并进步采取措施消除冲突。 5. **更新依赖版本兼容性** 确保所使用的Cartographer ROS包以及相关驱动程序均保持最新状态,因为旧版可能存在未修复的BUG引起此类异常行为。可通过APT仓库或者源码编译方式进行升级操作[^3]: ```bash sudo apt update && sudo apt upgrade ros-$ROS_DISTRO-cartographer-ros ``` ```python import rospy from geometry_msgs.msg import TransformStamped def check_tf_repetition(): """ 检查是否存在重复的TF """ try: rospy.init_node('check_tf', anonymous=True) rate = rospy.Rate(10) # 10 Hz while not rospy.is_shutdown(): tfs = rospy.get_published_topics('/tf') if len(tfs) > expected_count: # 替换expected_count为你期望的数量 print(f"Duplicated TF detected! Current count={len(tfs)}") rate.sleep() except Exception as e: print(e) if __name__ == '__main__': check_tf_repetition() ``` --- ###
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值