How to use the rosbag.TimeUtil.add function in rosbag

To help you get started, we’ve selected a few rosbag examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cruise-automation / webviz / packages / webviz-core / src / dataProviders / MemoryCacheDataProvider.js View on Github external
const currentConnection = this._currentConnection;
      if (!currentConnection || !isCurrent()) {
        return;
      }

      const currentBlockIndex = currentConnection.remainingBlockRange.start;
      // Only request topics that we don't already have.
      const topics = this._blocks[currentBlockIndex]
        ? currentConnection.topics.filter(
            (topic) => !this._blocks[currentBlockIndex] || !this._blocks[currentBlockIndex].messagesByTopic[topic]
          )
        : currentConnection.topics;

      // Get messages from the underlying provider.
      const startTime = TimeUtil.add(this._startTime, fromNanoSec(currentBlockIndex * MEM_CACHE_BLOCK_SIZE_NS));
      const endTime = TimeUtil.add(
        this._startTime,
        fromNanoSec(Math.min(this._totalNs, (currentBlockIndex + 1) * MEM_CACHE_BLOCK_SIZE_NS) - 1) // endTime is inclusive.
      );
      const messages = topics.length ? await this._provider.getMessages(startTime, endTime, topics) : [];

      // If we're not current any more, discard the messages, because otherwise we might write duplicate messages.
      if (!isCurrent()) {
        return;
      }

      // Create a new block if necessary.
      this._blocks[currentBlockIndex] = this._blocks[currentBlockIndex] || { messagesByTopic: {}, sizeInBytes: 0 };
      const currentBlock = this._blocks[currentBlockIndex];
      if (!currentBlock) {
        throw new Error("currentBlock should be set here");
      }
github cruise-automation / webviz / packages / webviz-core / src / players / RandomAccessPlayer.js View on Github external
this._setCurrentTime(time);

    const seekTime = Date.now();
    this._lastSeekTime = seekTime;
    this._cancelSeekBackfill = false;
    // cancel any queued _emitState that might later emit messages from before we seeked
    this._messages = [];

    // do not _emitState if subscriptions have changed, but time has not
    if (isEqual(this._currentTime, time)) {
      this._emitState();
    }

    if (!this._isPlaying) {
      this._getMessages(
        TimeUtil.add(clampTime(time, TimeUtil.add(this._start, { sec: 0, nsec: SEEK_BACK_NANOSECONDS }), this._end), {
          sec: 0,
          nsec: -SEEK_BACK_NANOSECONDS,
        }),
        time
      ).then((messages) => {
        // Only emit the messages if we haven't seeked again / emitted messages since we
        // started loading them. Note that for the latter part just checking for `isPlaying`
        // is not enough because the user might have started playback and then paused again!
        // Therefore we really need something like `this._cancelSeekBackfill`.
        if (this._lastSeekTime === seekTime && !this._cancelSeekBackfill) {
          this._messages = messages;
          this._emitState();
        }
      });
    }
  }
