笔记 || ROS相关基础 (Updated:20240908)
1. linux基础
1.1 pwd
查看当前所在目录
1.2 cd
进行目录的切换
1.3 mkdir
创造文件夹
mkdir XXX
XXX为创建的文件夹的名字
1.4 ls
列出当前文件下有的文件或文件夹
1.5 touch
创建一个文本文件
touch XXX
XXX为所创建的文件名
1.6 mv
移动一个文件到另一个文件夹下
mv XX /XXX
其中XX是文件名字
/XXX是文件的路径
1.7 cp
复制一个文件到指定路径下
cp XX XXX/XXXX
其中XX是文件名字
XXX是文件新的路径
XXXX是文件新的名字 如果希望重命令的话,如果不需要,则不需要后面的命令
1.8 rm
删除文件
rm XX
XX是文件名字
如果想要删除文件夹的话,咋需要加-r与斜杠
rm -r XXX/
其中XXX是文件夹名字
1.9 sudo
提升用户命令
sudo apt-get-update
1.10 help
帮助指令
--help
例如 sudo --help
1.11 clear
用于清理终端上信息。
或者使用快捷键“ctrl+L”
2. 安装g++与python
sudo apt-get install g++
sudo apt-get install python
3.ROS安装
ubuntu与ros版本对应关系
| Ubuntu | ROS 1.0 | ROS 2.0 |
| 16.04 LTS | Kinetic LTS | Ardent |
| 18.04 LTS | Melodic LTS | Dashing LTS |
| 20.04 LTS | Noetic LTS | Foxy LTS |
第1步 添加源
使用阿里镜像源,以加快安装速度
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.aliyun.com/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
第2步 设置密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
第3步 安装
对源进行更新
sudo apt-get update
安装ROS
sudo apt install ros-melodic-desktop-full
查看可使用的包,以确定安装成功
apt-cache search ros-melodic
安装ros的时候可能出现依赖问题,这个时候可以安装那些依赖包
sudo aptitude install ros-melodic-desktop ros-melodic-perception ros-melodic-simulators ros-melodic-urdf-sim-tutorial
可能需要安装aptitude,aptitude 相比于apt更加智能,会进行建议相关
sudo apt-get install aptitude
aptitude的一些常用的操作:
sudo aptitude update # 更新软件源
sudo aptitude search 软件名称 # 查看软件
sudo aptitude install 软件名称 # 安装软件
第4步 配置环境
rosdep 安装
sudo apt-get install python-rosdep
初始化rosdate
sudo rosdep init
rosdep update
初始化环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
安装rosdep时可能会出错,如果出错,就运行下面命令
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
第5步 验证ROS
启动 ros master 即节点管理器
roscore
新开一个终端,启动小海龟仿真器
rosrun turtlesim turtlesim_node
rosrun #功能包 #节点名字
再新开一个终端,启动小海龟控制节点
rosrun turtlesim turtle_teleop_key
再开一个终端,以查阅节点关系和话题列表
rqt_graph
一键脚本安装
脚本命令待确定
wget http://fishros.com/install -O fishros && sudo ./fishros
按照脚本提示进行安装即可
4.ROS相关框架与内容
4.1节点(Node)
- 执行具体任务的进程,独立运行的可执行文件。
- 不同节点可使用不同的编程语言,可分布式运行在不同的主机。
- 节点在系统中的名称必须是唯一的。
4.2 节点管理器(ROS Master)
- 为节点提供命名和注册服务。
- 跟踪和记录话题/服务,辅助节点相互查找、建立参数。
- 提供参数服务器,节点使用此服务器存储和检索运行时的参数。
4.3 话题(Topic)--异步通信机制
- 节点间用来传输数据的重要总线。
- 使用发布/订阅模型,数据由发布者传输到订阅者,同一个话题的订阅者或发布者可以不唯一。
4.4 消息(Message)--话题数据
- 具有一定的类型和数据结构,包括ROS提供的标准类型和用户自定义类型,是节点-话题-节点间传输数据的通道。
- 使用百年城语言无关.msg文件定义,编译过程中生成对应的代码文件。
可以通过下面这张图来理解话题和消息,话题类似于一个消息驿站,需要投放消息的向里面投放,需要接收消息的,从里面接收;换一个比喻就是冒险者工会。
![[Pasted image 20240811122825.png ||600]]
4.5 服务(Service)--同步通信机制
- 使用客户端/服务端(C/S) 模型,客户端发送请求数据,服务器完成处理后返回应答数据。
- 使用编程语言无关的.srv文件定义请求和应答数据结构,编译过程中生成对应的代码文件。
(需要区分话题和服务,话题发布出去,并不指定接收与回应,而服务是一对一的,有接收有回应。)
![[Pasted image 20240811123754.png ||600]]4.6 参数(Parameter)--全局共享字典
- 可通过网络访问的共享、多变量字典;
- 节点使用此服务来存储和检索运行时的参数;
- 适合存储静态、非二进制的配置参数,不适合存储动态配置的数据。
- (如果需要动态参数,ROS还有另外一个功能是动态参数配置,有需要的时候可以进行相关学习。)
4.7 文件系统
![[Pasted image 20240811124717.png||600]]
4.7.1 功能包(Package)
ROS 软件中基本单元,包含节点源码、配置文件、数据定义等。
4.7.2 功能包清单(Package manifest)
记录功能包的基本信息,包含作者信息,许可信息,依赖选项,编译标志等。
4.7.3 元功能包(Meta Package)
- 组织多喝用于同一目标的功能包。
4.8 命令行工具
4.8.1 rosnode(节点工具)
rosnode ping test connectivity to node
rosnode list list active nodes
rosnode info print information about node 后面跟节点名字
rosnode machine list nodes running on a particular machine or list machines
rosnode kill kill a running node 后面跟节点的id号码
rosnode cleanup purge registration information of unreachable nodes
4.8.2 rostopic(话题工具)
rostopic bw display bandwidth used by topic
rostopic delay display delay of topic from timestamp in header
rostopic echo print messages to screen
rostopic find find topics by type
rostopic hz display publishing rate of topic
rostopic info print information about active topic
rostopic list list active topics
rostopic pub publish data to topic
rostopic type print topic or field type
Type rostopic <command> -h for more detailed usage, e.g. 'rostopic echo -h'
4.8.3 rosservice(服务工具)
rosservice args print service arguments
rosservice call call the service with the provided args
rosservice find find services by service type
rosservice info print information about service
rosservice list list active services
rosservice type print service type
rosservice uri print service ROSRPC uri
4.8.4 rosbag(数据存储、回放及修改)
rosbag <subcommand> [options] [args]
---
Available subcommands:
check Determine whether a bag is playable in the current system, or if it can be migrated.
compress Compress one or more bag files.
decompress Decompress one or more bag files.
decrypt Decrypt one or more bag files.
encrypt Encrypt one or more bag files.
filter Filter the contents of the bag.
fix Repair the messages in a bag file so that it can be played in the current system.
help
info Summarize the contents of one or more bag files.
play Play back the contents of one or more bag files in a time-synchronized fashion.
record Record a bag file with the contents of specified topics.
reindex Reindexes one or more bag files.
举例
rosbag record -a -O cmd_record
其中 -a 表示记录所有数据,-O 表示数据存储的格式及名称
需要注意的是,默认数据存放的位置,是desktop位置
rosbag play cmd_record
即回访记录的数据。
5.工作空间与功能包的创建
5.1 工作空间的创建
- 工作空间(workspace)是存放工程开发相关文件的文件夹。
- src: 代码空间(source space) 源文件
- build: 编译空间(build space )编译过程中的中间文件,一般用不到
- devel: 开发空间(development sapce) 可执行文件,库,脚本等
- install: 安装空间(install space)安装成功的文件所在,devel与install中文件存在重复,在ROS2 中仅保留了install文件夹。
创建工作空间
mkdir catkin_ws
cd catkin_wa/
mkdir src
cd src/
catkin_init_workspace //变化文件夹的属性,使之成为工作空间
编译工作空间
cd catkin_ws/ //回到工作空间跟目录
catkin_make //进行编译,空文件夹也可以,会产生build 与devel 文件夹
catkin_make install //会产生install文件夹,安装空间,安放可执行文件
设置环境变量
source devel/setup.bash
检查环境变量路径,如有需要
echo $ROS_PACKAGE_PATH
5.2 功能包的创建
catkin_create_pkg (package_name) (depend1) (depend2) (depend3) ... // 创建功能包指令,依次是指定名字,指令需要依赖的库等
e.g.
创建功能包
cd catkin_ws/src/ //即功能包一定要放在工作空间的src里面才是可以的。 catkin_create_pkg test_pkg std_msgs rospy rosapp
- 编译
cd catkin_ws/ //进入工作空间
catkin_make //执行编译
source devel/setup.bash 刷新 环境变量,使之生效。
6.发布者publisher编程实现
问题发现与解决
1.解决每次打开ubuntu软件商店程序出现Unable to download updates from extensions.gnome.org
sudo add-apt-repository ppa:gnome-shell-extensions/ppa
sudo apt-get update
sudo apt-get install gnome-shell-extensions
分类挺明确的 不过要是关于linux 看看这个https://yjvc.cn/index.php/archives/1424/ 哈哈
收到,感谢!