Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/wwwroot/phxin.top/usr/themes/Joe/public/config.php on line 19

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/wwwroot/phxin.top/usr/themes/Joe/public/config.php on line 20

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/wwwroot/phxin.top/usr/themes/Joe/public/config.php on line 21

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/wwwroot/phxin.top/usr/themes/Joe/public/config.php on line 22

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/wwwroot/phxin.top/usr/themes/Joe/public/config.php on line 23
ROS流程--hello world - Hello World

ROS流程--hello world

清歌
2022-10-21 / 0 评论 / 0 阅读 / 正在检测是否收录...
1.创建工作空间并初始化
mkdir -p 自定义工作空间名称/src
cd 自定义空间名称
catkin_make

请输入图片描述

这里我命名工作空间名称为hello

2.进入 src 创建 ros 包并添加依赖
cd src
catkin_create_pkg 自定义ROS包名 roscpp rospy std_msgs

上述命令,会在工作空间下生成一个功能包,该功能包依赖于 roscpprospystd_msgs,其中roscpp是使用C++实现的库,而rospy则是使用python实现的库,std_msgs是标准消息库,创建ROS功能包时,一般都会依赖这三个库实现。
请输入图片描述

C++运行效率高但是编码效率低,而Python则反之,但是具体选择哪种语言,需要视需求而定。

3.进入 ros 包的 src 目录编辑源文件

请输入图片描述

4.在当前文件夹下生成c++文件
gedit hello_c.cpp

C++源码实现

#include "ros/ros.h"

int main(int argc, char *argv[])
{
    //执行 ros 节点初始化
    ros::init(argc,argv,"hello");
    //创建 ros 节点句柄(非必须)
    ros::NodeHandle n;
    //控制台输出 hello world
    ROS_INFO("hello world!");

    return 0;
}
5.编辑 ros 包下的 Cmakelist.txt文件
cd ..

找到136行与149行修改

add_executable(步骤4的源文件名
  src/步骤4的c++源文件名.cpp
)
target_link_libraries(步骤4的源文件名
  ${catkin_LIBRARIES}
)

请输入图片描述

6.进入工作空间目录并编译
cd cd 自定义工作空间名称
catkin_make

请输入图片描述

7.执行
roscore

再新建终端

cd 工作空间
source ./devel/setup.bash
rosrun 包名 C++节点

请输入图片描述

0

评论 (0)

取消