Initialization

The first thing to do in order to start your node is to call rosnodejs.initNode()

rosnodejs.initNode('my_node')

initNode returns a promise that will resolve when the connection to the ROS Master has been established. It will be passed a node handle for you to use if you like, though you may also get one yourself.

rosnodejs.initNode('my_node')
.then((nodeHandle) => {
  // do stuff
});

or

rosnodejs.initNode('my_node')
.then(() => {
  let nh = rosnodejs.nh;
  // do stuff
});

Options

initNode accepts a second object to provide optional overrides for default behavior. Possible overrides include

  • rosMasterUri

    • Specify the ROS Master address programmatically rather than through the ROS_MASTER_URI environment variable.

    onTheFly

    • Automatically generate messages to use rather than using the pre-generated messages.
    • Will fall back to pre-generated messages if available.

    logging

    • An object providing logging specific overrides. See logging for more information.
  • node

    • An object providing specific overrides to the ROS node itself. See Node for more information.

Shutdown

Once initialized, rosnodejs will continue to run until your process is exited or rosnodejs is terminated. This can be done either through Node.js' process.exit(), SIGINT, or if it receives a shutdown request from the ROS Master. It can also be done by calling rosnodejs.shutdown().

Registering Shutdown Hooks

Shutdown hooks can be registered once the ROS node has been initialized.

rosnodejs.on('shutdown', function() {  });
rosnodejs.once('shutdown', function() {  });
rosnodejs.removeListener('shutdown', function() { });

Note: the function passed into removeListener must be the same function used when registering the listener. See https://nodejs.org/api/events.html

Wiki: rosnodejs/overview/Initialization and Shutdown (last edited 2017-09-05 18:06:42 by chris-smith)