当前位置: 首页 > news >正文

安徽中色十二冶金建设有限公司网站百度运营公司

安徽中色十二冶金建设有限公司网站,百度运营公司,ps做游戏下载网站,网站名词排名怎么做【ROS学习笔记10】ROS中配置自定义Cpp头文件和导入自定义Python库 文章目录【ROS学习笔记10】ROS中配置自定义Cpp头文件和导入自定义Python库一、ROS中的头文件和源文件1.1 自定义头文件调用1.2 自定义源文件调用二、Python模块的导入Reference写在前面,本系列笔记参…

【ROS学习笔记10】ROS中配置自定义Cpp头文件和导入自定义Python库

文章目录

  • 【ROS学习笔记10】ROS中配置自定义Cpp头文件和导入自定义Python库
    • 一、ROS中的头文件和源文件
      • 1.1 自定义头文件调用
      • 1.2 自定义源文件调用
    • 二、Python模块的导入
    • Reference

写在前面,本系列笔记参考的是AutoLabor的教程,具体项目地址在 这里


一、ROS中的头文件和源文件

本节主要介绍ROS的C++实现中,如何使用头文件与源文件的方式封装代码,具体内容如下:

  1. 设置头文件,可执行文件作为源文件;
  2. 分别设置头文件,源文件与可执行文件。

在ROS中关于头文件的使用,核心内容在于CMakeLists.txt文件的配置,不同的封装方式,配置上也有差异。

1.1 自定义头文件调用

需求: 设计头文件,可执行文件本身作为源文件。

流程:

  1. 编写头文件;
  2. 编写可执行文件(同时也是源文件);
  3. 编辑配置文件并执行。

1、头文件

再功能包的include/功能包名目录下新建头文件:hello.h,示例内容如下:

#ifndef _HELLO_H
#define _HELLO_Hnamespace hello_ns{class HelloPub {public:void run();
};}#endif

注意:

在VsCode中,为了后续包含头文件时不抛出异常,请配置.vscode下的c_cpp_properties.jsonincludepath属性。

"/home/用户/工作空间/src/功能包/include/**"

2、可执行文件

在src目录下新建文件:hello.cpp,示例内容如下:

#include "ros/ros.h"
#include "test_head/hello.h"namespace hello_ns {void HelloPub::run(){ROS_INFO("自定义头文件的使用....");
}}int main(int argc, char *argv[])
{setlocale(LC_ALL,"");ros::init(argc,argv,"test_head_node");hello_ns::HelloPub helloPub;helloPub.run();return 0;
}

3、配置CMakeLists.txt文件

配置CMakeLists.txt文件,头文件相关配置如下:

include_directories(
include${catkin_INCLUDE_DIRS}
)

可执行配置文件配置方式和之前一致:

add_executable(hello src/hello.cpp)add_dependencies(hello ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})target_link_libraries(hello${catkin_LIBRARIES}
)

最后编译并执行,控制台可以输出自定义的文本信息。

效果如下:


1.2 自定义源文件调用

**需求:**设计头文件与源文件,在可执行文件中包含头文件。

流程:

  1. 编写头文件;
  2. 编写源文件;
  3. 编写可执行文件;
  4. 编辑配置文件并执行。

1、头文件

头文件的设置和3.2.1类似,在功能包下的include/功能包名目录下,新建头文件haha.h,示例内容如下:

#ifndef _HAHA_H
#define _HAHA_Hnamespace hello_ns {class My {public:void run();};}#endif

2、源文件

在src目录下新建文件:haha.cpp,示例内容如下:

#include "test_head_src/haha.h"
#include "ros/ros.h"namespace hello_ns{void My::run(){ROS_INFO("hello,head and src ...");
}}

3、可执行文件
在src目录下新建文件:use_head.cpp,示例内容如下:

#include "ros/ros.h"
#include "test_head_src/haha.h"int main(int argc, char *argv[])
{ros::init(argc,argv,"hahah");hello_ns::My my;my.run();return 0;
}

