ROS中的环境变量

参考http://wiki.ros.org/ROS/EnvironmentVariables

Master:节点管理器,ROS名称服务 (比如帮助节点找到彼此)。
rosout: ROS中相当于stdout/stderr。
roscore: 主机+ rosout + 参数服务器 (参数服务器会在后面介绍)。

查看环境变量

robot@ubuntu:~$ env | grep ROS
ROS_ROOT=/opt/ros/indigo/share/ros
ROS_PACKAGE_PATH=/opt/ros/indigo/share:/opt/ros/indigo/stacks
ROS_MASTER_URI=http://localhost:11311
ROSLISP_PACKAGE_DIRECTORIES=
ROS_DISTRO=indigo
ROS_ETC_DIR=/opt/ros/indigo/etc/ros

环境变量的作用:

CmakeList.txt 中的finding packages()里面需要列出所需要依赖的ros包

ROS能找到他们,需要依赖ROS_ROOT 和 ROS_PACKAGE_PATH 

ROS_ROOT 指向了ROS的core package

ROS_PACKAGE_PATH指向了ros包的位置。

安装ROS把source /opt/ros/indigo/setup.bash 保证了该环境变量的生成!!

影响结点运行

ROS_MASTER_URI 告诉结点Master在哪里,提供名称服务,互相找到彼此。甚至分布式计算在不同计算机之间的通信。

ROS_MASTER_URI is a required setting that tells nodes where they can locate the master. It should be set to the XML-RPC URI of the master. Great care should be taken when using localhost, as that can lead to unintended behaviors with remotely launched nodes.

export ROS_MASTER_URI=http://mia:11311/

ROS_IP ROS_HOSTNAME影响结点的网络地址

ROS_NAMESPACE允许你改变命名空间

  ROS_LOG_DIR 允许你改变目录文件保存的目录,默认为~/.ros/log

  修改编译系统:

ROS_BINDEPS_PATH, ROS_BOOST_ROOT, ROS_PARALLEL_JOBS, ROS_LANG_DISABLE 影响了怎么查找库文件,怎么编译等

PYTHONPATH

robot@ubuntu:~$ env | grep PY
PYTHONPATH=/opt/ros/indigo/lib/python2.7/dist-packages
PYTHONPATH 指定了所需要导入的模块的路径。还有一些python 工具需要依赖某些模块。

export PYTHONPATH=$PYTHONPATH:$ROS_ROOT/core/roslib/src

ROS_PACKAGE_PATH

export ROS_PACKAGE_PATH=/home/user/ros/ros-pkg:/another/path 

  #将自己的catkin_workspace增加入环境变量。这样roscd roslist 才能找到用户创建的包。


ROS_HOME

一般值~/.ROS

robot@ubuntu:~/.ros$ ls
log                rospack_cache_00838615507935911151
roscore-11311.pid  rospack_cache_11486458967921186402
rosdep             rosstack_cache_11486458967921186402

ROS_LOG_DIR

一般指ROS_HOME/log/

可改

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

节点的环境变量

ROS_IP/ROS_HOSTNAME

ROS_NAMESPACE

将一个节点放入一个命名空间。

典型的例子是turtlebot 两个小海龟,后一个海归跟随第一个海归的实例。launch中


printenv | grep CM*

CMAKE_PREFIX_PATH=/opt/ros/indigo

locate rosrun

/opt/ros/indigo/bin/rosrun

rosrun只不过是一个shell脚本,能够理解ROS的文件组织结构,当然结点之间能够互相找到,是结点管理器提供的名称注册/名称查找的作用。

而rosrun能够像linux系统命令可以执行的原因是:

echo $PATH
/opt/ros/indigo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

结点名和可执行文件名字不一定一样

1.节点名在程序内部实例化结点由一段字符串命名

1 // This is a ROS version of the standard "hello , world"
2 // program.
3
4 // This header defines the standard ROS classes .
5 #include <ros / ros.h>
6
7 int main ( int argc , char ** argv ) {
8 // Initialize the ROS system .
9 ros::init ( argc , argv , " hello _ros " ) ;//"hello_ros"为结点名
10
11 // Establ ish this program as a ROS node .
12 ros::NodeHandle nh ;
13
14 // Send some output as a log message .
15 ROS_INFO_STREAM( " Hello , ␣ ROS! " ) ;
16 }

      2.命令行重映射 rosrun package-name executable-name __name:=new_node_name

     3.launch文件,ns="" pkg="" type="executable-file-name" name="new_node_name"

     4. rosnode info/rosnode cleanup

