Skip to content

Commit

Permalink
Fix possible "Position is NaN"
Browse files Browse the repository at this point in the history
  • Loading branch information
Timocop committed Feb 4, 2024
1 parent e65ca2f commit e25950f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/psmoveservice/Filter/PositionFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ void PositionFilterKalman::update(

// Update for each dimension
for (int i = 0; i < 3; ++i) {
if (kal_err_estimate[i] <= k_real_epsilon)
if (kal_err_estimate[i] <= k_real_epsilon || (kal_err_estimate[i] + kalman_position_error) <= k_real_epsilon)
{
kal_err_estimate[i] = kalman_position_error;
}
Expand Down
40 changes: 36 additions & 4 deletions src/psmoveservice/Filter/PositionFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,31 @@ class PositionFilter : public IPositionFilter
class PositionFilterPassThru : public PositionFilter
{
public:
PositionFilterPassThru()
: PositionFilter()
, m_resetVelocity(false)
{
lastOpticalFrame = std::chrono::high_resolution_clock::now();
}

void update(const t_high_resolution_timepoint timestamp, const PoseFilterPacket &packet) override;
t_high_resolution_timepoint lastOpticalFrame;
bool m_resetVelocity = false;
bool m_resetVelocity;
};

class PositionFilterLowPassOptical : public PositionFilter
{
public:
PositionFilterLowPassOptical()
: PositionFilter()
, m_resetVelocity(false)
{
lastOpticalFrame = std::chrono::high_resolution_clock::now();
}

void update(const t_high_resolution_timepoint timestamp, const PoseFilterPacket &packet) override;
t_high_resolution_timepoint lastOpticalFrame;
bool m_resetVelocity = false;
bool m_resetVelocity;
};

class PositionFilterLowPassIMU : public PositionFilter
Expand All @@ -71,7 +85,6 @@ class PositionFilterLowPassIMU : public PositionFilter

class PositionFilterLowPassExponential : public PositionFilter
{
public:
void update(const t_high_resolution_timepoint timestamp, const PoseFilterPacket &packet) override;
std::list<float> deltaTimeHistory;
std::list<Eigen::Vector3f> blendedPositionHistory;
Expand All @@ -80,16 +93,35 @@ class PositionFilterLowPassExponential : public PositionFilter
class PositionFilterComplimentaryOpticalIMU : public PositionFilter
{
public:
PositionFilterComplimentaryOpticalIMU()
: PositionFilter()
{
lastOpticalFrame = std::chrono::high_resolution_clock::now();
}

void update(const t_high_resolution_timepoint timestamp, const PoseFilterPacket &packet) override;
t_high_resolution_timepoint lastOpticalFrame;
};

class PositionFilterKalman : public PositionFilter
{
public:
PositionFilterKalman()
: PositionFilter()
, m_resetVelocity(false)
{
kal_err_estimate[0] = 0.0;
kal_err_estimate[1] = 0.0;
kal_err_estimate[2] = 0.0;

kal_current_estimate = Eigen::Vector3f::Zero();
kal_gain = Eigen::Vector3f::Zero();
lastOpticalFrame = std::chrono::high_resolution_clock::now();
}

void update(const t_high_resolution_timepoint timestamp, const PoseFilterPacket &packet) override;
t_high_resolution_timepoint lastOpticalFrame;
bool m_resetVelocity = false;
bool m_resetVelocity;

private:
float kal_err_estimate[3];
Expand Down

0 comments on commit e25950f

Please sign in to comment.