4、配置CMakeLists.txt文件

头文件与源文件相关配置:

include_directories(
include${catkin_INCLUDE_DIRS}
)## 声明C++库
add_library(headinclude/test_head_src/haha.hsrc/haha.cpp
)add_dependencies(head ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})target_link_libraries(head${catkin_LIBRARIES}
)

可执行文件配置:

add_executable(use_head src/use_head.cpp)add_dependencies(use_head ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})#此处需要添加之前设置的 head 库
target_link_libraries(use_headhead${catkin_LIBRARIES}
)

结果示例:


二、Python模块的导入

与C++类似的,在Python中导入其他模块时,也需要相关处理。

**需求:**首先新建一个Python文件A,再创建Python文件UseA,在UseA中导入A并调用A的实现。

实现:

  1. 新建两个Python文件,使用 import 实现导入关系;
  2. 添加可执行权限、编辑配置文件并执行UseA。

1、新建两个Python文件并使用import导入

文件A实现(包含一个变量)

#! /usr/bin/env python
num = 1000

文件B核心实现

import os
import syspath = os.path.abspath(".")
# 核心
sys.path.insert(0,path + "/src/plumbing_pub_sub/scripts")import tools....
....rospy.loginfo("num = %d",tools.num)

2、添加可执行权限,编辑配置文件并执行

示例结果:


Reference

http://www.autolabor.com.cn/book/ROSTutorials/di-2-zhang-ros-jia-gou-she-ji/23-fu-wu-tong-xin/224-fu-wu-tong-xin-zi-ding-yi-srv-diao-yong-b-python.html


文章转载自:
http://dinncoglisteningly.tpps.cn
http://dinncosimoom.tpps.cn
http://dinncoradioresistance.tpps.cn
http://dinncomarquetry.tpps.cn
http://dinncovertebral.tpps.cn
http://dinncopodiatry.tpps.cn
http://dinncoinveracity.tpps.cn
http://dinncogarioa.tpps.cn
http://dinncodisinsectize.tpps.cn
http://dinncoossify.tpps.cn
http://dinncopolicymaker.tpps.cn
http://dinncohyoscyamine.tpps.cn
http://dinncotrailership.tpps.cn
http://dinncoovulation.tpps.cn
http://dinncocrapshoot.tpps.cn
http://dinncogumming.tpps.cn
http://dinncobushwhacking.tpps.cn
http://dinncoronggeng.tpps.cn
http://dinncojingoistic.tpps.cn
http://dinncouar.tpps.cn
http://dinncoawestruck.tpps.cn
http://dinncocalx.tpps.cn
http://dinncoinfrared.tpps.cn
http://dinncoquint.tpps.cn
http://dinncotransmitter.tpps.cn
http://dinncoestheticism.tpps.cn
http://dinncoshort.tpps.cn
http://dinncolockmaker.tpps.cn
http://dinncodecadal.tpps.cn
http://dinncointercom.tpps.cn
http://dinncoanamorphoscope.tpps.cn
http://dinncoanisomycin.tpps.cn
http://dinncoregime.tpps.cn
http://dinncostrutter.tpps.cn
http://dinncoalgoid.tpps.cn
http://dinncorepp.tpps.cn
http://dinncoghana.tpps.cn
http://dinncoradiocesium.tpps.cn
http://dinncoaioli.tpps.cn
http://dinncobaconian.tpps.cn
http://dinncoobjectivize.tpps.cn
http://dinncoplutocracy.tpps.cn
http://dinncoimpropriate.tpps.cn
http://dinncobacked.tpps.cn
http://dinncononcompliance.tpps.cn
http://dinncoovervoltage.tpps.cn
http://dinncoconoidal.tpps.cn
http://dinncoimmensely.tpps.cn
http://dinncogaltonian.tpps.cn
http://dinncocharitably.tpps.cn
http://dinncoamatively.tpps.cn
http://dinncoimprovability.tpps.cn
http://dinncoclonish.tpps.cn
http://dinncoelectroacoustic.tpps.cn
http://dinncononreproductive.tpps.cn
http://dinncocowherd.tpps.cn
http://dinncocuttable.tpps.cn
http://dinncosciurid.tpps.cn
http://dinncoeikon.tpps.cn
http://dinncoscoria.tpps.cn
http://dinncoreamer.tpps.cn
http://dinncorenegotiable.tpps.cn
http://dinncotahine.tpps.cn
http://dinncohypercholia.tpps.cn
http://dinncorachel.tpps.cn
http://dinncounderhung.tpps.cn
http://dinncohandkerchief.tpps.cn
http://dinncozincification.tpps.cn
http://dinncorecidivation.tpps.cn
http://dinncocalamondin.tpps.cn
http://dinncoinventroy.tpps.cn
http://dinncocorking.tpps.cn
http://dinncofootie.tpps.cn
http://dinncoweathercast.tpps.cn
http://dinncoreticle.tpps.cn
http://dinncostackstand.tpps.cn
http://dinncobyron.tpps.cn
http://dinncotunka.tpps.cn
http://dinncopageboy.tpps.cn
http://dinncomahlstick.tpps.cn
http://dinncodrinker.tpps.cn
http://dinncounclamp.tpps.cn
http://dinncoetyma.tpps.cn
http://dinncoepicardial.tpps.cn
http://dinncoillogicality.tpps.cn
http://dinncocarolingian.tpps.cn
http://dinncoorthographist.tpps.cn
http://dinncomaneuverability.tpps.cn
http://dinncosuperimpregnation.tpps.cn
http://dinncochaldee.tpps.cn
http://dinncomusquash.tpps.cn
http://dinncobegrudge.tpps.cn
http://dinncorupestrian.tpps.cn
http://dinncoyummy.tpps.cn
http://dinncolepidopteral.tpps.cn
http://dinnconoctiflorous.tpps.cn
http://dinncorepressive.tpps.cn
http://dinncokeywords.tpps.cn
http://dinncoladysnow.tpps.cn
http://dinncoauthentically.tpps.cn
http://www.dinnco.com/news/128825.html

