Removes templating on data type. (#68)
parent
2eca021003
commit
f798805c4f
|
@ -28,6 +28,7 @@
|
||||||
#include "cartographer/common/make_unique.h"
|
#include "cartographer/common/make_unique.h"
|
||||||
#include "cartographer/common/ordered_multi_queue.h"
|
#include "cartographer/common/ordered_multi_queue.h"
|
||||||
#include "cartographer/common/time.h"
|
#include "cartographer/common/time.h"
|
||||||
|
#include "cartographer/sensor/data.h"
|
||||||
#include "cartographer/sensor/sensor_packet_period_histogram_builder.h"
|
#include "cartographer/sensor/sensor_packet_period_histogram_builder.h"
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
|
@ -49,10 +50,9 @@ inline std::ostream& operator<<(std::ostream& out,
|
||||||
return out << '(' << key.trajectory_id << ", " << key.sensor_id << ')';
|
return out << '(' << key.trajectory_id << ", " << key.sensor_id << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename SensorDataType>
|
|
||||||
class Collator {
|
class Collator {
|
||||||
public:
|
public:
|
||||||
using Callback = std::function<void(int64, std::unique_ptr<SensorDataType>)>;
|
using Callback = std::function<void(int64, std::unique_ptr<Data>)>;
|
||||||
|
|
||||||
Collator() {}
|
Collator() {}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class Collator {
|
||||||
// added in time order.
|
// added in time order.
|
||||||
void AddSensorData(const int trajectory_id, const int64 timestamp,
|
void AddSensorData(const int trajectory_id, const int64 timestamp,
|
||||||
const string& sensor_id,
|
const string& sensor_id,
|
||||||
std::unique_ptr<SensorDataType> sensor_data) {
|
std::unique_ptr<Data> sensor_data) {
|
||||||
sensor_packet_period_histogram_builder_.Add(trajectory_id, timestamp,
|
sensor_packet_period_histogram_builder_.Add(trajectory_id, timestamp,
|
||||||
sensor_id);
|
sensor_id);
|
||||||
queue_.Add(
|
queue_.Add(
|
||||||
|
@ -113,7 +113,7 @@ class Collator {
|
||||||
private:
|
private:
|
||||||
struct Value {
|
struct Value {
|
||||||
int64 timestamp;
|
int64 timestamp;
|
||||||
std::unique_ptr<SensorDataType> sensor_data;
|
std::unique_ptr<Data> sensor_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Queue keys are a pair of trajectory ID and sensor identifier.
|
// Queue keys are a pair of trajectory ID and sensor identifier.
|
||||||
|
|
|
@ -28,40 +28,36 @@ namespace cartographer {
|
||||||
namespace sensor {
|
namespace sensor {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct TestData {
|
|
||||||
string frame_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST(Collator, Ordering) {
|
TEST(Collator, Ordering) {
|
||||||
TestData first{"horizontal_laser"};
|
Data first("horizontal_laser", sensor::LaserFan{});
|
||||||
TestData second{"vertical_laser"};
|
Data second("vertical_laser", sensor::LaserFan{});
|
||||||
TestData third{"imu"};
|
Data third("imu", Data::Imu{});
|
||||||
TestData fourth{"horizontal_laser"};
|
Data fourth("horizontal_laser", sensor::LaserFan{});
|
||||||
TestData fifth{"vertical_laser"};
|
Data fifth("vertical_laser", sensor::LaserFan{});
|
||||||
TestData sixth{"something"};
|
Data sixth("odometry", Data::Odometry{});
|
||||||
|
|
||||||
const std::unordered_set<string> frame_ids = {
|
const std::unordered_set<string> frame_ids = {
|
||||||
"horizontal_laser", "vertical_laser", "imu", "something"};
|
"horizontal_laser", "vertical_laser", "imu", "odometry"};
|
||||||
std::vector<std::pair<int64, TestData>> received;
|
std::vector<std::pair<int64, Data>> received;
|
||||||
Collator<TestData> collator;
|
Collator collator;
|
||||||
collator.AddTrajectory(
|
collator.AddTrajectory(
|
||||||
0, frame_ids,
|
0, frame_ids,
|
||||||
[&received](const int64 timestamp, std::unique_ptr<TestData> packet) {
|
[&received](const int64 timestamp, std::unique_ptr<Data> packet) {
|
||||||
received.push_back(std::make_pair(timestamp, *packet));
|
received.push_back(std::make_pair(timestamp, *packet));
|
||||||
});
|
});
|
||||||
|
|
||||||
collator.AddSensorData(0, 100, first.frame_id,
|
collator.AddSensorData(0, 100, first.frame_id,
|
||||||
common::make_unique<TestData>(first));
|
common::make_unique<Data>(first));
|
||||||
collator.AddSensorData(0, 600, sixth.frame_id,
|
collator.AddSensorData(0, 600, sixth.frame_id,
|
||||||
common::make_unique<TestData>(sixth));
|
common::make_unique<Data>(sixth));
|
||||||
collator.AddSensorData(0, 400, fourth.frame_id,
|
collator.AddSensorData(0, 400, fourth.frame_id,
|
||||||
common::make_unique<TestData>(fourth));
|
common::make_unique<Data>(fourth));
|
||||||
collator.AddSensorData(0, 200, second.frame_id,
|
collator.AddSensorData(0, 200, second.frame_id,
|
||||||
common::make_unique<TestData>(second));
|
common::make_unique<Data>(second));
|
||||||
collator.AddSensorData(0, 500, fifth.frame_id,
|
collator.AddSensorData(0, 500, fifth.frame_id,
|
||||||
common::make_unique<TestData>(fifth));
|
common::make_unique<Data>(fifth));
|
||||||
collator.AddSensorData(0, 300, third.frame_id,
|
collator.AddSensorData(0, 300, third.frame_id,
|
||||||
common::make_unique<TestData>(third));
|
common::make_unique<Data>(third));
|
||||||
|
|
||||||
EXPECT_EQ(3, received.size());
|
EXPECT_EQ(3, received.size());
|
||||||
EXPECT_EQ(100, received[0].first);
|
EXPECT_EQ(100, received[0].first);
|
||||||
|
@ -78,7 +74,7 @@ TEST(Collator, Ordering) {
|
||||||
EXPECT_EQ(500, received[4].first);
|
EXPECT_EQ(500, received[4].first);
|
||||||
EXPECT_EQ("vertical_laser", received[4].second.frame_id);
|
EXPECT_EQ("vertical_laser", received[4].second.frame_id);
|
||||||
EXPECT_EQ(600, received[5].first);
|
EXPECT_EQ(600, received[5].first);
|
||||||
EXPECT_EQ("something", received[5].second.frame_id);
|
EXPECT_EQ("odometry", received[5].second.frame_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Reference in New Issue