ROS_hydro_catkin创建工作空间~helloworld.cpp_rosrun/roslaunch
2015-11-28 23:31
591 查看
Create a ROS Workspace
Let's create acatkin workspace:
$ mkdir -p ~/catkin_ws/src $ cd ~/catkin_ws/src $ catkin_init_workspace
Even though the workspace is empty (there are no packages in the 'src' folder, just a singleCMakeLists.txt link) you can still "build" the workspace:
$ cd ~/catkin_ws/ $ catkin_make
The
catkin_make command is a convenience tool for working with
catkin workspaces. If you look in your current directory you should now have a 'build' and 'devel' folder. Inside the 'devel' folder you can see that there are now several setup.*sh files. Sourcing any of these files will overlay this workspace on top of
your environment. To understand more about this see the general catkin documentation:catkin. Before continuing source your new setup.*sh file:
$source devel/setup.bash
To make sure your workspace is properly overlayed by the setup script, make sureROS_PACKAGE_PATH environment variable
includes the directory you're in.
$ echo $ROS_PACKAGE_PATH /home/youruser/catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks
Now that your environment is setup
Creating a catkin Package
This tutorial will demonstrate how to use thecatkin_create_pkg script to create a new catkin package, and what you can do with it after it has been created.
First change to the source space directory of the catkin workspace you created in theCreating a Workspace for catkin tutorial:
# You should have created this in the Creating a Workspace Tutorial $ cd ~/catkin_ws/src
Now use the catkin_create_pkg script to create a new package called 'beginner_tutorials' which depends on std_msgs, roscpp, and rospy:
$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
This will create a beginner_tutorials folder which contains apackage.xml and aCMakeLists.txt,
which have been partially filled out with the information you gavecatkin_create_pkg.
catkin_create_pkg requires that you give it apackage_name and optionally a list of dependencies on which that package depends:
# This is an example, do not try to run this # catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
catkin_create_pkalities which is described incatkin/commands/catkin_create_pkg.
Building a catkin workspace and sourcing the setup file
Now you need to build the packages in the catkin workspace:$ cd ~/catkin_ws $ catkin_make
After the workspace has been built it has created a similar structure in thedevel subfolder as you usually find under/opt/ros/$ROSDISTRO_NAME.
To add the workspace to your ROS environment you need to source the generated setup file:
$ . ~/catkin_ws/devel/setup.bash
创建hello_world.cpp
cd ~/catkin_ws/src/beginner_tutorials/src
gedit hello_world.cpp
代码如下:
#include <ros/ros.h> int main(int argc, char** argv) { ros::init(argc, argv, "hello_meta_package_node"); ros::NodeHandle nh; ROS_INFO("Hello ROS!"); ros::spin(); }
CMakeLists.txt加入
add_executable(hello_world src/hello_world.cpp)
target_link_libraries(hello_world ${catkin_LIBRARIES} )
编译cpp即节点
cd ~/catkin_wscatkin_make
运行
rosrun beginner_tutorials hello_worldPS:若出现错误[rospack] Error: stack/package beginner_tutorials not found
类似错误都可以这样解决source devel/setup.bash
或者
$ cd ~
$gedit .bashrc
再后面加入两行
source /opt/ros/hydro/setup.bash
source /工作空间/devel/setup.bash
使用launch文件
$ roscdbeginner_tutorials
$ mkdir launch
$ cd launch
$gedit hello_world.launch
hello_world.launch内容:
<launch>
<node pkg="beginner_tutorials" name="hello_world" type="hello_world">
</node>
</launch>
roslaunch
beginner_tutorials hello_world.launch
为了看到信息,我们要打开 rqt_console
$ rqt_console
$roslaunch
beginner_tutorials hello_world.launch
参考:官网
http://blog.csdn.net/yaked/article/details/50083783 http://blog.csdn.net/sfe1012/article/details/42344041
相关文章推荐
- C语言开发总结(十六)
- 折纸问题 C++实现
- C语言实现简易通讯录
- C/C++对一个整数求出每一位的数值
- Effective c++学习笔记四
- C语言打印最长字符串
- C语言打印水平直方图或者垂直直方图
- C语言开发总结(十五)
- 【转】C语言中标识符的作用域、命名空间、链接属性、生命周期、存储类型
- C/C++整数除法以及保留小数位的问题
- 【简易通讯录】——C语言实现
- Visual Studio 2015 快捷键(C++篇可通用)
- C语言运算符小结
- C语言学习笔记1
- C++中单链表的建立
- C语言链表的操作和讲解
- 在YouCompleteMe+Syntastic中添加和取消对C++11的支持
- 【LeetCode从零单刷】Convert Sorted List to Binary Search Tree
- 编译原理(六) LL(1)文法分析法(分析过程的C++实现)
- [温故而知新] 《深度探索c++对象模型》——对象方法成员