ros nodelet能够加快高吞吐量程序运行速度比如点云

基本入门程序可以看

http://wiki.ros.org/nodelet/Tutorials/Porting%20nodes%20to%20nodelets

http://wiki.ros.org/nodelet

什么是nodelet,nodelet有什么用处

https://answers.ros.org/question/230972/what-is-a-nodelet/

代码框架:

class pcl_process_class
{
class MyPointCloudGeneratorNodelet : public nodelet::Nodelet
{
// Subscriptions
boost::shared_ptr<image_transport::ImageTransport> it_;
image_transport::CameraSubscriber sub_depth_;
int queue_size_; // Publications
boost::mutex connect_mutex_;
typedef sensor_msgs::PointCloud2 PointCloud;
ros::Publisher pub_point_cloud_; image_geometry::PinholeCameraModel model_; virtual void onInit(); void connectCb(); void depthCb(const sensor_msgs::ImageConstPtr& depth_msg,
const sensor_msgs::CameraInfoConstPtr& info_msg);
}; void MyPointCloudGeneratorNodelet::onInit()
{
ros::NodeHandle& nh = getNodeHandle();
it_.reset(new image_transport::ImageTransport(nh));
queue_size_ = ;
// Read parameters // Monitor whether anyone is subscribed to the output
ros::SubscriberStatusCallback connect_cb = boost::bind(&MyPointCloudGeneratorNodelet::connectCb, this);
// Make sure we don't enter connectCb() between advertising and assigning to pub_point_cloud_
boost::lock_guard<boost::mutex> lock(connect_mutex_);
pub_point_cloud_ = nh.advertise<PointCloud>("points", , connect_cb, connect_cb);
ROS_INFO("onInit"); } // Handles (un)subscribing when clients (un)subscribe
void MyPointCloudGeneratorNodelet::connectCb()
{
boost::lock_guard<boost::mutex> lock(connect_mutex_);
if (pub_point_cloud_.getNumSubscribers() == )
{
sub_depth_.shutdown();
}
else if (!sub_depth_)
{
image_transport::TransportHints hints("raw", ros::TransportHints(), getPrivateNodeHandle());
sub_depth_ = it_->subscribeCamera("image_rect", queue_size_, &MyPointCloudGeneratorNodelet::depthCb, this, hints);
}
ROS_INFO("connectCb"); } void MyPointCloudGeneratorNodelet::depthCb(const sensor_msgs::ImageConstPtr& depth_msg,
const sensor_msgs::CameraInfoConstPtr& info_msg)
{ pcl_process_class mpcl_process_class;
mpcl_process_class.pcl_process(depth_msg);
PointCloud pointCloud;
pcl::toROSMsg(*mpcl_p ointCloud);
} } // namespace depth_image_proc // Register as nodelet
#include <pluginlib/class_list_macros.h>
PLUGINLIB_EXPORT_CLASS(vision_obstacles_avoidance::MyPointCloudGeneratorNodelet,nodelet::Nodelet);

nodelet.launch

<launch>
<node pkg="nodelet" type="nodelet" name="standalone_nodelet" args="manager" output="screen"/> <node pkg="nodelet" type="nodelet" name="MyPointCloudGeneratorNodelet" args="load vision_obstacles_avoidance/MyPointCloudGeneratorNodelet standalone_nodelet" output="screen">
<remap from="image_rect" to="/camera/depth_registered/hw_registered/image_rect_raw"/>
<remap from="points" to="/point_cloud"/>
<remap from="/camera/depth_registered/hw_registered/camera_info" to="/camera/depth_registered/camera_info"/>
</node>
</launch>

nodelet比较好用尤其是在使用pointcloud时候,由于ros node之间采用tcpros标准来传输数据,点云要经过压缩解压缩过程所以很慢,但是nodelet是直接使用原来数据,类似指针,但是只能在同一个机器下才有用。

class MyPointCloudGeneratorNodelet : public nodelet::Nodelet{  // Subscriptions  boost::shared_ptr<image_transport::ImageTransport> it_;  image_transport::CameraSubscriber sub_depth_;  int queue_size_;
  // Publications  boost::mutex connect_mutex_;  typedef sensor_msgs::PointCloud2 PointCloud;  ros::Publisher pub_point_cloud_;
  image_geometry::PinholeCameraModel model_;
  virtual void onInit();
  void connectCb();
  void depthCb(const sensor_msgs::ImageConstPtr& depth_msg,               const sensor_msgs::CameraInfoConstPtr& info_msg);};
