ROS知识(6)----基于Eclipse开发
2015-10-12 14:21
405 查看
可以利用Eclipse集成开发环境进行ROS开发,从而提高研发效率。以色列巴尔伊兰大学的Mr. Roi Yehoshua开设了一门ROS课程,课程2( Lesson 2)讲解了如何利用Eclipse在ROS上进行开发。这里走下总结整理。安装步骤如下:
1. 安装Eclipse
确保Java虚拟机JVM已经安装,如果没有安装,在终端执行以下的命令:
下载Eclipse IDE for C/C++开发平台:
----下载地址:http://www.eclipse.org/downloads/
----最新的Eclipse版本为:eclipse-cpp-luna-SR1-linux-gtk-x86_64.tar.gz
解压Eclipse到你指定的文件夹中。
在终端中,将Eclipse移到系统的目录 /opt,执行如下命令:
创建一个链接,以给所有的用户可以使用,执行如下命令:
为了方便,弄个Eclipse的快捷方式到桌面
添加如下内容:
–The bash –i - c command will cause your IDE's launcher icon to load your ROS-sourced shell environment before launching eclipse
2. 生成Eclipse项目文件
创建工作空间,执行如下代码:
创建一个包first_pkg,执行如下代码:
到catkin的工作空间,利用catkin_make命令,建立一个eclipse的项目,命令如下:
项目的文件声称在目录 ~/catkin_ws/build里。
3. 导入项目
启动 Eclipse
选择catkin_ws 文件夹作为工作空间文件夹:
选择File --> Import --> General --> Existing Projects into Workspace
从文件夹~/catkin_ws/build中导入项目
4. 添加预编译头文件的路径
默认情况下,Eclipse是不会只能识别到ROS的头文件信息的,为了修复它,作如下操作进行设置:
–到 Project Properties --> C/C++ General --> Preprocessor Include Paths, Macros, etc. --> Providers tab
–检查CDT GCC Built-in Compiler Settings [Shared]
设置以上步骤后,重新编译C/C++索引右击项目 project -> Index -> Rebuild
5. 项目结构
项目的源文件在文件夹 "Source directory"中,开发者可以在这个目录下添加源代码。
6. 添加项目文件
右击src,然后选择New –> Source File, 创建文件 hello.cpp,如下图所示:
小技巧,Eclipse自动补齐代码快捷键:Ctrl+Space
编写如下代码:
7. 编译节点
在编译前,需要在包的CMakeLists.txt文件中添加新的编译内容(红色部分),如下所示:
按快捷键 Ctrl-B,编译项目
8. 在Eclipse中运行节点
创建新的启动配置,点击 Run --> Run configurations... --> C/C++ Application (double click or click on New)。
选择相应的二进制执行程序 (use the Browse… button),如本例程的执行程序为:~/catkin_ws/devel/lib/first_pkg/hello。
确保roscore已经在终端中运行。
点击Run,结果如下图所示:
当然也可以在终端中运行。
9. 在Eclipse中调试
为了调试,你需要将编译器设置为调试模式,终端中,到catkin_ws/build目录执行如下代码:
重启Eclipse
这样就可以利用Eclipse的调试工具进行调试了,进入调试界面,如下图所示:
参考资料:
[1].89-685: Introduction to Robotics
[2].Lesson 2
1. 安装Eclipse
确保Java虚拟机JVM已经安装,如果没有安装,在终端执行以下的命令:
$sudo apt-get install default-jre
下载Eclipse IDE for C/C++开发平台:
----下载地址:http://www.eclipse.org/downloads/
----最新的Eclipse版本为:eclipse-cpp-luna-SR1-linux-gtk-x86_64.tar.gz
解压Eclipse到你指定的文件夹中。
在终端中,将Eclipse移到系统的目录 /opt,执行如下命令:
$sudo mv eclipse /opt
创建一个链接,以给所有的用户可以使用,执行如下命令:
$sudo ln -s /opt/eclipse/eclipse /usr/bin/eclipse
为了方便,弄个Eclipse的快捷方式到桌面
$sudo gedit /usr/share/applications/eclipse.desktop
添加如下内容:
[Desktop Entry] Name=Eclipse Type=Application Exec=bash -i -c "/opt/eclipse/eclipse" Terminal=false Icon=/opt/eclipse/icon.xpm Comment=Integrated Development Environment NoDisplay=false Categories=Development;IDE Name[en]=eclipse.desktop
–The bash –i - c command will cause your IDE's launcher icon to load your ROS-sourced shell environment before launching eclipse
2. 生成Eclipse项目文件
创建工作空间,执行如下代码:
$ mkdir -p ~/catkin_ws/src $ cd ~/catkin_ws/src $ catkin_init_workspace $ cd ~/catkin_ws $ catkin_make
创建一个包first_pkg,执行如下代码:
$ cd ~/catkin_ws/src $ catkin_create_pkg first_pkg std_msgs rospy roscpp
到catkin的工作空间,利用catkin_make命令,建立一个eclipse的项目,命令如下:
$ cd ~/catkin_ws $ catkin_make --force-cmake -G"Eclipse CDT4 - Unix Makefiles"
项目的文件声称在目录 ~/catkin_ws/build里。
3. 导入项目
启动 Eclipse
选择catkin_ws 文件夹作为工作空间文件夹:
选择File --> Import --> General --> Existing Projects into Workspace
从文件夹~/catkin_ws/build中导入项目
4. 添加预编译头文件的路径
默认情况下,Eclipse是不会只能识别到ROS的头文件信息的,为了修复它,作如下操作进行设置:
–到 Project Properties --> C/C++ General --> Preprocessor Include Paths, Macros, etc. --> Providers tab
–检查CDT GCC Built-in Compiler Settings [Shared]
设置以上步骤后,重新编译C/C++索引右击项目 project -> Index -> Rebuild
5. 项目结构
项目的源文件在文件夹 "Source directory"中,开发者可以在这个目录下添加源代码。
6. 添加项目文件
右击src,然后选择New –> Source File, 创建文件 hello.cpp,如下图所示:
小技巧,Eclipse自动补齐代码快捷键:Ctrl+Space
编写如下代码:
#include "ros/ros.h" int main(int argc, char **argv) { ros::init(argc, argv, "hello"); ros::NodeHandle nh; ros::Rate loop_rate(10); int count = 0; while (ros::ok()) // Keep spinning loop until user presses Ctrl+C { ROS_INFO_STREAM("hello world" << count); ros::spinOnce(); // Allow ROS to process incoming messages loop_rate.sleep(); // Sleep for the rest of the cycle count++; } return 0; }
7. 编译节点
在编译前,需要在包的CMakeLists.txt文件中添加新的编译内容(红色部分),如下所示:
cmake_minimum_required(VERSION 2.8.3) project(first_pkg) ## Find catkin macros and libraries find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs) ## Declare ROS messages and services # add_message_files(FILES Message1.msg Message2.msg) # add_service_files(FILES Service1.srv Service2.srv) ## Generate added messages and services # generate_messages(DEPENDENCIES std_msgs) ## Declare catkin package catkin_package() ## Specify additional locations of header files include_directories(${catkin_INCLUDE_DIRS}) ## Declare a cpp executable add_executable(hello src/hello.cpp) ## Specify libraries to link a library or executable target against target_link_libraries(hello ${catkin_LIBRARIES})
按快捷键 Ctrl-B,编译项目
8. 在Eclipse中运行节点
创建新的启动配置,点击 Run --> Run configurations... --> C/C++ Application (double click or click on New)。
选择相应的二进制执行程序 (use the Browse… button),如本例程的执行程序为:~/catkin_ws/devel/lib/first_pkg/hello。
确保roscore已经在终端中运行。
点击Run,结果如下图所示:
当然也可以在终端中运行。
9. 在Eclipse中调试
为了调试,你需要将编译器设置为调试模式,终端中,到catkin_ws/build目录执行如下代码:
$ cmake ../src -DCMAKE_BUILD_TYPE=Debug
重启Eclipse
这样就可以利用Eclipse的调试工具进行调试了,进入调试界面,如下图所示:
参考资料:
[1].89-685: Introduction to Robotics
[2].Lesson 2
相关文章推荐
- 反射机制
- spring aop中的propagation的7种配置的意思
- SpringMVC 源代码深度解析<context:component-scan>(扫描和注册的注解Bean)
- Spring+SpringMVC+mybatis+easyui整合实例(二)注解方式的mybatis的使用
- BaseService.java(Service业务层基类)
- Java工作记录
- java中线程的优先级
- Spring MVC: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]
- Spring+SpringMVC+mybatis+easyui整合实例(三)spring mvc整合及mybatis事务部分
- java(4)--集合类
- spring的初始化过程(以三个上下文关系为出发点)
- Android 系统源码导入 eclipse
- 配置Spring bean
- 用Java 8 Lambda表达式实现设计模式:命令模式
- 用Java 8 Lambda表达式实现设计模式:命令模式
- java 通过实现Runnable接口实现多线程
- 框架培训-第一日
- Java设计模式 —— 开篇
- java类型转换
- JIRA Rest JAVA Client API实现问题管理及自定义字段(原创)