Skip to content

Commit

Permalink
tracker/pt: improve point filter somewhat
Browse files Browse the repository at this point in the history
Moving LEDs at different speeds results in nonsensical poses so use the
deltas from the fastest moving point.
  • Loading branch information
sthalik committed Oct 4, 2021
1 parent 38514e2 commit 76d9145
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tracker-pt/point-filter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "point-filter.hpp"
#include <algorithm>
#include <cmath>
#include <QDebug>

namespace pt_point_filter_impl {
Expand Down Expand Up @@ -29,27 +31,29 @@ const PointOrder& point_filter::operator()(const PointOrder& input)
constexpr int A = 1'000'000;
double K = *s.point_filter_coefficient;
f log10_pos = -2 + (int)K, rest = (f)(.999-fmod(K, 1.)*.9);
return A * pow((f)10, (f)-log10_pos) * rest;
return A * std::pow((f)10, (f)-log10_pos) * rest;
);
f dist[3], norm = 0;

f dist = 0;

for (unsigned i = 0; i < 3; i++)
{
vec2 tmp = input[i] - state_[i];
f x = sqrt(tmp.dot(tmp));
dist[i] = x;
norm += x;
dist = std::max((f)0, x);
}

if (norm < (f)1e-6)
if (dist < (f)1e-6)
return state_;

f dt = (f)t->elapsed_seconds(); t->start();
f delta = pow(norm, E) * C * dt; // gain
f delta = std::pow(dist, E) * C * dt; // gain

//qDebug() << "gain" << std::min((f)1, delta);

for (unsigned i = 0; i < 3; i++)
{
f x = std::clamp(delta * dist[i] / norm, (f)0, (f)1);
f x = std::clamp(delta, (f)0, (f)1);
state_[i] += x*(input[i] - state_[i]);
}

Expand Down

0 comments on commit 76d9145

Please sign in to comment.