rosout

rosout本身就是一个结点,随roscore启动(还有参数管理器,结点管理器),类似std::cout 到屏幕的标准输出。椭圆表示结点,方框表示话题

产生一个话题/rosout

ROS_INFO()

ROS_WARN()

ROS_FAULT()

rostopic info topic-name    /rostopic echo topic-name /rosmsg type msg-name

rostopic pub –r 1 /turtle1/cmd_vel geometry_msgs/Twist ’[2,0,0]’ ’[0,0,0]’ ##该消息有两个域,两个‘【】’代表两个域

自动在命令行输出特定消息格式的方式输出话题名 数据类型名 后,tab(自动补全消息的所有域及其顺序)

 rostopic pub /turtle1/cmd_vel geometry_msgs/Twist "linear:
  x: 0.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.0" 

编译:

当第一次在~/catkin_ws/编译时,使用catkin_make

以后添加功能包时,可以使用catkin_make --force-cmake 

       catkin_make -pkg your-new-pkg-name 

Using CATKIN_DEVEL_PREFIX: /home/robot/danimtb_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/indigo
-- This workspace overlays: /opt/ros/indigo
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/robot/danimtb_ws/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.19
-- BUILD_SHARED_LIBS is on
-- Configuring done
-- Generating done
-- Build files have been written to: /home/robot/danimtb_ws/build


关于肖军浩《机器人操作系统浅析》第61页,有一处错误,编译后build空间可以删除(正确),但是devel空间不可以删除,生成的结点在devel/lib/agitr/hello

robot@ubuntu:~/danimtb_ws$ catkin_make
Base path: /home/robot/danimtb_ws
Source space: /home/robot/danimtb_ws/src
Build space: /home/robot/danimtb_ws/build
Devel space: /home/robot/danimtb_ws/devel
Install space: /home/robot/danimtb_ws/install
####
#### Running command: "cmake /home/robot/danimtb_ws/src -DCATKIN_DEVEL_PREFIX=/home/robot/danimtb_ws/devel -DCMAKE_INSTALL_PREFIX=/home/robot/danimtb_ws/install -G Unix Makefiles" in "/home/robot/danimtb_ws/build"
####
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Using CATKIN_DEVEL_PREFIX: /home/robot/danimtb_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/robot/danimtb_ws/devel;/opt/ros/indigo
-- This workspace overlays: /home/robot/danimtb_ws/devel;/opt/ros/indigo
-- Found PythonInterp: /usr/bin/python (found version "2.7.6") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/robot/danimtb_ws/build/test_results
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.19
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - agitr
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'agitr'
-- ==> add_subdirectory(agitr)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/robot/danimtb_ws/build
####
#### Running command: "make -j1 -l1" in "/home/robot/danimtb_ws/build"
####
Scanning dependencies of target hello
[100%] Building CXX object agitr/CMakeFiles/hello.dir/hello.cpp.o
Linking CXX executable /home/robot/danimtb_ws/devel/lib/agitr/hello
[100%] Built target hello


使用apt安装软件包之后,ros的更新软件包目录的工具

$ rospack profile                               #更新一下ROS内部软件包
#rospack profile功能类似于使用sudo apt-get update更新Linux软件包一样。它的功能是:更新ros软件包
ros路径搜索的环境变量
robot@ubuntu:/usr/include/x86_64-linux-gnu$ echo $CMAKE_PREFIX_PATH
/opt/ros/indigo
robot@ubuntu:/usr/include/x86_64-linux-gnu$ cd ~/catkin_ws/
robot@ubuntu:~/catkin_ws$ . devel/setup.bash 
robot@ubuntu:~/catkin_ws$ echo $CMAKE_PREFIX_PATH
/home/robot/catkin_ws/devel:/opt/ros/indigo


详细参见以上网址

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值