ROS_Learn/README.md

146 lines
4.3 KiB
Markdown
Raw Normal View History

2025-06-30 11:09:41 +08:00
# <p align="center">ROS_Learn</p>
## 实验一
### ROS-noetic安装应用于Ubuntu20.04lts<br>注最好全程使用root权限
#### 1.切换ubuntu软件源访问清华源来提升下载速度。
2025-06-28 15:31:08 +08:00
```c
sudo vim /etc/apt/sources.list # 进入apt下载源文件
```
2025-06-30 11:09:41 +08:00
删除所有ubuntu官方源最好提前备份以下文件避免操作失误无法恢复添加清华源
2025-06-28 15:31:08 +08:00
```c
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
```
2025-06-30 11:09:41 +08:00
vim中按`Esc`退出编辑模式,按`Shift+`进入命令输入模式输入`wq`保存退出。<br>
在命令行中输入下列命令添加ROS源地址。
2025-06-28 15:31:08 +08:00
```c
sudo sh -c 'echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu focal main" > /etc/apt/sources.list.d/ros-latest.list'
```
设置密钥
```c
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-keys 6A030B21B4D2B67B
```
2025-06-30 11:09:41 +08:00
更新软件源
2025-06-28 15:31:08 +08:00
```c
sudo apt update
```
2025-06-30 11:09:41 +08:00
安装ROS-noetic适用于Ubuntu20.04Lts
2025-06-28 15:31:08 +08:00
```c
sudo apt install ros-noetic-desktop-full
```
初始化 rosdep
```c
sudo rosdep init
rosdep update
```
配置环境变量
```c
source /opt/ros/noetic/setup.bash
source ~/.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
2025-06-30 11:09:41 +08:00
# 将路径换为文件/文件夹路径,赋予文件/文件夹可执行权限
chmod +x /路径
2025-06-30 11:09:41 +08:00
# 将文件/文件夹可编辑权限赋予某用户
sudo chown -R 用户名:用户名 /路径
2025-06-28 15:31:08 +08:00
```
2025-06-30 11:09:41 +08:00
#### 2.启动roscore
2025-06-28 15:31:08 +08:00
```c
roscore
```
启动小乌龟
```c
rosrun turtlesim turtlesim_node
```
控制小乌龟(新终端窗口打开)
```c
rosrun turtlesim turtle_teleop_key
```
2025-06-30 11:09:41 +08:00
## 实验二
### ROS中话题通信
2025-06-28 15:31:08 +08:00
编译工作空间
```c
catkin_make
```
2025-06-30 11:09:41 +08:00
添加环境变量(所有新终端窗口要执行下列命令)
2025-06-28 15:31:08 +08:00
```c
source /home/zmn/Gitea/ROS_Learn/devel/setup.bash
```
启动roscore终端A
```c
roscore
```
启动订阅端终端B
2025-06-28 15:31:08 +08:00
```c
rosrun Topic_Newsletter Subscriber_TN.py
2025-06-28 15:31:08 +08:00
```
启动发送端终端C
2025-06-28 15:31:08 +08:00
```c
rosrun Topic_Newsletter Publisher_TN.py
2025-06-28 15:31:08 +08:00
```
2025-06-30 11:09:41 +08:00
启动RViz终端D
2025-06-28 15:31:08 +08:00
```c
rviz
```
将RViz左侧 Global Options 面板中 Fixed Frame 设为 map (默认无需修改)。
2025-06-28 22:11:36 +08:00
在 Displays 面板中,点击 Add添加 Marker 类型。
2025-06-30 11:09:41 +08:00
## 实验三
### ROS中服务和客户
2025-06-28 22:11:36 +08:00
编译工作空间
```c
catkin_make
```
2025-06-30 11:09:41 +08:00
启动roscore终端A
2025-06-28 22:11:36 +08:00
```c
roscore
```
添加环境变量
```c
source /home/zmn/Gitea/ROS_Learn/devel/setup.bash
```
2025-06-30 11:09:41 +08:00
启动发送端终端B
2025-06-28 22:11:36 +08:00
```c
rosrun position_demo publisher_node_three.py
```
2025-06-30 11:09:41 +08:00
启动订阅端也是客户端终端C
2025-06-28 22:11:36 +08:00
```c
rosrun position_demo subscriber_node_three.py
```
2025-06-30 11:09:41 +08:00
启动RViz终端F
2025-06-28 22:11:36 +08:00
```c
rviz
```
将RViz左侧 Global Options 面板中 Fixed Frame 改为程序中的 world 。
2025-06-30 11:09:41 +08:00
在 Displays 面板中,点击 Add添加 Marker 类型。
### 注服务端节点C提供FFT服务暂未完成。