常用變量
CMAKE_SOURCE_DIR ( 相當(dāng)于工程根目錄 )
this is the directory, from which cmake was started, i.e. the top level source directory
CMAKE_CURRENT_SOURCE_DIR(當(dāng)前cmakelist.txt所在的文件夾目錄)
this is the directory where the currently processed CMakeLists.txt is located in
PROJECT_SOURCE_DIR ( =CMAKE_SOURCE_DIR 相當(dāng)于工程根目錄 )
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是可執(zhí)行文件名
/opt/ros/kinetic/lib/turtlesim/turtlesim_node 這個文件是可執(zhí)行文件
roslaunch
.launch格式解析
add_executable(novatel_node src/novatel_node.cpp)
可執(zhí)行文件名字就是這個命令當(dāng)中的名字確定的。pkg
該節(jié)點屬于哪個包,相當(dāng)于rosrun命令后面的第一個參數(shù)type
可執(zhí)行文件的名字,rosrun命令的第二個參數(shù)name
該節(jié)點的名字,相當(dāng)于代碼中ros::int的命名信息,有了它代碼中的名稱會被覆蓋。
還有就是name屬性給節(jié)點指派了名稱,它將覆蓋任何通過調(diào)用 ros::int來賦予節(jié)點的名稱參數(shù)說明-param
如下所示的launch內(nèi)容
<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內(nèi)容/>:
配置文件xml的配置格式
.launch:
本質(zhì)是xml文件配置,來達(dá)到依賴注入的目的,這是一種在設(shè)計模式上稱之為控制反轉(zhuǎn)的策略,來達(dá)到讓框架或者核心代碼更加穩(wěn)定的設(shè)計方法,可以參考我的設(shè)計模式相關(guān)博客來理解,對于這些抽象的設(shè)計模式和設(shè)計方法,需要一點一滴的在工作中任何細(xì)節(jié)去參透消化,不要指望通過看一本書來消化這些,因為這些本身是在大量的軟件行業(yè)實踐和錯誤中提煉出來的準(zhǔn)則!只能從生活和工作中所見細(xì)節(jié)中去理解!
這些參數(shù)可以將一些關(guān)鍵的比如波特率啊,接口名字傳入到代碼中,而無需更改代碼本身,不同的項目不同的硬件,也只有一個xml文件的差別,代碼都不需要做版本控制
ros::NodeHandle
param命令
例如:nh_.param("odom_topic", odom_topic_, std::string("/gps_odom"));
第一個參數(shù)表示在配置參數(shù)的文件中找到odom_topic參數(shù) 并且把參數(shù)賦值給odom_topic_如果沒有,那么odom_topic_默認(rèn)參數(shù)為/gps_odomros::NodeHandle參數(shù)的命名空間問題在命名空間章節(jié)查找說明
一個ros的node只有一個NodeHandle,它提供這個node的對于topic的收發(fā)功能
node工作流程
-
初始化 ros::init
ros::init(argc, argv, "my_node_name");
例如:下面這里邊的都屬于node_name
ros::init(argc, argv, "novatel_node");
這里邊的name 啟動:ros::NodeHandle nh 實例化一個nh 就啟動
關(guān)閉
在任何時候你都可以調(diào)用ros :: shutdown()函數(shù)來關(guān)閉你的節(jié)點。這將殺死所有打開的訂閱,發(fā)布,服務(wù)調(diào)用和服務(wù)服務(wù)器。
默認(rèn)情況下,roscpp還會安裝一個SIGINT處理程序,它將檢測到Ctrl-C并自動關(guān)閉。
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,其文件結(jié)構(gòu)如下:
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() 區(qū)別及詳解
共同:這兩個有共同的功能就是獲取topic消息
區(qū)別:一個返回一個不返回