Ros node Startup and shutdown

1. ros Operating unit :

Ros The unit of program operation is ros node.

2. ros Start of node :

(1) initialization ros node : By calling ros::init() Interface implementation ; The default node name can be specified by a parameter , The reason is default , It's because when you execute a program on the command line , The node name can be modified .

(2) start-up ros node : By calling ros::NodeHnadle establish NodeHnadle example nh realization , When you first create an instance , Will call ros::start(), Start this node at this time .

3. ros Node shutdown :

(1) By calling ros::shutdown() Interface , close ros node , This interface turns off the subscription topic , Release topic , Request service and provide service .

(2) In the last one ros::NodeHnadle When the object is destroyed , Will be called automatically ros::shutdown(), To close ros node .

4. testing ros Is the node down :

(1)ros::ok() Interface : return false, Indicates that the node is down .

(2)ros::isShuttingDown() Interface : return true, explain ros::shutdown() Called , But the node ratio must end .

notes : So it is generally used ros::ok() judge , The node that ends at but doesn't end at , for example “ prolonged service
callback” in , You can only use ros::isShuttingDown(), Because this node will not be shut down , I wonder what node this is ?

5. interrupt :

(1) stay ros::init() Options , There is an option ros::init_options::NoSigintHandler, Decide whether to install the default SIGINT Processing function , If this parameter is not used , Then install , The program received SIGINT signal (ctrl+c) Time ,ros::ok() return false, Nodes can go through the closing process . If this parameter is used , You need to install it yourself SIGINT Processing function , To ensure that the node can end .

Technology