void MyPointCloudGeneratorNodelet::onInit(){  ros::NodeHandle& nh         = getNodeHandle();  it_.reset(new image_transport::ImageTransport(nh));  queue_size_ = 5;  // Read parameters
  // Monitor whether anyone is subscribed to the output  ros::SubscriberStatusCallback connect_cb = boost::bind(&MyPointCloudGeneratorNodelet::connectCb, this);  // Make sure we don't enter connectCb() between advertising and assigning to pub_point_cloud_  boost::lock_guard<boost::mutex> lock(connect_mutex_);  pub_point_cloud_ = nh.advertise<PointCloud>("points", 1, connect_cb, connect_cb);  ROS_INFO("onInit");
}
// Handles (un)subscribing when clients (un)subscribevoid MyPointCloudGeneratorNodelet::connectCb(){  boost::lock_guard<boost::mutex> lock(connect_mutex_);  if (pub_point_cloud_.getNumSubscribers() == 0)  {    sub_depth_.shutdown();  }  else if (!sub_depth_)  {    image_transport::TransportHints hints("raw", ros::TransportHints(), getPrivateNodeHandle());    sub_depth_ = it_->subscribeCamera("image_rect", queue_size_, &MyPointCloudGeneratorNodelet::depthCb, this, hints);  }  ROS_INFO("connectCb");
}
void MyPointCloudGeneratorNodelet::depthCb(const sensor_msgs::ImageConstPtr& depth_msg,                                   const sensor_msgs::CameraInfoConstPtr& info_msg){
  pcl_process_class mpcl_process_class;  mpcl_process_class.pcl_process(depth_msg);  PointCloud pointCloud;  pcl::toROSMsg(*mpcl_p ointCloud);}
} // namespace depth_image_proc
// Register as nodelet#include <pluginlib/class_list_macros.h>PLUGINLIB_EXPORT_CLASS(vision_obstacles_avoidance::MyPointCloudGeneratorNodelet,nodelet::Nodelet);

ros nodelet 使用的更多相关文章

  1. ROS nodelet的使用

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

  2. ROS nodelet 理解记录

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

  3. 使用yocs_cmd_vel_mux进行机器人速度控制切换

    cmd_vel_mux包从名字就可以推测出它的用途,即进行速度的选择(In electronics, a multiplexer or mux is a device that selects one ...

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

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

  5. ROS Node/Topic/Message/Service的一些问题

    1.Node http://blog.exbot.net/archives/1412 (摘自老王说ros) node干的什么活?callback queue里的活.这个callback queue里的 ...

  6. ZED 相机 && ORB-SLAM2安装环境配置与ROS下的调试

    注:1. 对某些地方进行了更新(红色标注),以方便进行配置. 2. ZED ROS Wrapper官方github已经更新,根据描述新的Wrapper可能已经不适用与Ros Indigo了,如果大家想 ...

  7. (一)ROS系统入门 Getting Started with ROS 以Kinetic为主更新 附课件PPT

    ROS机器人程序设计(原书第2版)补充资料 教案1 ROS Kinetic系统入门 ROS Kinetic在Ubuntu 16.04.01 安装可参考:http://blog.csdn.net/zha ...

  8. 奥比中光Orbbec Astra Pro RGBD 3D视觉传感器在ROS(indigo和kinetic)使用说明 rgb depth同时显示

    Orbbec Astra Pro传感器在ROS(indigo和kinetic)使用说明 rgb depth同时显示 这款摄像头使用uvc输入彩色信息,需要libuvc和libuvc_ros这样才能在R ...

  9. ROS机器人程序设计(原书第2版)补充资料 (贰) 第二章 ROS系统架构及概念

    ROS机器人程序设计(原书第2版)补充资料 (贰) 第二章 ROS系统架构及概念 书中,大部分出现hydro的地方,直接替换为indigo或jade或kinetic,即可在对应版本中使用. 由于工作事 ...

随机推荐

  1. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  2. HDU--2363

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2363 分析:最短路+二分. #include<iostream> #include< ...

  3. Codeforces 894.C Marco and GCD Sequence

    C. Marco and GCD Sequence time limit per test 1 second memory limit per test 256 megabytes input sta ...

  4. Java Socket UDP编程

    package com; import java.io.IOException; import java.net.*; /** * UDP Client * * Created by Administ ...

  5. laravel调试神器tinker

    一直以来,想调试框架中的某些东西,如想知道 Elpquent 的 create 方法返回值是个什么东西, 以前的话,应该就是在 create 方法调用之后,使用 dd 或者 var_dump 之类的函 ...

  6. OD常见指令和快捷键

    声明: 1.本表来自各论坛.博客,欢迎补充讨论 指令 解释 OD汇编指令   NOP 无操作 PUSH 将数据压如堆栈中 POP 出栈(与PUSH相反) PUSHAD 所有通用寄存器的内容按一定顺序压 ...

  7. numpy数组中冒号和负号的含义

    numpy数组中":"和"-"的意义 觉得有用的话,欢迎一起讨论相互学习~Follow Me 在实际使用numpy时,我们常常会使用numpy数组的-1维度和& ...

  8. input模拟

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. vee-validate

    http://vee-validate.logaretm.com/ 表单校验,配合VUE使用

  10. 2017北京国庆刷题Day6 afternoon

    期望得分:100+100+40=240 实际得分:100+0+40=140 二进制拆分.二进制前缀和 #include<cstdio> #include<iostream> u ...