npm package: @gov.nasa.jpl.honeycomb/rosbag-loader
Description: Loader and parser for processing rosbag files.
Latest version: 0.0.6

# rosbag-loader

Loader for loading and parsing ROS Bag files using the [rosbag](https://www.npmjs.com/package/rosbag) package.

!> Note that only `lz4` decompression is implemented when reading compressed Rosbags.

!> Note that for the moment RosbagLoader _always_ uses the browser implementation of rosbag.js. See [#439](https://github.jpl.nasa.gov/Honeycomb/honeycomb/issues/439)

<!--{package-dependencies ./package.json}-->

# Use

<!-- START_AUTOGENERATED_DOCS -->
## Functions
### load<a name="#load"></a>

```js
load( url : String, options : ReaderOptions | null = null ) : Map | Array | RosbagReader
```

Loads and parses the ROS bag file. The promise resolves with the returned data from the `parse` function.

### parse<a name="#parse"></a>

```js
parse( data : Blob, options : ReaderOptions | null = null ) : Map | Array | RosbagReader
```

Takes a file handle blob to read and a set of options to read the messages with. If `readAllData` is
false a [RosbagReader](#RosbagReader) instance is returned otherwise all frames are read and returned. See the
[#RosbagReader#read](#RosbagReader#read) for a description of the returned data.

## ReaderOptions

### flattenState<a name="ReaderOptions#flattenState"></a>

```js
flattenState : Boolean = false
```


If true the hierarchy of objects is flattened into a single object with the `flattenDelimiter` separating
object children.


### flattenDelimiter<a name="ReaderOptions#flattenDelimiter"></a>

```js
flattenDelimiter : String = '_'
```


The character to use to separate nested object names when flattening the object state.


### indexTransform<a name="ReaderOptions#indexTransform"></a>

```js
indexTransform : Boolean = true
```


If true the `transform` object in the "/tf" and "/tf_static" messages are converted from an array in to an
object indexed by `child_frame_id`:
```js
{
     transforms: [
         { child_frame_id: 'base_link', transform: { ... } },
         { child_frame_id: 'world', transform: { ... } }
     ]
}

// into

{
     transforms: {
         'base_link': { child_frame_id: 'base_link', transform: { ... } },
         'world': { child_frame_id: 'world', transform: { ... } }
     }
}

```


### readAllData<a name="ReaderOptions#readAllData"></a>

```js
readAllData : Boolean = true
```


If true the full list of Rosbag data will be returned from the reader in the callback. Otherwise a RosbagReader
handle will be returned so data can be read as needed.


### normalizeTopicNames<a name="ReaderOptions#normalizeTopicNames"></a>

```js
normalizeTopicNames : Boolean = true
```


If true all topic names are normalized to be prefixed with a `/` the way [roslibjs](https://github.com/RobotWebTools/roslibjs)
registers them over websocket. If false some topic name may not be prefixed with slashes.


### separateTopicArrays<a name="ReaderOptions#separateTopicArrays"></a>

```js
separateTopicArrays : Boolean = false
```


If true all topics are broken out into separate arrays of data in a map. Otherwise a single array of data is returned.


## RosbagReader

Class for reading data from the rosbag file.

### start<a name="RosbagReader#start"></a>

```js
start : Number
```


The start time in ms of the rosbag file.


### end<a name="RosbagReader#end"></a>

```js
end : Number
```


The end time in ms of the rosbag file.


### messageTypes<a name="RosbagReader#messageTypes"></a>

```js
messageTypes : Object
```


A map from topic name to ROS topic message type.


### topics<a name="RosbagReader#topics"></a>

```js
topics : Array<String>
```


The list of topics available in the given Rosbag.


### constructor

```js
constructor( handle : RosbagHandle, options : ReaderOptions ) : void
```

Takes a handle to the [Rosbag.js Bag Instance](https://github.com/cruise-automation/rosbag.js#bag-instance) to read
messages from an a set of options to use when reading messages.

### read<a name="RosbagReader#read"></a>

```js
read( from : Number, to : Number, options : ReaderOptions ) : Promise<Object | Array>
```

Takes a from time and and to time in milliseconds and returns the set of data between those times. A
set of options can be provided to override the set of options originally passed into the reader. Options
from rosbag.js cannot be overriden here.

The shape of the returned data depends on the `separateTopicArrays`. If true then a map of topic name
to array of frames of data is returned:
```js
{
     '/tf' : [ ... ],
     '/tf_static' : [ ... ],
     '/markers' : [ ... ],
}
```

Otherwise an array of frames is returned. A frame consists of a `time` field in ms and `state` field which
contains the ros topic message contents:
```js
{
     time: number,
     state: {
         //...
     }
}
```


<!-- END_AUTOGENERATED_DOCS -->