ubuntu 22.04安装ros2及nav2测试

安装ros2

参考鱼香ROS安装教程

// 换源,编辑/etc/apt/sources.list文件, 删除原有内容,将以下内容加入
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

// 更新
sudo apt-get update
sudo apt-get upgrade

// 添加源
echo "deb [arch=$(dpkg --print-architecture)] https://repo.huaweicloud.com/ros2/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
// 添加源对应的秘钥
sudo apt install curl gnupg2 -y
curl -s https://gitee.com/ohhuo/rosdistro/raw/master/ros.asc | sudo apt-key add -
// 更新
sudo apt update    
// 安装ROS2,上面步骤完成后,安装就变得非常的简单了,一行指令搞定;
sudo apt install ros-humble-desktop
// 安装额外依赖
sudo apt install python3-argcomplete -y
// 添加环境变量
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
// 补全colcon命令
echo "source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash" >> ~/.bashrc

安装Nav2

// 安装turtlebot3-gazebo
sudo apt install ros-humble-turtlebot3-gazebo
// 源码编译安装nav2
mkdir -p ~/nav2_ws/src
cd ~/nav2_ws/src
git clone https://github.com/ros-planning/navigation2.git -b humble
cd ..
// rosdepc install -r --from-paths src --ignore-src --rosdistro humble -y
// 自动安装依赖好像有点问题,采用手动安装的方式
sudo apt-get install ros-humble-bondcpp ros-humble-test-msgs ros-humble-behaviortree-cpp-v3 ros-humble-diagnostic-updater ros-humble-ompl
source ~/.bashrc
colcon build --symlink-install
echo "source ~/nav2_ws/install/setup.bash" >> ~/.bashrc
source ~/.bashrc
ros2 launch nav2_bringup tb3_simulation_launch.py headless:=False
// ps: 卸载ros2
sudo apt remove ros-humble-*
sudo apt autoremove

点击给出初始定位

然后就可以使用进行导航了。

nav2仿真建图测试

sudo apt-get install ros-humble-turtlebot3-teleop
// 启动仿真环境
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
// 启动nav2
ros2 launch nav2_bringup rviz_launch.py
// 启动SLAM
ros2 launch slam_toolbox online_async_launch.py
// 启动turtlebot3键盘控制节点
ros2 run turtlebot3_teleop teleop_keyboard
// 保存地图到home目录下
ros2 run nav2_map_server map_saver_cli -f ~/map

自定义地图测试

修改nav2_bringup功能包下tb3_simulation_launch.py文件的以下内容,地图文件位置/home/ubuntu/maps/house.yaml,加载turtlebot3_house仿真环境

declare_map_yaml_cmd = DeclareLaunchArgument(
        'map',
        default_value='/home/ubuntu/maps/house.yaml',
        # default_value=os.path.join(
        #     bringup_dir, 'maps', 'turtlebot3_world.yaml'),
        description='Full path to map file to load')

declare_world_cmd = DeclareLaunchArgument(
        'world',
        # TODO(orduno) Switch back once ROS argument passing has been fixed upstream
        #              https://github.com/ROBOTIS-GIT/turtlebot3_simulations/issues/91
        # default_value=os.path.join(get_package_share_directory('turtlebot3_gazebo'),
        # worlds/turtlebot3_worlds/waffle.model')
        # default_value=os.path.join(bringup_dir, 'worlds', 'world_only.model'),
        default_value=os.path.join(get_package_share_directory('turtlebot3_gazebo'),
        'worlds',
        'turtlebot3_house.world'),
        description='Full path to world model file to load')

参照ros2 launch nav2_bringup tb3_simulation_launch.py headless:=False即可进行测试

posted @ 2023-09-12 17:00  泡泡吐泡泡啊  阅读(667)  评论(0编辑  收藏  举报