常用变量
CMAKE_SOURCE_DIR ( 相当于工程根目录 )
this is the directory, from which cmake was started, i.e. the top level source directory
CMAKE_CURRENT_SOURCE_DIR(当前cmakelist.txt所在的文件夹目录)
this is the directory where the currently processed CMakeLists.txt is located in
PROJECT_SOURCE_DIR ( =CMAKE_SOURCE_DIR 相当于工程根目录 )
contains the full path to the root of your project source directory, i.e. to the nearest directory where CMakeLists.txt contains the PROJECT() command
CMAKE_PREFIX_PATH (用于找 Findxxx.cmake文件,找 库 和 头文件)
Path used for searching by FIND_XXX(), with appropriate suffixes added.
CMAKE_INSTALL_PREFIX ( 安装目录 )
Install directory used by install.
If “make install” is invoked or INSTALL is built, this directory is prepended onto all install directories. This variable defaults to /usr/local on UNIX and c:/Program Files on Windows.
例如: cmake .. -DCMAKE_INSTALL_PREFIX=/my/paht/to/install
rosrun
- rosrun [package_name] [node_name]
例如:rosrun turtlesim turtlesim_node
turtlesim是一个包名,turtlesim_node是可执行文件名
/opt/ros/kinetic/lib/turtlesim/turtlesim_node 这个文件是可执行文件
roslaunch
.launch格式解析
add_executable(novatel_node src/novatel_node.cpp)
可执行文件名字就是这个命令当中的名字确定的。pkg
该节点属于哪个包,相当于rosrun命令后面的第一个参数type
可执行文件的名字,rosrun命令的第二个参数name
该节点的名字,相当于代码中ros::int的命名信息,有了它代码中的名称会被覆盖。
还有就是name属性给节点指派了名称,它将覆盖任何通过调用 ros::int来赋予节点的名称参数说明-param
如下所示的launch内容
<launch>
<!-- This is the node written by David Hodo for use with AUXOS.
for more up-to date roslaunching, see novatel_for_psr.launch
-->
<!-- Start the novatel node -->
<node pkg="novatel" type="novatel_node" name="novatel_node" output="screen"
required="true">
<param name="port" value="/dev/ttyS0" />
<param name="baudrate" value="115200" />
<param name="odom_topic" value="/gps_odom" />
<param name="log_commands" value="" />
<param name="configure_port" value="COM2,9600,RTCM,NONE" />
<!-- <param name="log_commands" value="BESTUTMB ONTIME 1.0; BESTVELB ONTIME 1.0" /> -->
<param name="gps_default_logs_period" value="0.05" />
<param name="span_default_logs_period" value="0.0" />
</node>
</launch>
<xml内容/>:
配置文件xml的配置格式
.launch:
本质是xml文件配置,来达到依赖注入的目的,这是一种在设计模式上称之为控制反转的策略,来达到让框架或者核心代码更加稳定的设计方法,可以参考我的设计模式相关博客来理解,对于这些抽象的设计模式和设计方法,需要一点一滴的在工作中任何细节去参透消化,不要指望通过看一本书来消化这些,因为这些本身是在大量的软件行业实践和错误中提炼出来的准则!只能从生活和工作中所见细节中去理解!
这些参数可以将一些关键的比如波特率啊,接口名字传入到代码中,而无需更改代码本身,不同的项目不同的硬件,也只有一个xml文件的差别,代码都不需要做版本控制
ros::NodeHandle
param命令
例如:nh_.param("odom_topic", odom_topic_, std::string("/gps_odom"));
第一个参数表示在配置参数的文件中找到odom_topic参数 并且把参数赋值给odom_topic_如果没有,那么odom_topic_默认参数为/gps_odomros::NodeHandle参数的命名空间问题在命名空间章节查找说明
一个ros的node只有一个NodeHandle,它提供这个node的对于topic的收发功能
node工作流程
-
初始化 ros::init
ros::init(argc, argv, "my_node_name");
例如:下面这里边的都属于node_name
ros::init(argc, argv, "novatel_node");
启动:ros::NodeHandle nh 实例化一个nh 就启动
关闭
在任何时候你都可以调用ros :: shutdown()函数来关闭你的节点。这将杀死所有打开的订阅,发布,服务调用和服务服务器。
默认情况下,roscpp还会安装一个SIGINT处理程序,它将检测到Ctrl-C并自动关闭。
rosdep init
[yuhs@yuhs ~]$sudo rosdep init
ERROR: default sources list file already exists:
/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize
rosdep update
[yuhs@yuhs ~]$rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index.yaml
Add distro "groovy"
Add distro "hydro"
Add distro "indigo"
Add distro "jade"
Add distro "kinetic"
Add distro "lunar"
Add distro "melodic"
updated cache in /home/yuhs/.ros/rosdep/sources.cache
ros包package的理解
对于任何一个ROS package,其文件结构如下:
package_name
include
file.h
src
file.cpp
msg(optional)
MyMessage.msg
srv(optional)
MyService.srv
launch(optional)
MyLaunch.launch
CMakeList.txt
package.xml
spin和spinOnce
# ros::spin() 和 ros::spinOnce() 区别及详解
共同:这两个有共同的功能就是获取topic消息
区别:一个返回一个不返回