github cruise-automation / webviz / packages / webviz-core / src / dataProviders / MemoryCacheDataProvider.js View on Github external
while (true) {
      const currentConnection = this._currentConnection;
      if (!currentConnection || !isCurrent()) {
        return;
      }

      const currentBlockIndex = currentConnection.remainingBlockRange.start;
      // Only request topics that we don't already have.
      const topics = this._blocks[currentBlockIndex]
        ? currentConnection.topics.filter(
            (topic) => !this._blocks[currentBlockIndex] || !this._blocks[currentBlockIndex].messagesByTopic[topic]
          )
        : currentConnection.topics;

      // Get messages from the underlying provider.
      const startTime = TimeUtil.add(this._startTime, fromNanoSec(currentBlockIndex * MEM_CACHE_BLOCK_SIZE_NS));
      const endTime = TimeUtil.add(
        this._startTime,
        fromNanoSec(Math.min(this._totalNs, (currentBlockIndex + 1) * MEM_CACHE_BLOCK_SIZE_NS) - 1) // endTime is inclusive.
      );
      const messages = topics.length ? await this._provider.getMessages(startTime, endTime, topics) : [];

      // If we're not current any more, discard the messages, because otherwise we might write duplicate messages.
      if (!isCurrent()) {
        return;
      }

      // Create a new block if necessary.
      this._blocks[currentBlockIndex] = this._blocks[currentBlockIndex] || { messagesByTopic: {}, sizeInBytes: 0 };
      const currentBlock = this._blocks[currentBlockIndex];
      if (!currentBlock) {
        throw new Error("currentBlock should be set here");
github cruise-automation / webviz / packages / webviz-core / src / dataProviders / ReadAheadDataProvider.js View on Github external
const nextMatches = this._next && this._next.overlaps(start, end);
    if (/*:: this._current && */ currentMatches) {
      messages = messages.concat(await this._current.getMessages(start, end));
    }
    if (/*:: this._next && */ nextMatches) {
      messages = messages.concat(await this._next.getMessages(start, end));
    }
    if ((!currentMatches && !nextMatches) || (this._next && TimeUtil.isGreaterThan(end, this._next.end))) {
      let startTime = start;
      if (/*:: this._next && */ nextMatches) {
        startTime = TimeUtil.add(this._next.end, oneNanoSecond);
        log.info("readahead cache overrun - consider expanding readAheadRange");
      }
      this._current = this._makeReadResult(startTime, end, topics);
      await this._current.getMessages(startTime, end);
      const nextStart = TimeUtil.add(end, oneNanoSecond);
      this._next = this._makeReadResult(nextStart, TimeUtil.add(nextStart, this._readAheadRange), topics);
      messages = messages.concat(await this._getMessages(startTime, end, topics));
    } else if (/*:: this._next && */ nextMatches) {
      this._current = this._next;
      const nextStart = TimeUtil.add(this._current.end, oneNanoSecond);
      const nextEnd = TimeUtil.add(nextStart, this._readAheadRange);
      this._next = this._makeReadResult(nextStart, nextEnd, topics);
    }
    return messages.filter((message) => topics.includes(message.topic));
  }
}
github cruise-automation / webviz / packages / webviz-core / src / dataProviders / ReadAheadDataProvider.js View on Github external
}
    if ((!currentMatches && !nextMatches) || (this._next && TimeUtil.isGreaterThan(end, this._next.end))) {
      let startTime = start;
      if (/*:: this._next && */ nextMatches) {
        startTime = TimeUtil.add(this._next.end, oneNanoSecond);
        log.info("readahead cache overrun - consider expanding readAheadRange");
      }
      this._current = this._makeReadResult(startTime, end, topics);
      await this._current.getMessages(startTime, end);
      const nextStart = TimeUtil.add(end, oneNanoSecond);
      this._next = this._makeReadResult(nextStart, TimeUtil.add(nextStart, this._readAheadRange), topics);
      messages = messages.concat(await this._getMessages(startTime, end, topics));
    } else if (/*:: this._next && */ nextMatches) {
      this._current = this._next;
      const nextStart = TimeUtil.add(this._current.end, oneNanoSecond);
      const nextEnd = TimeUtil.add(nextStart, this._readAheadRange);
      this._next = this._makeReadResult(nextStart, nextEnd, topics);
    }
    return messages.filter((message) => topics.includes(message.topic));
  }
}
github cruise-automation / webviz / packages / webviz-core / src / dataProviders / ReadAheadDataProvider.js View on Github external
this._current = undefined;
      this._next = undefined;
    }
    let messages = [];
    const currentMatches = this._current && this._current.overlaps(start, end);
    const nextMatches = this._next && this._next.overlaps(start, end);
    if (/*:: this._current && */ currentMatches) {
      messages = messages.concat(await this._current.getMessages(start, end));
    }
    if (/*:: this._next && */ nextMatches) {
      messages = messages.concat(await this._next.getMessages(start, end));
    }
    if ((!currentMatches && !nextMatches) || (this._next && TimeUtil.isGreaterThan(end, this._next.end))) {
      let startTime = start;
      if (/*:: this._next && */ nextMatches) {
        startTime = TimeUtil.add(this._next.end, oneNanoSecond);
        log.info("readahead cache overrun - consider expanding readAheadRange");
      }
      this._current = this._makeReadResult(startTime, end, topics);
      await this._current.getMessages(startTime, end);
      const nextStart = TimeUtil.add(end, oneNanoSecond);
      this._next = this._makeReadResult(nextStart, TimeUtil.add(nextStart, this._readAheadRange), topics);
      messages = messages.concat(await this._getMessages(startTime, end, topics));
    } else if (/*:: this._next && */ nextMatches) {
      this._current = this._next;
      const nextStart = TimeUtil.add(this._current.end, oneNanoSecond);
      const nextEnd = TimeUtil.add(nextStart, this._readAheadRange);
      this._next = this._makeReadResult(nextStart, nextEnd, topics);
    }
    return messages.filter((message) => topics.includes(message.topic));
  }
}
github cruise-automation / webviz / packages / webviz-core / src / players / automatedRun / AutomatedRunPlayer.js View on Github external
while (TimeUtil.isLessThan(currentTime, this._providerResult.end)) {
      if (this._error) {
        return;
      }
      const end = TimeUtil.add(currentTime, { sec: 0, nsec: nsBagTimePerFrame });
      this._client.markTotalFrameStart();
      const messages = await this._getMessages(currentTime, end);

      this._client.markFrameRenderStart();
      await this._emitState(messages, end);
      this._client.markTotalFrameEnd();
      this._client.markFrameRenderEnd();

      await this._client.onFrameFinished(frameCount);

      currentTime = TimeUtil.add(end, { sec: 0, nsec: 1 });
      frameCount++;
    }

    await this._client.finish();
    logger.info("AutomatedRunPlayer._run() finished");
  }
