学生用源代码-Turtlebot3-burger入门教程-noetic版

现将TB3源代码提供给大家,具体位置参考教程。希望能对大家的学习有所帮助。

https://www.ncnynl.com/archives/202110/4660.html

学生用源代码-Turtlebot3-burger入门教程-noetic版

PC端代码-Turtlebot3-burger入门教程-noetic版
#ROS安装
# 设置源
$  sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" >  /etc/apt/sources.list.d/ros-latest.list'
# 设置keys
$ sudo apt install curl # if you haven't already installed curl
$ curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
# 安装noetic
$ sudo apt-get update 
$ sudo apt install ros-noetic-desktop-full 
# 配置环境
$ echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc 
$ source ~/.bashrc
#验证noetic版安装成功 
$ rosversion -d
#安装相关依赖包
$ sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
# 初始化rosdep
$ sudo rosdep init
$ rosdep update


#如果出错,则#编辑文件添加内容 $ sudo gpedit /etc/hosts     
185.199.111.133  raw.githubusercontent.com  
20.205.243.166  github.com    
#查询IP地址 site.ip138.com

#安装相关依赖包
$ sudo apt-get install ros-noetic-joy ros-noetic-teleop-twist-joy \
  ros-noetic-teleop-twist-keyboard ros-noetic-laser-proc \
  ros-noetic-rgbd-launch ros-noetic-rosserial-arduino \
  ros-noetic-rosserial-python ros-noetic-rosserial-client \
  ros-noetic-rosserial-msgs ros-noetic-amcl ros-noetic-map-server \
  ros-noetic-move-base ros-noetic-urdf ros-noetic-xacro \
  ros-noetic-compressed-image-transport ros-noetic-rqt* ros-noetic-rviz \
  ros-noetic-gmapping ros-noetic-navigation ros-noetic-interactive-markers \
  ros-noetic-slam-karto ros-noetic-hector-mapping 

#安装TurtleBot3包
$ mkdir -p ~/turtlebot3_ws/src
$ cd ~/turtlebot3_ws/src
$ catkin_init_workspace
$ git clone  https://github.com/ROBOTIS-GIT/DynamixelSDK.git
$ 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/hls_lfcd_lds_driver.git
$ cd ~/turtlebot3_ws && catkin_make
$ echo "source ~/turtlebot3_ws/devel/setup.bash" >> ~/.bashrc

#配置模型的环境变量
$ echo "export TURTLEBOT3_MODEL=burger" >> ~/.bashrc
$ source ~/.bashrc

#获得对应的IP地址:比如192.168.0.100
$ ifconfig
#修改根目录下的 .bashrc 文件
$ sudo gedit ~/.bashrc
#PC配置。复制内容如下:
export ROS_MASTER_URI=http://192.168.0.100:11311
export ROS_HOSTNAME=192.168.0.100
#让环境生效
$ source ~/.bashrc

Turtlebot端代码-Turtlebot3-burger入门教程-noetic版
#验证noetic版安装成功 
rosversion -d

#编译TurtleBot3包
$ cd ~/turtlebot3_ws && catkin_make

#配置模型的环境变量
$ echo "export TURTLEBOT3_MODEL=burger" >> ~/.bashrc
$ echo "export LDS_MODEL=LDS-02" >> ~/.bashrc #根据当时使用的雷达来设置
$ source ~/.bashrc

#命令获得对应的IP地址:比如192.168.0.101
$ ifconfig
#TURTLEBOT配置。复制内容如下:
export ROS_MASTER_URI=http://192.168.0.100:11311
export ROS_HOSTNAME=192.168.0.101

#让环境生效
$ source ~/.bashrc

PC和Turtlebot一起来完成的代码:
测试是否配置好主从机
[Remote PC] 启动roscore
$ roscore
[TurtleBot] 查看是否订阅到主机发布的话题
$ rostopic list
/rosout
/rosout_agg
若出现错误 ERROR: Unable to communicate with master! 即说明主从机未配置成功

雷达测试LDS-02。可跳过此步。

启动测试。可跳过此步。


键盘控制
[Remote PC] 启动roscore
$ roscore
[TurtleBot] 启动burger
$ roslaunch turtlebot3_bringup turtlebot3_robot.launch
[Remote PC] 启动进行简单远程操作测试
$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

创建地图
[Remote PC] 启动roscore
$ roscore
[TurtleBot] 启动Burger
$ roslaunch turtlebot3_bringup turtlebot3_robot.launch
[Remote PC] 然后运行SLAM启动文件以及Rviz,默认的slam算法为gampping
$ export TURTLEBOT3_MODEL=burger
# 默认使用gmapping算法
$ roslaunch turtlebot3_slam turtlebot3_slam.launch 

也可选择以下算法,执行相应命令。

# hector算法
$ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=hector
# cartographer算法
$ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer
# karto算法
$ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=karto

[Remote PC] 启动键盘操作
$ export TURTLEBOT3_MODEL=burger
$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
移动burger进行建图
[Remote PC] 建图完成后保存地图
$ rosrun map_server map_saver -f ~/map
map.pgm和map.yaml 在 ~/ 目录里创建

进行导航
[Remote PC] 启动roscore
$ roscore
[TurtleBot] 启动burger
$ roslaunch turtlebot3_bringup turtlebot3_robot.launch
[Remote PC] 启动导航和rviz
$ export TURTLEBOT3_MODEL=burger
$ roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/map.yaml
[Remote PC] 在开始导航之前,TurtleBot3应该知道它的位置和姿势。

给出初始数据,点击2D Pose Estimate按钮
通过单击并拖动地图上的方向来设置地图上的大致位置。

发送目标位置:点击 2D Nav Goal按钮
点击地图上你想要的TurtleBot驱动和拖动方向TurtleBot应该指向地方

posted @ 2026-01-13 00:21  hncj2024  阅读(138)  评论(0)    收藏  举报