[Documentation] [TitleIndex] [WordIndex] 

Message generation

From Catkin

rosnodejs uses generated Node.js source code from msg, srv, and action files created by gennodejs. These messages are built with your packages automatically when running catkin_make in ROS Kinetic and later. The pattern for this looks similar to rospy's.

Service files look similar

These files are generated from the src directory of package_name. Message files are required through rosnodejs itself.

const std_msgs = rosnodejs.require('std_msgs');
const StringMsg = std_msgs.msg.String;

or

const SetBool = rosnodejs.require('std_srvs').srv.SetBool;

On the fly

rosnodejs also provides the ability to dynamically create message classes on the fly without the need to run catkin_make

rosnodejs.initNode('my_node',
                   { onTheFly: true });

These messages are required in the same way, but can not be required until after the initNode call has completed.

Pre-generated, Pre-Kinetic

To support users in ROS Indigo and earlier who want to use pre-generated messages, rosnodejs also provides the ability to generate message code.

rosnodejs.loadAllPackages();

Messages will be built into your devel workspace by default, though you can optionally specify a different destination if you prefer.

Message Initialization

Message fields are given default values, so you can directly assign values to embedded messages.

const msg = new geometry_msgs.msg.PoseStamped();
msg.header.frame_id = 'base';

Messages also accept arguments for fields if you prefer

const msg = new std_msgs.msg.String({ data: 'Hello' });

Note: if you provide a value for a complex field in the constructor for the message rosnodejs will assume you have provided a full, valid message for that field.


2026-09-19 12:46