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

  1. cmake_minimum_required(VERSION 2.8.3)
  2. project(nodelet_test_pkg)
  3. find_package(catkin REQUIRED COMPONENTS nodelet roscpp std_msgs)#
  4. ## Setup include directories
  5. include_directories(${catkin_INCLUDE_DIRS})
  6. catkin_package(
  7. )
  8. add_library(nodelet_test plus.cpp)
  9. target_link_libraries(nodelet_test ${catkin_LIBRARIES})

package.xml

  1. <package>
  2. <name>nodelet_test_pkg</name>
  3. <version>0.0.0</version>
  4. <description>Nodelet test.</description>
  5. <maintainer email="huasheng_zyh@163.com">kint zhao</maintainer>
  6. <license>BSD</license>
  7. <buildtool_depend>catkin</buildtool_depend>
  8. <build_depend>nodelet</build_depend>
  9. <build_depend>roscpp</build_depend>
  10. <build_depend>std_msgs</build_depend>
  11. <run_depend>nodelet</run_depend>
  12. <run_depend>roscpp</run_depend>
  13. <run_depend>std_msgs</run_depend>
  14. <export>
  15. <nodelet plugin="${prefix}/nodelet_test_plugin.xml"/>
  16. </export>
  17. </package>
plugin
  1. <library path="lib/libnodelet_test_lib">
  2. <class name="nodelet_ns/Plus" type="nodelet_ns::Plus" base_class_type="nodelet::Nodelet">
  3. <description>
  4. A node to add a value and republish.
  5. </description>
  6. </class>
  7. </library>

launch

  1. <launch>
  2. <node pkg="nodelet" type="nodelet" name="manager_1"  args="manager" output="screen"/>
  3. <node pkg="nodelet" type="nodelet" name="test1" args="load nodelet_ns/Plus manager_1" output="screen"/>
  4. <node pkg="nodelet" type="nodelet" name="test2" args="load nodelet_ns/Plus manager_1" output="screen"/>
  5. <node pkg="nodelet" type="nodelet" name="test3" args="load nodelet_ns/Plus manager_1" output="screen"/>
  6. <node pkg="nodelet" type="nodelet" name="manager_2"  args="manager" output="screen"/>
  7. <node pkg="nodelet" type="nodelet" name="test4" args="load nodelet_ns/Plus manager_2" output="screen"/>
  8. <node pkg="nodelet" type="nodelet" name="test5" args="load nodelet_ns/Plus manager_2" output="screen"/>
  9. <node pkg="nodelet" type="nodelet" name="test6" args="standalone nodelet_ns/Plus " output="screen"/>
  10. </launch>

.cpp文件

  1. #include <pluginlib/class_list_macros.h>
  2. #include <nodelet/nodelet.h>
  3. #include <ros/ros.h>
  4. #include <std_msgs/Float64.h>
  5. #include <stdio.h>
  6. #include <math.h> //fabs
  7. namespace nodelet_ns
  8. {
  9. class Plus : public nodelet::Nodelet
  10. {
  11. public:
  12. Plus()
  13. : value_(0)
  14. {}
  15. private:
  16. virtual void onInit()
  17. {
  18. ros::NodeHandle& private_nh = getPrivateNodeHandle();
  19. private_nh.getParam("value", value_);
  20. pub = private_nh.advertise<std_msgs::Float64>("out", 10);
  21. sub = private_nh.subscribe("in", 10, &Plus::callback, this);
  22. }
  23. void callback(const std_msgs::Float64::ConstPtr& input)
  24. {
  25. std_msgs::Float64Ptr output(new std_msgs::Float64());
  26. output->data = input->data + value_;
  27. NODELET_DEBUG("Adding %f to get %f", value_, output->data);
  28. pub.publish(output);
  29. }
  30. ros::Publisher pub;
  31. ros::Subscriber sub;
  32. double value_;
  33. };
  34. PLUGINLIB_DECLARE_CLASS(nodelet_ns, Plus, nodelet_ns::Plus, nodelet::Nodelet);//*******
  35. }



