nodelet的应用
1.创建一个包,如example_pkg
catkin_create_pkg example_pkg
2.创建MyNodeletClass.h文件
cd ~/catkin_ws/src/example_pkg/
mkdir -p include/example_pkg
touch include/example_pkg/MyNodeletClass.h
vim include/example_pkg/MyNodeletClass.h
其内容为
#include <nodelet/nodelet.h>
namespace example_pkg
{
class MyNodeletClass : public nodelet::Nodelet
{
public:
virtual void onInit();
};
}
3.创建MyNodeletClass.cpp文件
cd ~/catkin_ws/src/example_pkg/
mkdir src
touch src/MyNodeletClass.cpp
vim src/MyNodeletClass.cpp
其内容为
// this should really be in the implementation (.cpp file)
#include <ros/ros.h>
#include <pluginlib/class_list_macros.h>
#include <example_pkg/MyNodeletClass.h> namespace example_pkg
{
void MyNodeletClass::onInit()
{
NODELET_DEBUG("Initializing nodelet...");
ROS_INFO("Nodelet is Ok for test!!");
}
} // watch the capitalization carefully
PLUGINLIB_DECLARE_CLASS(example_pkg, MyNodeletClass, example_pkg::MyNodeletClass, nodelet::Nodelet)
成功则输出"Nodelet is Ok for test!!"
4.创建nodelet_plugins.xml文件
cd ~/catkin_ws/src/example_pkg/
mkdir plugins
touch plugins/nodelet_plugins.xml
vim plugins/nodelet_plugins.xml
其内容为
<library path="lib/libexample_pkg">
<class name="example_pkg/MyNodeletClass" type="example_pkg::MyNodeletClass" base_class_type="nodelet::Nodelet">
<description>
This is my nodelet.
</description>
</class>
</library>
5.修改package.xml文件,增加:
cd ~/catkin_ws/src/example_pkg/
vim package.xml
其内容为
<buildtool_depend>catkin</buildtool_depend>
<build_depend>nodelet</build_depend>
<build_depend>roscpp</build_depend>
<run_depend>nodelet</run_depend>
<run_depend>roscpp</run_depend>
<!-- The export tag contains other, unspecified, tags -->
<export>
<!-- Other tools can request additional information be placed here -->
<nodelet plugin="${prefix}/plugins/nodelet_plugins.xml" />
</export>
6.修改CMakeLists.txt
cd ~/catkin_ws/src/example_pkg
vim CMakeLists.txt
其内容为
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
## Declare a C++ library
add_library(${PROJECT_NAME} src/MyNodeletClass.cpp)
add_dependencies(${PROJECT_NAME}
${${PROJECT_NAME}_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS}
)
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
)
6.创建mynodelet.launch文件
d ~/catkin_ws/src/example_pkg/
mkdir launch
touch launch/mynodelet.launch
vim launch/mynodelet.launch
其内容为
<launch>
<node pkg="nodelet" type="nodelet" name="standalone_nodelet" args="manager" output="screen"/>
<node pkg="nodelet" type="nodelet" name="MyNodeletClass" args="load example_pkg/MyNodeletClass standalone_nodelet" output="screen">
</node>
</launch>
6.编译
cd ~/catkin_ws/
catkin_make
rospack profile
7.运行
- 新终端,运行roscore
$ roscore
- 新终端,运行launch
$ rosluanch examples_pkg mynodelet.launch
参考:
http://www.ncnynl.com/archives/201702/1326.html
http://blog.csdn.net/zhangrelay/article/details/62048915
http://rosclub.cn/post-164.html
http://blog.csdn.net/yiranhaiziqi/article/details/53308657
http://www.lai18.com/content/2386868.html
例子
http://blog.csdn.net/zyh821351004/article/details/52143309
创建包nodelet_test,依赖项nodelet roscpp std_msgs
CMakeLists.txt
- cmake_minimum_required(VERSION 2.8.3)
- project(nodelet_test_pkg)
- find_package(catkin REQUIRED COMPONENTS nodelet roscpp std_msgs)#
- ## Setup include directories
- include_directories(${catkin_INCLUDE_DIRS})
- catkin_package(
- )
- add_library(nodelet_test plus.cpp)
- target_link_libraries(nodelet_test ${catkin_LIBRARIES})
package.xml
- <package>
- <name>nodelet_test_pkg</name>
- <version>0.0.0</version>
- <description>Nodelet test.</description>
- <maintainer email="huasheng_zyh@163.com">kint zhao</maintainer>
- <license>BSD</license>
- <buildtool_depend>catkin</buildtool_depend>
- <build_depend>nodelet</build_depend>
- <build_depend>roscpp</build_depend>
- <build_depend>std_msgs</build_depend>
- <run_depend>nodelet</run_depend>
- <run_depend>roscpp</run_depend>
- <run_depend>std_msgs</run_depend>
- <export>
- <nodelet plugin="${prefix}/nodelet_test_plugin.xml"/>
- </export>
- </package>
plugin
- <library path="lib/libnodelet_test_lib">
- <class name="nodelet_ns/Plus" type="nodelet_ns::Plus" base_class_type="nodelet::Nodelet">
- <description>
- A node to add a value and republish.
- </description>
- </class>
- </library>
launch
- <launch>
- <node pkg="nodelet" type="nodelet" name="manager_1" args="manager" output="screen"/>
- <node pkg="nodelet" type="nodelet" name="test1" args="load nodelet_ns/Plus manager_1" output="screen"/>
- <node pkg="nodelet" type="nodelet" name="test2" args="load nodelet_ns/Plus manager_1" output="screen"/>
- <node pkg="nodelet" type="nodelet" name="test3" args="load nodelet_ns/Plus manager_1" output="screen"/>
- <node pkg="nodelet" type="nodelet" name="manager_2" args="manager" output="screen"/>
- <node pkg="nodelet" type="nodelet" name="test4" args="load nodelet_ns/Plus manager_2" output="screen"/>
- <node pkg="nodelet" type="nodelet" name="test5" args="load nodelet_ns/Plus manager_2" output="screen"/>
- <node pkg="nodelet" type="nodelet" name="test6" args="standalone nodelet_ns/Plus " output="screen"/>
- </launch>
.cpp文件
- #include <pluginlib/class_list_macros.h>
- #include <nodelet/nodelet.h>
- #include <ros/ros.h>
- #include <std_msgs/Float64.h>
- #include <stdio.h>
- #include <math.h> //fabs
- namespace nodelet_ns
- {
- class Plus : public nodelet::Nodelet
- {
- public:
- Plus()
- : value_(0)
- {}
- private:
- virtual void onInit()
- {
- ros::NodeHandle& private_nh = getPrivateNodeHandle();
- private_nh.getParam("value", value_);
- pub = private_nh.advertise<std_msgs::Float64>("out", 10);
- sub = private_nh.subscribe("in", 10, &Plus::callback, this);
- }
- void callback(const std_msgs::Float64::ConstPtr& input)
- {
- std_msgs::Float64Ptr output(new std_msgs::Float64());
- output->data = input->data + value_;
- NODELET_DEBUG("Adding %f to get %f", value_, output->data);
- pub.publish(output);
- }
- ros::Publisher pub;
- ros::Subscriber sub;
- double value_;
- };
- PLUGINLIB_DECLARE_CLASS(nodelet_ns, Plus, nodelet_ns::Plus, nodelet::Nodelet);//*******
- }
nodelet的应用的更多相关文章
- ROS nodelet的使用
ROS是一种基于分布式网络通讯的操作系统,整个机器人控制系统是由一个Master主节点和若干个功能相对独立的Node子节点组成,这也是ROS系统最主要的特点就是分布式以及模块化的设计.在ROS通讯过程 ...
- ros nodelet 使用
ros nodelet能够加快高吞吐量程序运行速度比如点云 基本入门程序可以看 http://wiki.ros.org/nodelet/Tutorials/Porting%20nodes%20to%2 ...
- nodelet的理解
1.介绍 nodelet包可以为在相同进程中的多个算法之间实现零拷贝的传输方式. 这个包也提供了实现一个nodelet所需的nodelet基类以及用于实例化nodelet的NodeletLoader类 ...
- 第十九课 pluginlib&Nodelet
把rgb摄像头的数据转换为laser的时候使用了Nodelet. pluginlib(插件库) 在ros中有一个plugin的包,下面是一个ROS Plugin Registration的例子 上面包 ...
- ROS nodelet 理解记录
发现网上许多的例子都是基于官网的例子,还需要做进一步的说明. 1. NODELET_DEBUG 是无法打印的信息的,需要使用NODELET_INFO NODELET_DEBUG("Addin ...
- movebase导航
利用turtlebot 的导航配置文件 由于movbase发的速度太不友好了所以使用了ros自带的滤波安装相应的包 apt-get install ros-indigo-yocs-velocity-s ...
- 利用move_base导航--42
摘要: 原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 各位博友好长时间又没有写博客了,突然发现上班和在学校是不一样的,在公司的却没有时间写博客了,不过 ...
- PCL Nodelets 和 3D 点云---36
原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 1.首先确保你的kinect驱动或者uvc相机驱动能正常启动,如果你没有安装kinect深度相机驱动,请 ...
- ubuntu14.04 and ros indigo install kinect driver--16
摘要: 原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ 今日多次测设ros indigo install kinect driver ,提示各种失败,然 ...
随机推荐
- [CSU1911]Card Game
vjudge 题意 两个数组\(\{a_i\}\)和\(\{b_i\}\),求从中分别选出两个数或运算结果为\(x\)的方案数. sol 裸的FWT. code #include<cstdio& ...
- ACM学习历程—HDU5701 中位数计数(中位数 && 计数排序)
http://acm.hdu.edu.cn/showproblem.php?pid=5701 这是这次百度之星初赛2B的第六题.之前白山云做过类似的题,省赛完回来,我看了一下大概就有这样的思路:首先枚 ...
- UVA11168 Airport
题意 PDF 分析 首先发现距离最短的直线肯定在凸包上面. 然后考虑直线一般方程\(Ax+By+C=0\),点\((x_0,y_0)\)到该直线的距离为 \[ \frac{|Ax_0+By_0+C|} ...
- AVAWEB学习笔记 ---- 系列文章
[JAVAWEB学习笔记]网上商城实战5:后台的功能模块 [JAVAWEB学习笔记]网上商城实战4:订单模块 [JAVAWEB学习笔记]网上商城实战3:购物模块和订单模块 [JAVAWEB学习笔记]网 ...
- HashMap源码分析(基于JDK1.6)
在Java集合类中最常用的除了ArrayList外,就是HashMap了.本文尽自己所能,尽量详细的解释HashMap的源码.一山还有一山高,有不足之处请之处,定感谢指定并及时修正. 在看Hash ...
- (转)java中查找List的快捷小方法
相信java开发的程序员,经常会遍历list里的数据,来查找想要的数据.之后选出来在做处理,我这有个小方法在大量数据的情况下能更快捷,当然这方法只对菜鸟有点用,对老鸟来说也许有更好的方法,请指点 遍历 ...
- 定时任务&&找出两个list的不同
/*-------------------------application-context.xml------------------------------*/ <?xml version= ...
- Python 字典 列表 嵌套 复杂排序大全
https://blog.csdn.net/ray_up/article/details/42084863 一: 字典排序 解析: 使用sorted 方法, 排序后的结果为一个元组. 可以字符串排序( ...
- slabtop 监控实时内核片缓存信息
使用 slabtop命令监控实时内核片缓存信息 默认情况下,sl ...
- Linux Change The I/O Scheduler For A Hard Disk
ow do I change the I/O scheduler for a particular hard disk without rebooting my Linux server system ...