使用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

發佈了40 篇原創文章 · 獲贊 153 · 訪問量 44萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章