@gov.nasa.jpl.honeycomb/ros-message-converter
v0.0.6
Published
Utility for converting cbor-raw ROSLibJS message contents to the content.
Readme
ROS Message Converter
Utility for loading and tracking message types and definitions from RosLibJs or Ros Bags and converting binary-form messages to js objects.
Use
Converting messages manually.
const ros = new ROSLIB.ROS( { ... } );
const converter = new RosMsgConverter();
await converter.initFromRos( ros );
const topic = new ROSLIB.Topic( {
ros: ros,
name: '/tf',
type: converter.getTopicType( '/tf' ),
compression: 'cbor-raw',
} );
topic.subscribe( function( raw ) {
const msg = converter.convertFromTopic( this.name, raw.data );
// data!
} );Or using a "SmartTopic" that infers the message type, uses cbor-raw compression, and autoconverts the content.
const topic = new SmartTopic( {
ros: ros,
converter: converter,
name: '/tf'
} );
topic.subscribe( msg => {
// data!
} );RosMsgConverter
Class for tracking ROS Topic, types, and definitions and converting binary "cbor-raw" representations to javascript objects.
ready
ready : BooleanBoolean indicating whether or not the instance has been initialized and ready to use.
types
types : ObjectA map of topic name to the name of the type.
initFromRos
initFromRos( handle : ROSLIB.ROS ) : voidInitialializes the types asynchronously using a ROSLIB.ROS instance by fetching the topics and raw message definitions message.
initFromBags
initFromBags( handles : ...Bag ) : voidTakes a list of initialized rosbag package "Bag" instances to initializes the class with.
hasType
hasType( type : string ) : BooleanReturns whether the converter can handle the given type.
convertFromType
convertFromType( type : string, data : ArrayBuffer ) : ObjectConverts the binary data to a javascript object using the reader of the given type.
convertFromTopic
convertFromTopic( topic : string, data : ArrayBuffer ) : ObjectConverts the binary data to a javascript object using the reader of the type of the given topic.
getTopicType
getTopicType( topic : string ) : stringReturns the type associated with the given topic.
SmartTopic
An extension of the ROSLIB.Topic that takes a RosMsgConverter in the options (as the "converter" option), uses "cbor-raw" compression by default, converts the result using the provided converter, and infers the topic type based on the topic name.
extends Topic
options
options : null