roslibjs: How to import and use custom `*.msg` types?

asked 2021-07-27 15:57:34 -0500

ifconfigBLT gravatar image

Hi all!

I've created several custom ROS topic message types (defined in *.msg) files that I've so far used without issue in my project's C++ and Python elements. Now, I'm working on making an electron app that also needs to interface with the ROS topics. I've been able to follow the basic roslibjs tutorial to listen for and receive messages of types from std_msgs/* (like std_msgs/Float64) like so:

const ROSLIB = require('roslib')

const ros = new ROSLIB.Ros({
  // url : 'ws://localhost:11311'
  url : 'ws://localhost:9090'
})

ros.on('connection', () => {
  console.log("Connected to ROS WS server!");
})

var altitude_input_listener = new ROSLIB.Topic({
  ros : ros,
  name : '/altitude_input',
  messageType : 'std_msgs/Float64'
});

altitude_input_listener.subscribe((msg) => {
  console.log("Received msg on " + altitude_input_listener.name + ": " + JSON.stringify(msg));
});

However, I've not yet found any information on how to import/specify the message type according to a *.msg type definition. Could anyone please help me with this?

edit retag flag offensive close merge delete