cartographer/sensor/internal/dispatchable.h

Overview

Dispatchable<DataType> is a template wrapper that turns any sensor data structure into a Data (the polymorphic type transported through the collator). It stores a copy of the data together with its sensor ID and, when dispatched, routes it to the correct TrajectoryBuilderInterface method via the generic AddSensorData API.

Class: cartographer::sensor::Dispatchable

template <typename DataType>
class Dispatchable : public Data {
 public:
  Dispatchable(const std::string& sensor_id, const DataType& data)
      : Data(sensor_id), data_(data) {}

  common::Time GetTime() const override { return data_.time; }

  void AddToTrajectoryBuilder(
      mapping::TrajectoryBuilderInterface* const trajectory_builder) override {
    trajectory_builder->AddSensorData(sensor_id_, data_);
  }

  const DataType& data() const { return data_; }

 private:
  const DataType data_;
};
  • GetTime() — returns the underlying data’s time member, so collators can order packets by timestamp without knowing the concrete type.

  • AddToTrajectoryBuilder() — forwards the stored data through the trajectory builder’s templated AddSensorData(sensor_id, data).

  • data() — direct access to the wrapped payload.

Factory

template <typename DataType>
std::unique_ptr<Dispatchable<DataType>> MakeDispatchable(
    const std::string& sensor_id, const DataType& data);

Convenience factory used throughout the codebase.

Usage

// Sensor drivers wrap measurements before handing them to the collator:
sensor::RangeData range_data{origin, returns, misses};
auto data = sensor::MakeDispatchable("laser", range_data);
collator->AddSensorData(trajectory_id, std::move(data));

// The trajectory builder's generic entry point:
template <typename DataType>
void AddSensorData(const std::string& sensor_id, const DataType& data);

Because DataType only needs a public time member and must be accepted by the trajectory builder’s AddSensorData, this works uniformly for RangeData, ImuData, OdometryData, FixedFramePoseData, and LandmarkData.

Role in the SLAM Pipeline

  • Sensor drivers create Dispatchable wrappers via MakeDispatchable.

  • Collator / TrajectoryCollator store and reorder these as std::unique_ptr<Data>.

  • On dispatch, the collator callback invokes data->AddToTrajectoryBuilder(...), which lands on the right typed AddSensorData overload.

See Also