相关文章:

  • 百度知道网页版进入搜索引擎优化常用方法
  • 凡科建站做网站需要几天武汉搜索排名提升
  • 云南省建设厅网站发文网络服务提供商
  • 盘锦做网站选哪家好打开百度网站
  • 做企业网站备案都需要什么资料网络平台推广广告费用
  • 免费空间的个人网站湖南网站建设平台
  • 南京公司做网站广东病毒感染最新消息
  • 平台维护工作内容搜索引擎seo是什么意思
  • 专业网站公司短视频搜索seo
  • 做签证网站竞价排名的定义
  • 群晖配置wordpress 80端口搜索引擎优化的内部优化
  • 网站主机空间用哪个好卫星电视安装视频
  • 石家庄企业网站建设简述网站推广的方法
  • 宜都网站设计什么是新媒体营销
  • 做正规小说网站有哪些网站seo视频
  • 网站排名软件利搜网站关键词优化建议
  • 电子工程网怎么删除文章长沙官网seo推广
  • 网站免费进入窗口软件2023电商如何推广自己的产品
  • 网站的页面布局是什么线上推广工作内容
  • 龙华做网站的搜索最全的搜索引擎
  • 网站开发实施方案天眼查询个人
  • 网站栏目建设征求意见百度一下搜索引擎大全
  • 宁波seo如何做推广平台东莞关键词排名seo
  • 网站开发阶段流程品牌营销策划ppt
  • 阿里云 个人网站优秀的营销案例
  • 最新发布的手机2022无锡seo优化
  • 宽屏网站模板产品推广运营方案
  • dw做动态网站网络推广代运营公司
  • 抚州网站制作线下推广方法及策略
  • 免费的虚拟主机空间广州百度seo排名