This section needs to complete the content of the previous section to realize the normal creation of new maps by turtlebot3, so as to realize the automatic obstacle avoidance and navigation in this section
automatic obstacle avoidance
- Start a simulation of a virtual robot with an environment
export SVGA_VGPU10=0
source ./devel/setup.bash # 之前已经写入.bashrc,可以忽略此步骤
export TURTLEBOT3_MODEL=burger # 之前已经写入.bashrc,可以忽略此步骤
roslaunch turtlebot3_gazebo turtlebot3_world.launch
- keyboard control
open new port
# 如果上面的命令已经写入.bashrc,如果未写入。每次打开新端口都需要执行一次
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
3. Automatic obstacle avoidance
Open a new port
roslaunch turtlebot3_gazebo turtlebot3_simulation.launch
4. Call rviz
roslaunch turtlebot3_gazebo turtlebot3_gazebo_rviz.launch
Note: You can change the thickness of the laser scanning edge by modifying the size
build map
It has been activated before and does not need to restart the world map
# 启动世界地图,默认的空白地图环境中加载Turtlebot3机器人
roslaunch turtlebot3_gazebo turtlebot3_world.launch
# 新端口启动slam程序
roslaunch turtlebot3_slam turtlebot3_slam.launch
After starting up, you can build a map synchronously
# 新端口 启动键盘控制移动,,建立全部的地图
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
# 如果无法控制,可以再新端口使用自动避障使其自己走
roslaunch turtlebot3_gazebo turtlebot3_simulation.launch
Control turtlebot3 to move around until you are satisfied with the construction.
After building the map, we run the following command to save the map:
rosrun map_server map_saver -f ~/map
This is the map is saved to the current path. save as two files
navigation
# 加载仿真环境 启动地图
roslaunch turtlebot3_gazebo turtlebot3_world.launch
# 加载这个地图
roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/map.yaml # 这个路径根据自己配置,是你的地图路径
# 如果启动报警告,就多试几次
The effect is as follows:
(1) When [2d pose estimate] is pressed in the rviz menu , a green arrow will appear, place the arrow on the position of the tb3 robot on the map, hold down the left mouse button, and turn the green arrow to point to the front of the robot .This arrow is equivalent to giving the robot an initial position and forward direction (I understand it this way for the time being, welcome to correct me)
(2) After everything is ready, issue a movement command below. If you press [2D Nav Goal] in RViz's menu , a very big green arrow will appear. The green arrow is a mark specifying the destination of the robot, the starting point of the arrow is the x, y position of the robot, and the direction of the arrow is the i direction of the robot. Move this arrow to the robot's destination, then drag to set the direction. The robot will avoid obstacles according to the created map and move to the destination.
Click the 2D Nav Goal button and drag to set the direction , as shown in the figure, and you can navigate
mistake
error 1
An error is reported when starting the navigation.
This error seems to be nothing, but it may take a while. I executed it a few times , and it will be fine after a while.
reference
Turtlebot3 realizes navigation in the simulation environment
[ros practice 2] turtlebot3 map building and navigation