From 9cca4ffd9987352e43119d9c4dea0ce84c2c448f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 5 Oct 2018 15:59:58 +0200 Subject: silly busywork --- logic/pipeline.cpp | 52 ++++++++++++++++++---------------------------------- logic/pipeline.hpp | 36 +++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 51 deletions(-) (limited to 'logic') diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp index bd7f8300..73f51509 100644 --- a/logic/pipeline.cpp +++ b/logic/pipeline.cpp @@ -28,9 +28,7 @@ # include #endif -using namespace euler; -using namespace time_units; -using namespace pipeline_impl; +namespace pipeline_impl { static constexpr inline double r2d = 180. / M_PI; static constexpr inline double d2r = M_PI / 180.; @@ -158,9 +156,7 @@ Pose reltrans::apply_pipeline(reltrans_state state, const Pose& value, } } else - { interp_pos = rel; - } } else { @@ -295,7 +291,7 @@ bool pipeline::maybe_enable_center_on_tracking_started() if (tracking_started && s.center_at_startup) { - set(f_center, true); + b.set(f_center, true); return true; } } @@ -305,28 +301,18 @@ bool pipeline::maybe_enable_center_on_tracking_started() void pipeline::maybe_set_center_pose(const Pose& value, bool own_center_logic) { - if (get(f_center | f_held_center)) + if (b.get(f_center | f_held_center)) { if (libs.pFilter) libs.pFilter->center(); if (own_center_logic) { -#if 0 - state.inv_rot_center = rmat::eye(); - state.t_center = {}; -#endif - scaled_state.inv_rot_center = rmat::eye(); scaled_state.t_center = {}; } else { -#if 0 - state.inv_rot_center = state.inv_rot_center; - state.t_center = (const double*)(value); -#endif - scaled_state.inv_rot_center = scaled_state.rotation.t(); scaled_state.t_center = (const double*)(value); } @@ -335,10 +321,6 @@ void pipeline::maybe_set_center_pose(const Pose& value, bool own_center_logic) void pipeline::store_tracker_pose(const Pose& value) { -#if 0 - euler_t tmp(d2r * euler_t(&value[Yaw])); - state.rotation = euler_to_rmat(tmp); -#endif // alas, this is poor man's gimbal lock "prevention" // this is some kind of "canonical" representation, // if we can even talk of one @@ -464,9 +446,9 @@ void pipeline::logic() logger.reset_dt(); // we must center prior to getting data from the tracker - const bool center_ordered = get(f_center | f_held_center) && tracking_started; + const bool center_ordered = b.get(f_center | f_held_center) && tracking_started; const bool own_center_logic = center_ordered && libs.pTracker->center(); - const bool hold_ordered = get(f_enabled_p) ^ get(f_enabled_h); + const bool hold_ordered = b.get(f_enabled_p) ^ b.get(f_enabled_h); { Pose tmp; @@ -535,9 +517,9 @@ error: ok: - set(f_center, false); + b.set(f_center, false); - if (get(f_zero)) + if (b.get(f_zero)) for (int i = 0; i < 6; i++) value(i) = 0; @@ -650,20 +632,20 @@ void pipeline::raw_and_mapped_pose(double* mapped, double* raw) const } } -void pipeline::set_center() { set(f_center, true); } +void pipeline::set_center() { b.set(f_center, true); } void pipeline::set_held_center(bool value) { - set(f_held_center, value); + b.set(f_held_center, value); } -void pipeline::set_enabled(bool value) { set(f_enabled_h, value); } -void pipeline::set_zero(bool value) { set(f_zero, value); } +void pipeline::set_enabled(bool value) { b.set(f_enabled_h, value); } +void pipeline::set_zero(bool value) { b.set(f_zero, value); } -void pipeline::toggle_zero() { negate(f_zero); } -void pipeline::toggle_enabled() { negate(f_enabled_p); } +void pipeline::toggle_zero() { b.negate(f_zero); } +void pipeline::toggle_enabled() { b.negate(f_enabled_p); } -void bits::set(flags flag, bool val) +void bits::set(bit_flags flag, bool val) { const unsigned flag_ = unsigned(flag); const unsigned val_ = unsigned(val); @@ -674,7 +656,7 @@ void bits::set(flags flag, bool val) break; } -void bits::negate(flags flag) +void bits::negate(bit_flags flag) { const unsigned flag_= flag; unsigned b_ = 0; @@ -684,7 +666,7 @@ void bits::negate(flags flag) break; } -bool bits::get(flags flag) +bool bits::get(bit_flags flag) { return !!(b & flag); } @@ -697,3 +679,5 @@ bits::bits() : b(0u) set(f_enabled_h, true); set(f_zero, false); } + +} // ns pipeline_impl diff --git a/logic/pipeline.hpp b/logic/pipeline.hpp index 0cdeebfb..3be4f45e 100644 --- a/logic/pipeline.hpp +++ b/logic/pipeline.hpp @@ -25,8 +25,8 @@ namespace pipeline_impl { -using rmat = euler::rmat; -using euler_t = euler::euler_t; +using namespace euler; +using namespace time_units; using vec6_bool = Mat; using vec3_bool = Mat; @@ -49,7 +49,7 @@ class reltrans // this implements smooth transition into reltrans mode // once not aiming anymore. see `apply_pipeline()'. Timer interp_phase_timer; - unsigned RC_phase = 0; + unsigned RC_stage = 0; bool cur = false; bool in_zone = false; @@ -72,27 +72,27 @@ public: using namespace time_units; -struct OTR_LOGIC_EXPORT bits -{ - enum flags : unsigned { - f_center = 1 << 0, - f_held_center = 1 << 1, - f_enabled_h = 1 << 2, - f_enabled_p = 1 << 3, - f_zero = 1 << 4, - }; +enum bit_flags : unsigned { + f_center = 1 << 0, + f_held_center = 1 << 1, + f_enabled_h = 1 << 2, + f_enabled_p = 1 << 3, + f_zero = 1 << 4, +}; +struct OTR_LOGIC_EXPORT bits +{ std::atomic b; - void set(flags flag, bool val); - void negate(flags flag); - bool get(flags flag); + void set(bit_flags flag, bool val); + void negate(bit_flags flag); + bool get(bit_flags flag); bits(); }; -DEFINE_ENUM_OPERATORS(bits::flags); +DEFINE_ENUM_OPERATORS(bit_flags); -class OTR_LOGIC_EXPORT pipeline : private QThread, private bits +class OTR_LOGIC_EXPORT pipeline : private QThread { Q_OBJECT @@ -133,6 +133,8 @@ class OTR_LOGIC_EXPORT pipeline : private QThread, private bits Pose apply_reltrans(Pose value, vec6_bool disabled, bool centerp); Pose apply_zero_pos(Pose value) const; + bits b; + public: pipeline(Mappings& m, runtime_libraries& libs, event_handler& ev, TrackLogger& logger); ~pipeline() override; -- cgit v1.2.3