[Documentation] [TitleIndex] [WordIndex

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

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


2024-11-30 17:52