Getting Started with ROS on Embedded Systems - User Guide - C++ - Initialization

From RidgeRun Developer Connection
Jump to: navigation, search




Previous: User Guide/C++/Package set up Index Next: User Guide/C++/Topics




Introduction

This wiki is based on the following ROS page: http://wiki.ros.org/roscpp/Overview/Initialization%20and%20Shutdown

There are two levels of initialization for a roscpp Node:

  1. Initializing the node through a call to one of the ros::init() functions. This provides command line arguments to ROS, and allows you to name your node and specify other options.
  2. Starting the node is most often done through creation of a ros::NodeHandle, but in advanced cases can be done in different ways.

Initialization

And example of initialization for the a ROS node inside a main.cpp can be the following:

ros::init(argc, argv, "rr_node");

Starting

Calling init doesn't actually start the node, it just initialized it, in order to start it, you can create a node handle, this will call the ros::start underneath:

ros::NodeHandle node_handle("node_namespace");

Look here that we just assigned a node namespace, we will take about them later in the names section.

Testing

You can test the node by adding this to the code:

while (ros::ok()){
    /* Do something here */
    ros::spin();
}

After compilation, you can launch the node by using:

rosrun <package> <node_name_executable>
Previous: User Guide/C++/Package set up Index Next: User Guide/C++/Topics