ros 下基本编程 hellp world_ros hello word

img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上物联网嵌入式知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、电子书籍、讲解视频,并且后续会持续更新

需要这些体系化资料的朋友,可以加我V获取:vip1024c (备注嵌入式)

如果你需要这些资料,可以戳这里获取

$ 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 the catkin_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
代码如下:

[cpp]
view plain
copy
print
?

  1. #include <ros/ros.h>
  2. int main(int argc, char** argv)
  3. {
  4. ros::init(argc, argv, “hello_meta_package_node”);
  5. ros::NodeHandle nh;
  6. ROS_INFO(“Hello ROS!”);
  7. ros::spin();
  8. }

CMakeLists.txt加入
add_executable(hello_world src/hello_world.cpp)

target_link_libraries(hello_world  ${catkin_LIBRARIES} )

编译cpp即节点

cd ~/catkin_ws

catkin_make

运行

rosrun beginner_tutorials hello_world

PS:若出现错误[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内容:

img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上物联网嵌入式知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、电子书籍、讲解视频,并且后续会持续更新

需要这些体系化资料的朋友,可以加我V获取:vip1024c (备注嵌入式)

如果你需要这些资料,可以戳这里获取

提升的进阶课程,涵盖了95%以上物联网嵌入式知识点,真正体系化!**

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、电子书籍、讲解视频,并且后续会持续更新

需要这些体系化资料的朋友,可以加我V获取:vip1024c (备注嵌入式)

如果你需要这些资料,可以戳这里获取

  • 12
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值