Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete rewrite #13

Merged
merged 23 commits into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Typing adjustments.
  • Loading branch information
ashtuchkin committed Feb 16, 2017
commit 260e1d5bc8146999e6a4f44ac2dea0f506affe4c
11 changes: 6 additions & 5 deletions src/cycle_phase_classifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ enum PhaseFixLevels {
};

CyclePhaseClassifier::CyclePhaseClassifier()
: prev_full_cycle_idx_(0)
, phase_history_(0)
: prev_full_cycle_idx_()
, phase_history_()
, fix_level_(kPhaseFixNone)
, phase_shift_(0)
, pulse_base_len_(0.0)
, bits_()
, phase_shift_()
, pulse_base_len_()
, bits_{}
, average_error_()
, debug_print_state_(false) {
reset();
}
Expand Down
2 changes: 1 addition & 1 deletion src/data_frame_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DataFrameDecoder::DataFrameDecoder(uint32_t base_station_idx)
, cur_bit_idx_(0)
, data_idx_(0)
, data_frame_len_(0)
, data_frame_() {
, data_frame_{} {
}

void DataFrameDecoder::consume(const DataFrameBit& frame_bit) {
Expand Down
6 changes: 4 additions & 2 deletions src/primitives/timestamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class TimeDelta {
// Constructors
constexpr TimeDelta(): time_delta_(0) {} // Default constructor to make it possible to include it in structs.
constexpr TimeDelta(int val, TimeUnit tu): time_delta_(val * tu) {} // Main way to create TimeDelta: value and TimeUnit.
constexpr TimeDelta(const TimeDelta& other) = default;
constexpr TimeDelta& operator=(const TimeDelta& other) = default;

constexpr int get_value(TimeUnit tu) const { return time_delta_ / tu; }

Expand Down Expand Up @@ -59,8 +61,8 @@ class Timestamp {
public:
// Constructors.
constexpr Timestamp(): time_(0) {} // Default constructor. We need it to be able to keep Timestamp in structs.
constexpr Timestamp(const Timestamp& other): time_(other.time_) {}
inline Timestamp& operator=(const Timestamp& other) { time_ = other.time_; return *this; }
constexpr Timestamp(const Timestamp& other) = default;
constexpr Timestamp& operator=(const Timestamp& other) = default;

// Get adjusted value of this timestamp in provided time unit.
// We try to "extend" the value outside of regular period of timestamp using current time in millis.
Expand Down
5 changes: 4 additions & 1 deletion src/primitives/vector.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Simple version of vector with dynamic length, but fixed capacity.
// Only compatible with value or POD types, not classes (it doesn't do construction/destruction).
#pragma once
#include <type_traits>
#include <assert.h>

// Type T, Capacity C.
template<typename T, unsigned C>
class Vector {
static_assert(C > 0, "Please provide positive capacity");
static_assert(std::is_trivially_destructible<T>(), "Vector only works on simple types");
static_assert(std::is_trivially_copyable<T>(), "Vector only works on simple types");
public:
Vector(): size_(0) {}
Vector() : size_{} {}
inline unsigned long size() const { return size_; }
inline unsigned long max_size() const { return C; }
inline bool empty() const { return size_ == 0; }
Expand Down
6 changes: 5 additions & 1 deletion src/pulse_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ PulseProcessor::PulseProcessor(uint32_t num_inputs)
: num_inputs_(num_inputs)
, cycle_fix_level_(0)
, cycle_idx_(0)
, angles_frame_()
, cycle_long_pulses_{}
, cycle_short_pulses_{}
, unclassified_long_pulses_{}
, phase_classifier_{}
, angles_frame_{}
, time_from_last_long_pulse_(0, usec)
, debug_print_state_(false) {
angles_frame_.sensors.set_size(num_inputs);
Expand Down
6 changes: 5 additions & 1 deletion src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ b1 origin 1.718700 2.543170 0.725060 matrix 0.458350 -0.649590 0.606590 0.028970

PersistentSettings settings;

PersistentSettings::PersistentSettings() : is_configured_(false) {
PersistentSettings::PersistentSettings()
: is_configured_(false)
, inputs_{}
, base_stations_{}
, geo_builders_{} {
read_from_eeprom();
}

Expand Down
5 changes: 3 additions & 2 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <type_traits>

class PersistentSettings {
static_assert(std::is_pod<InputDef>(), "InputDef must be POD");
static_assert(std::is_pod<BaseStationGeometryDef>(), "BaseStationGeometryDef must be POD");
public:
// Data accessors
inline const Vector<InputDef, max_num_inputs> &inputs() const { return inputs_; }
Expand Down Expand Up @@ -39,6 +37,9 @@ class PersistentSettings {
};

static_assert(sizeof(PersistentSettings) < 1500, "PersistentSettings must fit into eeprom");
static_assert(std::is_trivially_copyable<InputDef>(), "InputDef must be trivially copyable type");
static_assert(std::is_trivially_copyable<BaseStationGeometryDef>(), "BaseStationGeometryDef must be trivially copyable type");
static_assert(std::is_trivially_copyable<GeometryBuilderDef>(), "GeometryBuilderDef must be trivially copyable type");

// Singleton to access current settings.
extern PersistentSettings settings;
4 changes: 2 additions & 2 deletions src/vive_sensors_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ std::unique_ptr<Pipeline> create_vive_sensor_pipeline(const PersistentSettings &
auto pulse_processor = pipeline->emplace_back(std::make_unique<PulseProcessor>(settings.inputs().size()));

// Create input nodes as configured.
Vector<InputNode *, max_num_inputs> input_nodes;
Vector<InputNode *, max_num_inputs> input_nodes{};
for (uint32_t input_idx = 0; input_idx < settings.inputs().size(); input_idx++) {
auto input_def = settings.inputs()[input_idx];
auto input_node = pipeline->emplace_front(InputNode::create(input_idx, input_def));
Expand All @@ -33,7 +33,7 @@ std::unique_ptr<Pipeline> create_vive_sensor_pipeline(const PersistentSettings &
}

// Create geometry builders as configured.
Vector<GeometryBuilder *, max_num_inputs> geometry_builders;
Vector<GeometryBuilder *, max_num_inputs> geometry_builders{};
if (settings.geo_builders().size() > 0 && settings.base_stations().size() != 2)
throw_printf("2 base stations must be defined to use geometry builders.");

Expand Down