ros nodelet 使用
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 使用的更多相关文章
- ROS nodelet的使用
ROS是一种基于分布式网络通讯的操作系统,整个机器人控制系统是由一个Master主节点和若干个功能相对独立的Node子节点组成,这也是ROS系统最主要的特点就是分布式以及模块化的设计.在ROS通讯过程 ...
- ROS nodelet 理解记录
发现网上许多的例子都是基于官网的例子,还需要做进一步的说明. 1. NODELET_DEBUG 是无法打印的信息的,需要使用NODELET_INFO NODELET_DEBUG("Addin ...
- 使用yocs_cmd_vel_mux进行机器人速度控制切换
cmd_vel_mux包从名字就可以推测出它的用途,即进行速度的选择(In electronics, a multiplexer or mux is a device that selects one ...
- ubuntu14.04 and ros indigo install kinect driver--16
摘要: 原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ 今日多次测设ros indigo install kinect driver ,提示各种失败,然 ...
- ROS Node/Topic/Message/Service的一些问题
1.Node http://blog.exbot.net/archives/1412 (摘自老王说ros) node干的什么活?callback queue里的活.这个callback queue里的 ...
- ZED 相机 && ORB-SLAM2安装环境配置与ROS下的调试
注:1. 对某些地方进行了更新(红色标注),以方便进行配置. 2. ZED ROS Wrapper官方github已经更新,根据描述新的Wrapper可能已经不适用与Ros Indigo了,如果大家想 ...
- (一)ROS系统入门 Getting Started with ROS 以Kinetic为主更新 附课件PPT
ROS机器人程序设计(原书第2版)补充资料 教案1 ROS Kinetic系统入门 ROS Kinetic在Ubuntu 16.04.01 安装可参考:http://blog.csdn.net/zha ...
- 奥比中光Orbbec Astra Pro RGBD 3D视觉传感器在ROS(indigo和kinetic)使用说明 rgb depth同时显示
Orbbec Astra Pro传感器在ROS(indigo和kinetic)使用说明 rgb depth同时显示 这款摄像头使用uvc输入彩色信息,需要libuvc和libuvc_ros这样才能在R ...
- ROS机器人程序设计(原书第2版)补充资料 (贰) 第二章 ROS系统架构及概念
ROS机器人程序设计(原书第2版)补充资料 (贰) 第二章 ROS系统架构及概念 书中,大部分出现hydro的地方,直接替换为indigo或jade或kinetic,即可在对应版本中使用. 由于工作事 ...
随机推荐
- Codeforces 585D. Lizard Era: Beginning(meet in the middle)
一眼题...这个数据范围也太明显了吧... suma1==suma2 && sumb1==sumb2 && sumc1==sumc2 相当于suma1-sumb1==s ...
- 浴谷八连测R6题解(收获颇丰.jpg)
这场的题都让我收获颇丰啊QWQ 感谢van♂老师 T1 喵喵喵!当时以为经典题只能那么做, 思维定势了... 因为DP本质是通过一些条件和答案互相递推的一个过程, 实际上就是把条件和答案分配在DP的状 ...
- 如何在 ASP.NET 应用程序中实现模拟用户身份(在ASP.NET中以管理员身份运行网站)
前言 在实际的项目开发中,我们可能会需要调用一些非托管程序,而有些非托管程序需要有更高的身份权限才能正确执行.本文介绍了如何让IIS承载的ASP.NET网站以特定的账户执行,比如Administrat ...
- Spring MVC @CookieValue注解
@CookieValue的作用 用来获取Cookie中的值 @CookieValue参数 1.value:参数名称 2.required:是否必须 3.defaultValue:默认值 @Cookie ...
- Centos7.3 安装 OpenCV3.3.0
一开始会出现这个错误: CMake Error at CMakeLists.txt: (message): FATAL: In-source builds are not allowed. You s ...
- 洛谷P1290 欧几里得的游戏
题目描述 欧几里德的两个后代Stan和Ollie正在玩一种数字游戏,这个游戏是他们的祖先欧几里德发明的.给定两个正整数M和N,从Stan开始,从其中较大的一个数,减去较小的数的正整数倍,当然,得到的数 ...
- 报Cannot find /usr/local/tomcat/bin/setclasspath.sh错误
错误如下: [root@RSP-DEVWEB03 bin]#sh startup.sh Cannot find /usr/local/tomcat8081/bin/setclasspath.sh Th ...
- C++ string的那些坑
1. size_type find_first_of( const basic_string &str, size_type index = 0 ); 查找在字符串中第一个与str中的某个字符 ...
- [LeetCode] 28. Implement strStr() ☆
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- RabbitMQ的原理和使用
转载:RabbitMQ从入门到精通 转载:轻松搞定RabbitMQ 转载:RabbitMQ Java入门教程 一.RabbitMQ AMQP,即Advanced Message Queuing Pro ...