ROS节点的初始化及退出详解(ros::init、SIGINT、ros::ok、ros::NodeHandle
https://haoqchen.site/2018/04/28/ROS-node-init/
#include "ros/ros.h"
#include <signal.h> void MySigintHandler(int sig)
{
//这里主要进行退出前的数据保存、内存清理、告知其他节点等工作
ROS_INFO("shutting down!");
ros::shutdown();
} int main(int argc, char** argv){
//ros::init()
/**
* The ros::init() function needs to see argc and argv so that it can perform
* any ROS arguments and name remapping that were provided at the command line. For programmatic
* remappings you can use a different version of init() which takes remappings
* directly, but for most command-line programs, passing argc and argv is the easiest
* way to do it. The third argument to init() is the name of the node.
*
* You must call one of the versions of ros::init() before using any other
* part of the ROS system.
*/
ros::init(argc, argv, "ist_node");
//初始化节点名字必须在最前面,如果ROS系统中出现重名,则之前的节点会被自动关闭
//如果想要多个重名节点而不报错,可以在init中添加ros::init_options::AnonymousName参数
//该参数会在原有节点名字的后面添加一些随机数来使每个节点独一无二
//ros::init(argc, argv, "my_node_name", ros::init_options::AnonymousName); //ros::NodeHandle
/**
* NodeHandle is the main access point to communications with the ROS system.
* The first NodeHandle constructed will fully initialize this node, and the last
* NodeHandle destructed will call ros::shutdown() to close down the node.
*/
ros::NodeHandle h_node;
//获取节点的句柄,init是初始化节点,这个是Starting the node
//如果不想通过对象的生命周期来管理节点的开始和结束,你可以通过ros::start()和ros::shutdown() 来自己管理节点。 ros::Rate loop_rate();
//loop once per second
//Cannot use before the first NodeHandle has been created or ros::start() has been called. //shut down
signal(SIGINT, MySigintHandler);
//覆盖原来的Ctrl+C中断函数,原来的只会调用ros::shutdown()
//为你关闭节点相关的subscriptions, publications, service calls, and service servers,退出进程 //run status
int sec = ;
while(ros::ok() && sec++ < ){
loop_rate.sleep();
ROS_INFO("ROS is ok!");
ros::spinOnce();
}
//ros::ok()返回false,代表可能发生了以下事件
//1.SIGINT被触发(Ctrl-C)调用了ros::shutdown()
//2.被另一同名节点踢出 ROS 网络
//3.ros::shutdown()被程序的另一部分调用
//4.节点中的所有ros::NodeHandles 都已经被销毁
//ros::isShuttingDown():一旦ros::shutdown()被调用(注意是刚开始调用,而不是调用完毕),就返回true
//一般建议用ros::ok(),特殊情况可以用ros::isShuttingDown() ROS_INFO("Node exit");
printf("Process exit\n");
return ;
}
ROS节点的初始化及退出详解(ros::init、SIGINT、ros::ok、ros::NodeHandle的更多相关文章
- Kubernetes K8S之固定节点nodeName和nodeSelector调度详解
Kubernetes K8S之固定节点nodeName和nodeSelector调度详解与示例 主机配置规划 服务器名称(hostname) 系统版本 配置 内网IP 外网IP(模拟) k8s-mas ...
- 深入理解mybatis原理, Mybatis初始化SqlSessionFactory机制详解(转)
文章转自http://blog.csdn.net/l454822901/article/details/51829785 对于任何框架而言,在使用前都要进行一系列的初始化,MyBatis也不例外.本章 ...
- Linux进程退出详解(do_exit)--Linux进程的管理与调度(十四)
Linux进程的退出 linux下进程退出的方式 正常退出 从main函数返回return 调用exit 调用_exit 异常退出 调用abort 由信号终止 _exit, exit和_Exit的区别 ...
- appium+java(二)appium初始化参数部分详解
Capabilities介绍 实际上它的全称是:Desired capabilities Desired capability是一个JSON对象,包含一组key和value值.它由客户端发送给服务端, ...
- Linux CentOS 服务器搭建与初始化配置图文详解
这几天对服务器兴趣贼为浓厚,在虚拟机上装了一个CentOS7玩了玩,遇到过很多问题,比如网卡驱动设置,不能ping 等等问题,然后掏钱买个ECS搭服务器玩玩,下面就开始谢谢我的心路历程吧. 首先 买服 ...
- Linux 启动详解之init
1.init初探 init是Linux系统操作中不可缺少的程序之一.init进程,它是一个由内核启动的用户级进程,然后由它来启动后面的任务,包括多用户环境,网络等. 内核会在过去曾使用过init的几个 ...
- SD卡初始化以及命令详解
SD卡是嵌入式设备中很常用的一种存储设备,体积小,容量大,通讯简单,电路简单所以受到很多设备厂商的欢迎,主要用来记录设备运行过程中的各种信息,以及程序的各种配置信息,很是方便,有这样几点是需要知道的 ...
- ROS学习笔记十:URDF详解
Unified Robot Description Format,简称为URDF(标准化机器人描述格式),是一种用于描述机器人及其部分结构.关节.自由度等的XML格式文件. 一.URDF语法规范 参见 ...
- I2C初始化结构体详解
typedef struct { uint32_t I2C_ClockSpeed; /*设置SCL时钟频,此值不低于40000*/ uint16_t I2C_Mode; /* 指定工作模式,可选I2C ...
随机推荐
- C++ SOCKET 基础编程
{ http://c.biancheng.net/socket/ }
- 初识STL
原生指针 泛型指针 智能指针 都是什么? iterator迭代器和指针的区别 C++标准模板库(STL)迭代器的原理与实现 [C++]STL常用容器总结之一:容器与迭代器 C++内置数组和array的 ...
- 函数开始处的MOV EDI, EDI的作用
调试程序调试到系统库函数的代码时,总会发现系统函数都是从一条MOV EDI, EDI指令开始的,紧接着这条指令下面才是标准的建立函数局部栈的代码.对系统DLL比如ntdll.dll进行反汇编,可以发现 ...
- JAVA 设计模式之 原型模式详解
原型模式(Prototype Pattern)是指原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 原型模式利用的是克隆的原理,创建新的对象,JDK提供的Cloneable 和JSON. ...
- vue mounted组件的使用
1.钩子函数 钩子函数是Windows消息处理机制的一部分,通过设置“钩子”,应用程序可以在系统级对所有消息.事件进行过滤,访问在正常情况下无法访问的消息.钩子的本质是一段用以处理系统消息的程序,通 ...
- LightOJ-1234-Harmonic Number-调和级数+欧拉常数 / 直接打表
In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers ...
- AtCoder ABC 129F Takahashi's Basics in Education and Learning
题目链接:https://atcoder.jp/contests/abc129/tasks/abc129_f 题目大意 给定一个长度为 L ,首项为 A,公差为 B 的等差数列 S,将这 L 个数拼起 ...
- JavaScript开发人员必知的10个关键习惯
还在一味没有目的的编写JavaScript代码吗?那么你就OUT了!让我们一起来看看小编为大家搜罗的JavaScript开发人员应该具备的十大关键习惯吧! 随着新技术的不断发展,JavaScript已 ...
- How to use view controller containment
https://www.hackingwithswift.com/example-code/uikit/how-to-use-view-controller-containment private f ...
- iOS开发系列-线程同步技术
概述 多线程的本质就是CPU轮流随机分配给每条线程时间片资源执行任务,看起来多条线程同时执行任务. 多条线程同时访问同一块资源,比如操作同一个对象.统一变量.同一个文件,就会引发数据错乱和数据安全的问 ...