github cruise-automation / webviz / packages / webviz-core / src / dataProviders / ReadAheadDataProvider.js View on Github external
if (/*:: this._current && */ currentMatches) {
      messages = messages.concat(await this._current.getMessages(start, end));
    }
    if (/*:: this._next && */ nextMatches) {
      messages = messages.concat(await this._next.getMessages(start, end));
    }
    if ((!currentMatches && !nextMatches) || (this._next && TimeUtil.isGreaterThan(end, this._next.end))) {
      let startTime = start;
      if (/*:: this._next && */ nextMatches) {
        startTime = TimeUtil.add(this._next.end, oneNanoSecond);
        log.info("readahead cache overrun - consider expanding readAheadRange");
      }
      this._current = this._makeReadResult(startTime, end, topics);
      await this._current.getMessages(startTime, end);
      const nextStart = TimeUtil.add(end, oneNanoSecond);
      this._next = this._makeReadResult(nextStart, TimeUtil.add(nextStart, this._readAheadRange), topics);
      messages = messages.concat(await this._getMessages(startTime, end, topics));
    } else if (/*:: this._next && */ nextMatches) {
      this._current = this._next;
      const nextStart = TimeUtil.add(this._current.end, oneNanoSecond);
      const nextEnd = TimeUtil.add(nextStart, this._readAheadRange);
      this._next = this._makeReadResult(nextStart, nextEnd, topics);
    }
    return messages.filter((message) => topics.includes(message.topic));
  }
}

rosbag

`rosbag` is a node.js & browser compatible module for reading [rosbag](http://wiki.ros.org/rosbag) binary data files.

Apache-2.0
Latest version published 1 year ago

Package Health Score

63 / 100
Full package analysis

Similar packages