转载请注明出处,谢谢。
本配置主要根据
http://wiki.ros.org/IDEs#Reusing_your_shell.27s_environment
在ubuntu上开发ROS,官网教程是使用Vim或者nano之类的,可对单个文本进行编辑,但是无法浏览整个项目结构,调试及运行也需要打开终端进行.
1.安装eclipse
官网下载安装,写这篇记录的时候电脑上已经安装好了,忘记了具体的安装流程,以后有机会再补上吧,可以肯定的是,安装阶段与ROS无关.
2.创建eclipse项目
此处有三种方法,根据所选编译器不同而不同,分别是rosbuild/catkin/catkin tools
我使用的是catkin,故参照教程2.2继续走
首先按照ROS官网教程创建一个workspace,例如catkin_ws,这个workspace之前使用过或者没使用过catkin_make无所谓.
cd catkin_ws
catkin_make --force-cmake -G"Eclipse CDT4 - Unix Makefiles"
再运行
awk -f $(rospack find mk)/eclipse.awk build/.project > build/.project_with_env && mv build/.project_with_env build/.project
之后,在build文件夹下就会有eclipse的工程了,这样就可以把工程导入到eclipse中了.
注意:如果你想在eclipse中进行debug,cd进入build文件夹,执行
cmake ../src -DCMAKE_BUILD_TYPE=Debug(亲测有效,如果不能顺利debug,就在eclipse中重新编译全部project)
eclipse和python相关设置,暂时没用到,以后用了再来补充.
3.把工程导入eclipse
File -> Import -> General -> Existing Projects into Workspace,
select a root directory,选择catkin_ws中的build文件夹,就会自动搜索.不要选择Copy projects into workspace.
这样就完成了项目的导入,但是还要修复一些依赖上的问题,一些C++文件会出现找不到函数的情况
解决办法:
官网列出了5条,我使用了其中一条,修改eclipse的相关设置.
-
In Eclipse, right click the project, click properties -> C/C++ general -> Preprocessor Include Paths, Macros etc. Click the tab "Providers" and check the box next to "CDT GCC Built-in Compiler Settings [ Shared ]".就是把providers那个tag下面对应的选项给勾选上.
-
Afterwards, right click the project, select Index -> Rebuild. This will rebuild your index. Once this is done, usually all includes will resolve.
-
As a last resort, you can also manually add folders that will be searched for headers, using right click project -> properties -> C/C++ Include Paths and Symbols. This is usually not necessary though.
4.在eclipse中进行编译
如果不能编译,查看环境变量设置:
Right click on the project, select Properties --> C/C++ Make Project --> Environment, and check whether the following environment variables are assigned to the correct values:
- ROS_ROOT
- ROS_PACKAGE_PATH
- PYTHONPATH
-
PATH
5.运行/Debug
by clicking on Run --> Run configurations... --> C/C++ Application (double click or click on New),
重点是选择二进制文件,一般在devel/lib文件夹下;运行哪个,就选择那个.
然后在environment选项卡中,添加
- ROS_ROOT
-
ROS_MASTER_URI
-
这两个环境变量,这两个环境变量可通过终端打印方式获得,echo $ROS_ROOT
之后重新编译全部!!!!就可以运行和Debug了
注意ROS_INFO用的是ANSI编码方式,可能会在Console中产生乱码,解决方法 http://mihai-nita.net/java/(http://www.mihai-nita.net/eclipse/)
我没有试过.
6.排版问题
-
下载配置文件:http://wiki.ros.org/IDEs?action=AttachFile&do=view&target=ROS_format.xml
- Start Eclipse
-
Select Window->Preferences->C/C++->Code Style->Formatter
-
Click Import...
-
Select ROS_format.xml from the location used in step 1
-
Click OK
-
别忘了点击apply
-
然后在eclipse中点击source->Format
经过一段时间使用,发现编辑xml和cmake文件时,编辑器没有对应的颜色支持,使用很麻烦,经过搜索,发现可以通过安装几个eclipse插件来解决这些问题。
安装插件的方法统一为:打开eclipse -> Help -> Install new Software->Add->name一栏空着 Location一栏写插件的地址,地址会在下文提供。
1.CMake Editor(编辑CMake文件)
http://cmakeed.sourceforge.net/eclipse/
装好后重启eclipse会发现Cmakelists文件图标变了,打开之后有了对应的颜色显示
2.Eclipse Color Theme
改编辑器背景颜色的
http://eclipse-color-theme.github.io/update/
设置:Window->Preferences->General->Appearance->Color Theme
3.PyDev for Eclipse
4.Rinzo XML Editor(编辑XML文件)
http://marketplace.eclipse.org/content/rinzo-xml-editor
安装方法稍有不同,在页面上,把install按钮拖到eclipse即可
5.YEdit Feature
http://marketplace.eclipse.org/content/yedit
安装方法同上