1.初始化roscpp 节点

ros::init()  API链接:http://docs.ros.org/api/roscpp/html/init_8h.html

在node代码中在调用其它roscpp函数前,首先调用ros::init()函数

例如:

 ros::init(argc, argv, "my_node_name");
ros::init(argc, argv, "my_node_name", ros::init_options::AnonymousName);

函数原型:

void ros::init(<command line or remapping arguments>, std::string node_name, uint32_t options);

argc和argv:解析命令行重映射参数

node_name:节点名,在ros系统中,节点名必须唯一;如果重名节点被运行,那之前的节点就会自动关闭。

options:选项参数,明确roscpp的一些具体的行为

初始化节点只是简单地从命令行参数和环境中确定像节点名、名字空间以及重映射。它不会与主节点master交互。

1) 初始化选项

ros::init_options API链接:

http://docs.ros.org/api/roscpp/html/namespaceros_1_1init__options.html

2)获取你的命令行参数

ros::removeROSArgs() API链接:

http://docs.ros.org/api/roscpp/html/init_8h.html

2.启动roscpp节点

最常用的启动roscpp节点的方式就是创建ros::NodeHandle实例:

ros::NodeHandle nh;

二、节点的关闭

1.关闭节点

节点会在调用ros::shutdown()函数时被关闭,这将杀死所有该节点相关的订阅者,发布者,服务请求,服务提供...

2.关闭测试

有两种测试关闭状态的方法。

最常用的方法是ros::ok(),一旦ros::ok()返回false,节点就已经被关闭了。

使用方法:

while(ros::ok())
{
...
...
...
}

另一种是使用ros::isShutDown()方法。当ros::shutdown()函数被调用时,该函数返回true.

在一个持久的服务回调函数中使用该测试函数测试是否应该结束,这时候不能使用ros::ok()来测试,因为节点在回调函数运行时无法完成shutdown

自定义的SIGINT句柄:信号中断句柄。

使用方法:

#include <ros/ros.h>
#include <signal.h>
void mySigintHandler(int sig)
{
// Do some custom action.
// For example, publish a stop message to some other nodes.
// All the default sigint handler does is call shutdown()
ros::shutdown();
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "my_node_name", ros::init_options::NoSigintHandler);
ros::NodeHandle nh;
// Override the default ros sigint handler.
// This must be set after the first NodeHandle is created.
signal(SIGINT, mySigintHandler);
//...
ros::spin();
return ;
}
												

最新文章

  1. Bringing Whoops Back to Laravel 5
  2. [LeetCode] Binary Tree Right Side View 二叉树的右侧视图
  3. 手机web页面开发-第一弹
  4. Win7系统修改hosts文件不能保存的解决方法
  5. struts理解
  6. ArrayList vs LinkedList vs Vector
  7. RFS一些基本概念
  8. 学号20145220 《Java程序设计》第5周学习总结
  9. 关于kafka连接不上别的机器问题Connection refused
  10. sublime text3设置文件类型(CR/LF)
  11. win8、win8.1官方版本、及安装密钥
  12. Best Time to Buy and Sell Stock 解答
  13. Android 使用PopupWindow实现弹出菜单
  14. vconfig 的使用
  15. xmlns:xsi ——是指xml文件遵守xml规范,xsi全名:xml schema instance
  16. Dictionary导致CPU暴涨
  17. Unity 简易的UI背景昼夜轮替效果
  18. python3 练习题(用函数完成登录注册以及购物车的功能)
  19. 20154305 齐帅 PC平台逆向破解
  20. [PHP] 看博客学习观察者模式

热门文章

  1. 杭电 OJ 提交代码需要注意的问题
  2. Map集合框架的练习
  3. Java图片验证码乱码问题
  4. 利用LOCK机制来定位前缀劫持者
  5. linux mysql 卸载与安装及配置命令
  6. 纯小白入手 vue3.0 CLI - 2.6 - 组件的复用
  7. Postman&#160;Postman测试接口之POST提交本地文件数据
  8. android控件跟随手势滑动改变位置
  9. 004-React-Native--多图选择上传
  10. ConstraintLayout (约束布局)属性详情