nodelet的应用的更多相关文章

  1. ROS nodelet的使用

    ROS是一种基于分布式网络通讯的操作系统,整个机器人控制系统是由一个Master主节点和若干个功能相对独立的Node子节点组成,这也是ROS系统最主要的特点就是分布式以及模块化的设计.在ROS通讯过程 ...

  2. ros nodelet 使用

    ros nodelet能够加快高吞吐量程序运行速度比如点云 基本入门程序可以看 http://wiki.ros.org/nodelet/Tutorials/Porting%20nodes%20to%2 ...

  3. nodelet的理解

    1.介绍 nodelet包可以为在相同进程中的多个算法之间实现零拷贝的传输方式. 这个包也提供了实现一个nodelet所需的nodelet基类以及用于实例化nodelet的NodeletLoader类 ...

  4. 第十九课 pluginlib&Nodelet

    把rgb摄像头的数据转换为laser的时候使用了Nodelet. pluginlib(插件库) 在ros中有一个plugin的包,下面是一个ROS Plugin Registration的例子 上面包 ...

  5. ROS nodelet 理解记录

    发现网上许多的例子都是基于官网的例子,还需要做进一步的说明. 1. NODELET_DEBUG 是无法打印的信息的,需要使用NODELET_INFO NODELET_DEBUG("Addin ...

  6. movebase导航

    利用turtlebot 的导航配置文件 由于movbase发的速度太不友好了所以使用了ros自带的滤波安装相应的包 apt-get install ros-indigo-yocs-velocity-s ...

  7. 利用move_base导航--42

    摘要: 原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 各位博友好长时间又没有写博客了,突然发现上班和在学校是不一样的,在公司的却没有时间写博客了,不过 ...

  8. PCL Nodelets 和 3D 点云---36

    原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 1.首先确保你的kinect驱动或者uvc相机驱动能正常启动,如果你没有安装kinect深度相机驱动,请 ...

  9. ubuntu14.04 and ros indigo install kinect driver--16

    摘要: 原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ 今日多次测设ros indigo install kinect driver ,提示各种失败,然 ...

随机推荐

  1. Swift-自定制带有特殊按钮TabBar

    ---恢复内容开始--- 封装了一个带有中间凸起的自定制Tabbar,包含4个普通按钮和中间的一个凸起按钮- 首先封装了一个UIButton,重新设置了UIButton的图片位置和label位置 使用 ...

  2. bzoj 4032 [HEOI2015]最短不公共子串——后缀自动机

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4032 不是 b 的子串的话就对 b 建后缀自动机,在 a 上枚举从每个位置开始的子串或者找子 ...

  3. gen already exists but is not a source folder

    遇到android项目导入出现后重复空包等错误,往往是导入的java编译级别有关,点击项目properties-> java Compiler ->修改Compiler complianc ...

  4. 遍历listmap 遍历map

    package excel; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import j ...

  5. Maven入门----MyEclipse创建maven项目(二)

    新建项目: Next next next 新建项目后,MyEclipse会自动从远程仓库中下载支持包,需要几分钟左右时间. 项目结构图: HelloWorld.java public class He ...

  6. web.config 权限设置

    <system.web> <authorization> <!--未登陆用户不可以访问--> <deny users="?" /> ...

  7. Redis存储AccessToken

    AccessToken 2小时有效. 就不要每次都调取了,这样会造成浪费. 或者存入Session中,设置过期时间. 或者存入Redis中,设置过期时间. 过期之后,进行重新获取. <?php ...

  8. srvctl和crs_start命令无法启动oracle RAC实例, 但sqlplus可以启动

    今天遇到一个奇怪问题,发现srvctl和crs_start命令无法启动Oracle RAC实例,但用sqlplus却可以正常启动.最终发现原因是在OCR中数据库的状态变成了disable,将此状态更改 ...

  9. 自定义ListView里面的Item的内容

    我们不可能满足只是往每个item里面填字就足够,像QQ的好友列表就是一个ListView,每个Item里面有头像.名字啊.签名什么的,内容丰富.那我们要怎么定义一个内容丰富的item呢? 要用到Ada ...

  10. JS判断IE,FF,Opera,Safari等浏览器类型

    第一种,只区分浏览器,不考虑版本 function myBrowser(){ var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var ...