# turtlebot3_simulation_1
**Repository Path**: zbrover/turtlebot3_simulation_1
## Basic Information
- **Project Name**: turtlebot3_simulation_1
- **Description**: https://www.yuque.com/u41966529/lmsgts/ec6adi8146o2b99q
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: ardupilot_controller
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 3
- **Created**: 2024-08-20
- **Last Updated**: 2024-08-20
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## 简介
1.工作目标
本项目用ros 2和Gazebo Garden实现ArduPilot Rover导航的软件仿真。
2.基本思路
[turblebot3_simulation](https://github.com/ROBOTIS-GIT/turtlebot3_simulations)软件包已经提供了Gazebo classic版本的小车模型,在小车模型中采用了ros 1的差速车驱动插件(libgazebo_ros_diff_drive),也实现了Gazebo classic的小车模型的仿真。为了用ros 2和Gazebo Garden实现ArduPilot小车的仿真,我们分两步来做:
- 第一步,我们把小车模型的Gazebo classic版本改成Gazebo Garden版本,并在小车模型中使用ros 2的差速车插件(DiffDrive),这样就用ros 2实现Gazebo Garden版本的小车仿真。
- 第二步,我们将ros 2的差速车驱动插件替换成ArduPilot的ros 2的插件(ardupilot_gazebo),这样就可以用ros 2实现ArduPilot Rover在Gazebo Garden版本下的软件仿真。为此,我们还需要在turblebot3_simulation软件包中启动ardupilot dds,这样,ardupilot软件仿真程序才能通过Gazebo中的ros 2插件与Gazebo的物理引擎产生互动。
关于导航软件包[navigation2](https://github.com/ros-planning/navigation2.git),由于此软件包采用turblebot3_simulation的Gazebo classic小车模型实现了导航,又由于我们在turblebot3_simulation中已经将Gazebo classic的模型改造成了Gazebo Garden模型,所以我们可以直接调用navigation2的启动序列实现导航。
我们的程序既可以用ArduPilot提供的ros 2 Gazebo插件实现软件仿真,也可以用Gazebo提供的ros 2差速车驱动插件实现软件仿真。
3.代码库的组织
navigation2的分支和turtlebot3_simulation的ardupilot_controller分支是一个使用ardupilot固件的导航仿真程序
navigation2的ardupilot_controller分支是由humble分支改造而来,turtlebot3_simulation的ardupilot_controller分支是由master分支改造而来
旧分支参考链接:
[https://gazebosim.org/docs/latest/migrating_gazebo_classic_ros2_packages/](http://)
[https://docs.nav2.org/development_guides/build_docs/index.html#build](http://)
[https://github.com/azeey/turtlebot3_simulations/tree/new_gazebo](http://)
## 版本说明
本仿真用到的基础软件版本说明如下:
Ubuntu Linux 22.04
ROS 2.0(ROS Humble)
Gazebo Garden(ROS Humble)
## 先决条件
1.安装ROS2.0
2.安装Gazebo Garden
3.ROS2 with SITL in Gazebo
[https://ardupilot.org/dev/docs/ros2.html](http://)
[https://ardupilot.org/dev/docs/ros2-sitl.html](http://)
[https://ardupilot.org/dev/docs/ros2-gazebo.html](http://)
## 安装步骤
1.将turtlebot3_simulation功能包下载到ros2_ws工作空间
打开一个新的终端:
`mkdir -p ~/ros2_ws/src`
`cd ~/ros2_ws/src`
`git clone -b ardupilot_controller https://gitee.com/zbrover/turtlebot3_simulation.git`
`colcon build --packages-select turtlebot3_simulations turtlebot3_fake_node turtlebot3_gazebo --symlink-install`
2.建立ROS工作空间,并下载功能包navigation2
打开一个新的终端:
`mkdir -p ~/nav2_ws/src`
`cd ~/nav2_ws/src`
`git clone https://github.com/ros-planning/navigation2.git --branch humble ./src/navigation2`
`cd ~/nav2_ws`
`rosdep install -y \
--from-paths ./src \
--ignore-src`
`rosdep install -y -r -q --from-paths src --ignore-src --rosdistro humble`
`colcon build --symlink-install`
`rosdep install -y -r -q --from-paths src --ignore-src --rosdistro humble`
3.将twist_stamper(话题转换)功能包下载到ros2_ws工作空间
原文链接:[https://github.com/joshnewans/twist_stamper](http://)
`cd ~/ros2_ws/src`
` git clone -b main https://github.com/joshnewans/twist_stamper`
`colcon build --packages-select twist_stamper`
## 启动步骤(ArduPilot提供的ros 2 Gazebo插件)
目前实现的命令:
1.事先要在sitl_dds_udp.launch.py中把mavproxy注释掉。
打开一个新的终端:
2.刷新环境变量
~$ `cd nav2_ws`
~/nav2_ws$`. install/setup.bash`
~/nav2_ws$ `cd`
~$ `cd ros2_ws`
~/ros2_ws$ `. install/setup.bash`
3.变量赋值,使其找到所需要使用的文件
~/ros2_ws$ `export TURTLEBOT3_MODEL=apm`
~/ros2_ws$ `ros2 launch turtlebot3_gazebo apm_turtlebot3_launch_2.py`
打开一个新的终端:
4.启动地面站软件mavproxy
~$ `mavproxy.py --out 127.0.0.1:14550 --out 127.0.0.1:14551 --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501 --non-interactive`
注意:运行这个才有DDS节点
打开一个新的终端:
5.解锁ardupilot
~/ros2_ws$ `ros2 service call /ap/arm_motors ardupilot_msgs/srv/ArmMotors "{arm: True}"`
6.设置ardupilot为导航模式
~/ros2_ws$ `ros2 service call /ap/mode_switch ardupilot_msgs/srv/ModeSwitch "{mode: 15}"`
7.运行话题转换节点
~/ros2_ws$ `ros2 run twist_stamper twist_stamper --ros-args -r cmd_vel_in:=cmd_vel -r cmd_vel_out:=/ap/cmd_vel -p frame_id:=base_link`
8.现在可以在rviz中初始化2D Pose Estimate,然后指定2D goal。
## 启动步骤(Gazebo提供的ros 2差速车驱动插件)
1.刷新环境变量
~$ `cd nav2_ws/`
~/nav2_ws$ `. install/setup.bash`
~/nav2_ws$ `cd`
~$ `cd ros2_ws`
~/ros2_ws$ `. install/setup.bash`
2.变量赋值,使其找到所需要使用的文件
~/ros2_ws$ `export TURTLEBOT3_MODEL=waffle`
~/ros2_ws$ `export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/home/ros2/turtlebot3_ws/src/turtlebot3_simulations/turtlebot3_gazebo/models`
~/ros2_ws$ `ros2 launch turtlebot3_gazebo tb3_turtlebot3_launch_2.py`