ROS_Learn/README.md
2025-09-27 09:27:05 +00:00

206 lines
5.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# <p align="center">ROS_Learn</p>
## 实验一
### ROS-noetic安装应用于Ubuntu20.04LTS<br>注最好全程使用root权限
切换ubuntu软件源并添加ROS源地址访问清华源来提升下载速度。最好提前备份以下文件避免操作失误无法恢复
```c
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
```
设置apt密钥。
```c
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
```
更新apt软件源。
```c
sudo apt update
```
安装ROS-noetic适用于Ubuntu20.04Lts)。
```c
sudo apt install ros-noetic-desktop-full
```
配置ROS-noetic环境变量。
```c
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
```
安装ROS-python3工具包。
```c
sudo apt install python3-rosinstall python3-rosinstall-generator python3-wstool
sudo apt install build-essential
```
环境配置检测,配置无误的话可无需运行。
```c
# 确保环境配置
source /opt/ros/noetic/setup.bash
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
# 确保ROS安装完整
sudo apt install --reinstall ros-noetic-desktop-full
# 检测roslaunch是否安装
dpkg -l | grep ros-noetic-roslaunch
# 若roslaunch以安装则无需执行下条命令
sudo apt install ros-noetic-roslaunch
```
常用命令。
```c
# 将路径换为文件/文件夹路径,赋予文件/文件夹可执行权限
chmod +x /路径
# 将文件/文件夹可编辑权限赋予某用户
sudo chown -R 用户名:用户名 /路径
# 停止roscore命令
ps aux | grep roscore
kill -9 <PID>
```
启动roscore。
```c
roscore
```
启动小乌龟(新终端窗口打开)。
```c
rosrun turtlesim turtlesim_node
```
控制小乌龟(新新终端窗口打开)。
```c
rosrun turtlesim turtle_teleop_key
```
### 结果图
终端运行结果:<br>
![小乌龟](/Pictures/Turtle.png#pic_center)
创建工作空间。
```c
mkdir -p src
catkin_make
```
设置 ROS 环境变量。
```c
echo "source /文件夹路径/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc
```
进入 src 目录并创建功能包。
```c
cd src
catkin_create_pkg Service rospy std_msgs geometry_msgs visualization_msgs message_generation
```
创建结构和放置文件。
```c
cd Service
mkdir scripts
mkdir srv
```
## 实验二
### ROS中话题通信
编译工作空间。
```c
catkin_make
```
设置文件可执行权限。
```c
chmod +x /文件夹路径/程序名.py
```
添加环境变量(所有新终端窗口要执行下列命令)。
```c
source /文件夹路径/devel/setup.bash
```
启动roscore终端A
```c
roscore
```
启动订阅端终端B
```c
rosrun Topic_Newsletter Subscriber_TN.py
```
启动发送端终端C
```c
rosrun Topic_Newsletter Publisher_TN.py
```
启动RViz终端D
```c
rviz
```
将RViz左侧 Global Options 面板中 Fixed Frame 设为 map (默认无需修改)。<br>
在 Displays 面板中,点击 Add添加 Marker 类型。
### 结果图
终端运行数据结果:<br>
![话题通讯1](/Pictures/Topic_Newsletter_one.png#pic_center)
RViz图像<br>
![话题通讯2](/Pictures/Topic_Newsletter_two.png#pic_center)
## 实验三
### ROS中服务端和客户端
编译工作空间。
```c
catkin_make
```
设置文件可执行权限。
```c
chmod +x /文件夹路径/程序名.py
```
添加环境变量。
```c
source /文件夹路径/devel/setup.bash
```
启动roscore终端A
```c
roscore
```
启动服务端终端B
```c
rosrun Service Service_S.py
```
启动订阅端也是客户端终端C
```c
rosrun Service Subscriber_Client_S.py
```
启动发送端终端D
```c
rosrun Service Publisher_S.py
```
启动RViz终端F
```c
rviz
```
将RViz左侧 Global Options 面板中 Fixed Frame 改为程序中的 world 。<br>
在 Displays 面板中,点击 Add添加 Marker 类型。
### 结果图
终端运行数据结果:<br>
![服务和客户1](/Pictures/Service_one.png#pic_center)
RViz图像<br>
![服务和客户2](/Pictures/Service_two.png#pic_center)
## 实验四
### ROS中导航与路径规划
更新源。
```c
sudo apt update
```
安装仿真模型包和自主导航包
```c
sudo apt install ros-noetic-turtlebot3 ros-noetic-turtlebot3-simulations ros-noetic-navigation
```
添加环境变量。
```c
echo "export TURTLEBOT3_MODEL=burger" >> ~/.bashrc
source ~/.bashrc
```
启动roscore终端A
```c
roscore
```
启动 TurtleBot3 的 Gazebo 仿真环境终端B
```c
roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch
```
启动地图服务节点终端C
```c
rosrun map_server map_server /home/zmn/下载/0113.yaml
```
启动 TurtleBot3 的导航系统并打开RViz显示终端D
```c
roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=/home/zmn/下载/0113.yaml
```
在 RViz 中点击 2D Nav Goal 后在地图上选择终点目标。小车将开始自动导航自动到所选终点。
### 结果图
终端运行数据结果:<br>
![导航与路径规划1](/Pictures/Navigation_one.jpg#pic_center)
RViz图像<br>
![导航与路径规划2](/Pictures/Navigation_two.jpg#pic_center)
## 小组成员
张豪、祝令旭、程思凡、曾叶昊、张梦南<br>
(排名不分先后)