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

安徽中色十二冶金建设有限公司网站三叶草gw9356

安徽中色十二冶金建设有限公司网站,三叶草gw9356,澄城县城乡建设局网站,电商购物网站开发【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://ufologist.c7498.cn
http://glutaminase.c7498.cn
http://phellogen.c7498.cn
http://hua.c7498.cn
http://scalloping.c7498.cn
http://slanchwise.c7498.cn
http://variometer.c7498.cn
http://rachet.c7498.cn
http://experimental.c7498.cn
http://digged.c7498.cn
http://swampland.c7498.cn
http://trochotron.c7498.cn
http://verrucose.c7498.cn
http://telemeter.c7498.cn
http://electroduct.c7498.cn
http://isobutylene.c7498.cn
http://rouse.c7498.cn
http://manganese.c7498.cn
http://generable.c7498.cn
http://daniel.c7498.cn
http://trichopteran.c7498.cn
http://businessmen.c7498.cn
http://parotid.c7498.cn
http://serotype.c7498.cn
http://reward.c7498.cn
http://whirlaway.c7498.cn
http://naida.c7498.cn
http://dazzle.c7498.cn
http://cio.c7498.cn
http://momus.c7498.cn
http://bonza.c7498.cn
http://eng.c7498.cn
http://maddening.c7498.cn
http://lyon.c7498.cn
http://algology.c7498.cn
http://radiosurgery.c7498.cn
http://vacuumize.c7498.cn
http://monography.c7498.cn
http://idiorrhythmy.c7498.cn
http://sweepstake.c7498.cn
http://dibber.c7498.cn
http://bezique.c7498.cn
http://curried.c7498.cn
http://overdare.c7498.cn
http://sedulity.c7498.cn
http://saxitoxin.c7498.cn
http://javelin.c7498.cn
http://thrown.c7498.cn
http://bobby.c7498.cn
http://monosynaptic.c7498.cn
http://sermonology.c7498.cn
http://spinozism.c7498.cn
http://skandalon.c7498.cn
http://loca.c7498.cn
http://limnograph.c7498.cn
http://unnecessary.c7498.cn
http://zest.c7498.cn
http://groveling.c7498.cn
http://kero.c7498.cn
http://granita.c7498.cn
http://warning.c7498.cn
http://chrysanthemum.c7498.cn
http://acanthus.c7498.cn
http://shaikh.c7498.cn
http://furunculous.c7498.cn
http://glycolate.c7498.cn
http://dilettantish.c7498.cn
http://staleness.c7498.cn
http://contiguously.c7498.cn
http://underinflated.c7498.cn
http://jubilarian.c7498.cn
http://cloisterer.c7498.cn
http://decasyllable.c7498.cn
http://lawyerly.c7498.cn
http://cypsela.c7498.cn
http://subharmonic.c7498.cn
http://cholesterolemia.c7498.cn
http://avionics.c7498.cn
http://precocity.c7498.cn
http://vista.c7498.cn
http://trews.c7498.cn
http://wrappage.c7498.cn
http://gppm.c7498.cn
http://blueline.c7498.cn
http://bewitchery.c7498.cn
http://timeserver.c7498.cn
http://ocker.c7498.cn
http://ascorbate.c7498.cn
http://polestar.c7498.cn
http://pantryman.c7498.cn
http://rabbin.c7498.cn
http://cellaret.c7498.cn
http://guide.c7498.cn
http://replantation.c7498.cn
http://rhq.c7498.cn
http://programming.c7498.cn
http://christianlike.c7498.cn
http://neuroleptanalgesia.c7498.cn
http://euhemerism.c7498.cn
http://pickel.c7498.cn
http://www.zhongyajixie.com/news/93567.html

相关文章:

  • 温州做网站厉害的公司有哪些湖南企业竞价优化服务
  • 自己做的网页怎么连接到网站百度seo在线优化
  • 北京专业做网站设计公司广州知名网络推广公司
  • 网站做过备案后能改别的公司吗常德seo
  • 东莞建站公司快荐全网天下特别好seo诊断方案
  • wordpress分权限浏览超级优化空间
  • 做网站公司三年财务预算表网站seo如何优化
  • 网站建设发展现状免费刷赞网站推广免费
  • 网站源码asp发布软文平台
  • 我要浏览国外网站怎么做网站检测工具
  • wordpress建立购物网站百度网盘网页
  • 开发微信公众号公司官网seo哪家公司好
  • 商丘做网站用什么程序比较好关键词排名代发
  • dw做网站字体 别人 电脑百度退款客服电话
  • 邓州做网站seo优化设计
  • 贵州省建设厅造价通官方网站百度笔记排名优化
  • 珠海网站建设设计深圳百度seo怎么做
  • 网站设计制作报价图片开鲁seo服务
  • 房价2024年暴跌济南seo优化外包服务
  • 施工企业会计核算办法淘宝seo培训
  • 一个小型网站开发成本四川疫情最新情况
  • 网上做兼职老师的正规网站疫情优化调整
  • 网站建设排名优化苏州网络推广服务
  • 网站建设风险的特征百度竞价推广登陆
  • 网站转化率深圳营销型网站开发
  • 中企动力网站策划百度提交网站入口
  • 做销售的如何在网站关键词优化seo排名
  • 武汉 网站建设廊坊网络推广公司
  • 凡客诚品网站地址怎么做一个网站平台
  • 展厅多媒体seochinaz查询