ros::NodeHandle成员介绍
2016-08-17 10:32
716 查看
完整英文介绍见网址http://docs.ros.org/jade/api/roscpp/html/classros_1_1NodeHandle.html ros::NodeHandle1 NodeHandle::advertise
Advertise a topic, simple version.This call connects to the master to publicize that the node will be publishing messages on the given topic. This method returns a Publisher thatallows you to publish a message on this topic.This version of advertise is a templated convenience function, and can be used like so使用示例:ros::Publisher pub= handle.advertise<std_msgs::Empty>("my_topic", 1);Parameters:
Returns:On success, a Publisher that,when it goes out of scope, will automatically release a reference on this advertisement. On failure, an empty Publisher.Exceptions:
介绍:以指定名称,队列大小发布一个topic,latch参数表示是否发送保存,可不初始化。回调函数写法:
Subscribe to a topic, version for class member function with bare pointer.This method connects to the master to register interest in a given topic. The node will automatically be connected with publishers on this topic. On each message receipt, fp is invoked and passed a shared pointer to the message received.This message should not be changed in place, as it is shared with any other subscriptions to this topic.This version of subscribe is a convenience function for using member functions, and can be used like so:
Create a client for a service, version templated on two message types.When the last handle reference of a persistent connection is cleared, the connection will automatically close.Parameters:
参数解释:service_name链接到的服务的名称 persistent是否持续连接Exceptions:
Advertise a service, version for class member function with bare pointer.This call connects to the master to publicize that the node will be offering an RPC service with the given name.This is a convenience function for using member functions, and can be used like so:
Returns:On success, a ServiceServer that, when all copies of it go out of scope, will unadvertise this service. On failure, an empty ServiceServer which can be checked with:
Publisher ros::NodeHandle::advertise | ( | const std::string & | topic, |
uint32_t | queue_size, | ||
bool | latch = false | ||
) | [inline] |
topic | Topic to advertise on |
queue_size | Maximum number of outgoing messages to be queued for delivery to subscribers |
latch | (optional) If true, the last message published on this topic will be saved and sent to new subscribers when they connect |
InvalidNameException | If the topic name begins with a tilde, or is an otherwise invalid graph resource name, or is an otherwise invalid graph resource name |
void connectCallback(const ros::SingleSubscriberPublisher& pub) { // Do something } ros::Publisher pub =handle.advertise<std_msgs::Empty>("my_topic", 1, (ros::SubscriberStatusCallback)connectCallback);2 NodeHandle::subscribe
Subscriber ros::NodeHandle::subscribe | ( | const std::string & | topic, |
uint32_t | queue_size, | ||
void(T::*)(M) | fp, | ||
T * | obj, | ||
const TransportHints & | transport_hints = TransportHints() | ||
) | [inline] |
void Foo::callback(const std_msgs::Empty::ConstPtr& message) { } Foo foo_object; ros::Subscriber sub = handle.subscribe("my_topic", 1, &Foo::callback, &foo_object);
参数 | |
topic | Topic to subscribe to |
queue_size | Number of incoming messages to queue up for processing (messages in excess of this queue capacity will be discarded). |
fp | Member function pointer to call when a message has arrived |
obj | Object to call fp on |
transport_hints | a TransportHints structurewhich defines various transport-related options |
参数解释:
fp 消息到达时的回调函数指针
obj 回调对象
3 NodeHandle::serviceClient |
ServiceClient ros::NodeHandle::serviceClient | ( | conststd::string & | service_name, |
bool | persistent = false, | ||
const M_string & | header_values = M_string() | ||
) | [inline] |
service_name | The name of the service to connect to |
persistent | Whetherthis connection should persist. Persistent services keep the connection to the remote host active so that subsequent calls will happen faster. In general persistent services are discouraged, as they are not as robust to node failure as non-persistent services. |
header_values | Key/valuepairs you'd like to send along in the connection handshake |
InvalidNameException | Ifthe service name begins with a tilde, or is an otherwise invalid graph resource name |
4 NodeHandle::advertiseService
ros::NodeHandle::advertiseService | ( | conststd::string & | service, |
bool(T::*)(MReq &, MRes &) | srv_func, | ||
T* | obj | ||
) | [inline] |
bool Foo::callback(std_srvs::Empty& request, std_srvs::Empty& response) { return true; } Foo foo_object; ros::ServiceServer service = handle.advertiseService("my_service", &Foo::callback, &foo_object);Parameters:
service | Service name to advertise on |
srv_func | Memberfunction pointer to call when a message has arrived |
obj | Object to call srv_func on |
bool Foo::callback(std_srvs::Empty& request, std_srvs::Empty& response) { return true; } ros::NodeHandle nodeHandle; Foo foo_object; ros::ServiceServer service = nodeHandle.advertiseService("my_service", &Foo::callback, &foo_object); if (service) // Enter if advertised service is valid { ... }
相关文章推荐
- JavaScript中Element与Node的区别,children与childNodes的区别
- 19. Remove Nth Node From End of List
- Node.js中使用jQuery的做法
- node 练习之多人聊天、点对点聊天室demo
- nodejs-util笔记
- node-path工具模块笔记
- [leetcode]382. Linked List Random Node
- Reverse Nodes in k-Group_Leetcode_#25
- nodejs使用connect-multiparty实现文件上传(文件接收)后端
- Nodejs为代理npm设置代理
- gulp自动化环境搭建,自动化解决方案
- nodejs express实现 客户端+服务端
- 《Node.js开发指南》读书笔记
- nw.js node-webkit系列(24)如何对本地文件读写
- node.js学习笔记(6)_极客学院_Waterline
- [Node.js] require背后的故事
- 【leetcode】382. Linked List Random Node
- nodejs 更新最新版本
- Node之Event模块
- nodejs常用命令,nondejs初学者