首页 » 技术分享 » 使用ROS遇到的一些小问题

使用ROS遇到的一些小问题

 

1、bashrc文件设置的环境变量无效

具体表现为自己在catkin_ws空间创建的包用roscd找不到,直接运行roscore提示说网络配置不正确。

siat@ubuntu:~$ roscore
... logging to /home/siat/.ros/log/f973aef0-3ff4-11e5-a30c-28d244c5bb27/roslaunch-ubuntu-11487.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

Unable to contact my own server at [http://192.168.1.104:54385/].
This usually means that the network is not configured properly.

A common cause is that the machine cannot ping itself.  Please check
for errors by running:

    ping 192.168.1.104

For more tips, please see

    http://www.ros.org/wiki/ROS/NetworkSetup

原因是多次将source命令和export命令写进bashrc文件,导致后面的顺序如下:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi
source /home/siat/catkin_ws/devel/setup.bash
source /opt/ros/hydro/setup.bash
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/siat/ccny/ccny_vision:/home/siat/catkin_ws/src
export ROS_HOSTNAME=localhost
export ROS_MASTER_URI=http://localhost:11311
source ~/turtlebot/devel/setup.bash

发现只要将三个export语句放在所有source语句的后面就行了,改成如下

$ cd
$ gedit ~/.bashrc

修改最后几行命令的顺序

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

source /opt/ros/hydro/setup.bash
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/siat/ccny/ccny_vision:/home/siat/catkin_ws/src
export ROS_HOSTNAME=localhost
export ROS_MASTER_URI=http://localhost:11311

保存并关闭.bashrc文件,关闭终端,Ctrl+Alt+T重新打开一个终端,这个时候roscd 自己创建的包和直接运行roscore都没问题了。
原因是连续运行多条source语句只有最后一条是有效的(如下博客所说ROS每次执行命令都只能在一个工作空间中进行),所以这三条source只需要留一条在.bashrc里面就可以了

source /home/siat/catkin_ws/devel/setup.bash
source /opt/ros/hydro/setup.bash
source ~/turtlebot/devel/setup.bash

以后如果发现找不到包就要记得source一下那个工作空间中的setup.bash文件了,当你有多个工作空间的情况下博客还提供了一种overlay的方案,让ROS按照overlay的路径链条一层层往下找到对应的工作空间。
后来参考以下两篇博客发现问题了
ROS基础系列之【基本配置】– by Exbot_玄影游侠
配置ROS工作空间catkin+rosbuild
ROS每次执行命令都只能在一个工作空间中进行。
而工作空间需要配置一些东西,比如ROS命令运行需要包含的系统文件的路径,以及其他的一些配置。
如果每次在你每次打开terminal要执行ROS命令的时候,都要重新配置一次的话,就太麻烦了。这时,就需要一个脚本来执行上述繁琐的配置过程。
source setup.bash就是这个作用,如果你不知道source命令的含义,可以看一下这里
每次打开一个新的terminal,运行这个命令后,当前的terminal下就可以执行相应工作空间的ROS命令了。
如果你对setup.bash里面的内容感兴趣,可以去cd /opt/ros/hydro/(以hydro系统为例)文件夹下的setup.bash,以及setup.sh里面看一看。
具体需要source哪个setup.bash?
你在哪个工作空间执行ROS的命令,就需要source哪个工作空间的setup.bash,
例如在系统工作空间下,而你的系统是Hydro版本的话,就是
source /opt/ros/hydro/setup.bash
如果你新建并初始化了一个新的工作空间,则到你的新建的工作空间下的devel文件夹,并source相应的setup.bash文件。
关于source,以及工作空间的覆盖等概念,YuanboShe做了清晰的解释,请看这里(这里同时还有ROS中一些基本概念的讲解)。

另外在ROSWIKI里面有具体讲工作空间覆盖的问题:
catkin/Tutorials/workspace_overlaying

转载自原文链接, 如需删除请联系管理员。

原文链接:使用ROS遇到的一些小问题,转载请注明来源!

0