ROS原始的编译和打包系统是rosbuild,而catkin(基本就是创建功能和编译功能包
)是现在ROS官方指定的系统。catkin的原理和流程和CMake很类似,与rosbuild相比,它的可移植性,以及对交叉编译的支持更好。
roscpp rospy 表示不同语言的接口,都可以用来创建topic等,是package的依赖
0.package
create a workspace
$ mkdir -p ~/catkin_ws/src //在主目录下创建catkin_ws,同时包含一个子目录src
$ cd ~/catkin_ws/
$ catkin_make //编译,会在src路径中生成一个CMakeLists.txt
激活环境变量
source devel/setup.bash //添加环境变量
echo $ROS_PACKAGE_PATH //查看环境变量
Creating a ROS Package
https://blog.csdn.net/weixin_38923551/article/details/80065912
http://wiki.ros.org/ROS/Tutorials/CreatingPackage
cd src
catkin_create_pkg beginner_tutorials std_msgs rospy roscpp//在src路径下catkin_create_pkg <package_name> [depend1] [depend2] [depend3]生成一个包,然后包里有CMakelists.txt文件和xml文件
cd ~/catkin_ws
catkin_make //生成包以后要进行编译,生成build\devel文件夹,build是cmake被调用的配置文件,devel是在包未被安装的时存放变量、库的文件
. ~/catkin_ws/devel/setup.bash//添加环境
The build folder is the default location of the build space and is where cmake and make are called to configure and build your packages. The devel folder is the default location of the devel space, which is where your executables and libraries go before you install your packages.
查看ROS包的依赖项
rospack depends1 beginner_tutorials //可以在src中查看,也可以在src上一级路径中查看,查看第一级依赖项 就是我们在创建包的时候指定的依赖项,该信息由xml文件提供
roscd beginner_tutorials //直接 跳转到建立的包里
cat package.xml//显示xml文件
rospack find [package_name] //会显示包的路径
rospack list//查看所有的包
rospack list | grep turtlebot //如查找所有包含turtlebot的包
1.Node相关操作
-
Nodes: A node is an executable that uses ROS to communicate with other nodes.
( Node本质上也就是package里面的可执行文件而已 ) -
Messages: ROS data type used when subscribing or publishing to a topic.
-
Topics: Nodes can publish messages to a topic as well as subscribe to a topic to receive messages.
-
Master: Name service for ROS (i.e. helps nodes find each other)
-
rosout: ROS equivalent of stdout/stderr
-
roscore: Master + rosout + parameter server (parameter server will be introduced later)
roscore //roscore is the first thing you should run when using ROS
rosnode //roscore = ros+core : master (provides name service for ROS) + rosout (stdout/stderr) + parameter server (parameter server will be introduced later)
//master是整个ROS运行的核心,它主要的功能就是登记注册节点、服务和话题的名称,并维护一个参数服务器。没有它你就甭想启动任何一个节点,roscore就是用来启动master的。https://blog.csdn.net/lisfaf/article/details/90449362
//http://wiki.ros.org/roscore
可以指定一个端口来运行核心
NOTE: if you use the port switch, you will probably have to pass in this switch to any separate roslaunch files you launch as well. In addition, do not forget to change the environment variable ROS_MASTER_URI before, e.g.
$export ROS_MASTER_URI=http://YourPC:1234/
$roscore -p 1234
查看所有正在运行的 Node
$ rosnode list
查看某节点信息
rosnode info [node_name]
运行某个包中的某个node文件
rosrun [package_name] [node_name]
2.rostopic
rostopic list -h
//Usage: rostopic list [/topic]
Options:
-h, --help show this help message and exit
-b BAGFILE, --bag=BAGFILE
list topics in .bag file
-v, --verbose list full details about each topic
-p list only publishers
-s list only subscribers
3.ROS Message
http://wiki.ros.org/ROS/Tutorials/UnderstandingTopics
rostopic type [topic]
rostopic type /turtle1/cmd_vel
//get the type :geometry_msgs/Twist
rosmsg show geometry_msgs/Twist
//输出
// geometry_msgs/Vector3 linear
// float64 x
// float64 y
// float64 z
// geometry_msgs/Vector3 angular
// float64 x
// float64 y
// float64 z
4.ROS service
Services are another way that nodes can communicate with each other. Services allow nodes to send a request and receive a response.
安装乌龟模拟器
sudo apt-get install ros-melodic-turtle-tf
ROS拥有三种通讯协议:
publishers/subscribers //消息订阅
services/clients //服务
action-servers/action-clients
除了以上三种通信机制,还有第四种通信机制,那就是
parameter server
可以很方便的通过parameter server保存或读取一些不需要经常变动的常量。
常常用来设置一些配置参数等信息,将这些参数信息写入YAML文件中,一般使用以下方法读取YAML文件的信息(具体操作在第二部分):
通过命令行进入parameter server加载这个YAML文件
通过launch文件调用它