Skip to content

Commit fced616

Browse files
committed
Fix Madgwick not resetting orientation on init
1 parent 8aab89f commit fced616

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/psmoveservice/Filter/OrientationFilter.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void OrientationFilterPassThru::update(const float delta_time, const PoseFilterP
250250
void OrientationFilterMadgwickARG::resetState()
251251
{
252252
OrientationFilter::resetState();
253-
timeReset = std::chrono::high_resolution_clock::now();
253+
m_reset = true;
254254
}
255255

256256
// -- OrientationFilterMadgwickARG --
@@ -380,6 +380,12 @@ void OrientationFilterMadgwickARG::update(const float delta_time, const PoseFilt
380380
const float adaptive_falloff = clampf(filter_madgwick_apt_falloff, 0.0f, 0.999f);
381381

382382
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
383+
if (m_reset)
384+
{
385+
m_reset = false;
386+
timeReset = now;
387+
}
388+
383389
std::chrono::duration<double, std::milli> resetDuration = now - timeReset;
384390

385391
if (resetDuration.count() < k_madgwick_reset_time)
@@ -445,7 +451,7 @@ void OrientationFilterMadgwickMARG::resetState()
445451
{
446452
OrientationFilterMadgwickARG::resetState();
447453
m_omega_bias_x= m_omega_bias_y= m_omega_bias_z= 0.f;
448-
timeReset = std::chrono::high_resolution_clock::now();
454+
m_reset = true;
449455
}
450456

451457
void OrientationFilterMadgwickMARG::update(const float delta_time, const PoseFilterPacket &packet)
@@ -619,6 +625,12 @@ void OrientationFilterMadgwickMARG::update(const float delta_time, const PoseFil
619625
const float adaptive_falloff = clampf(filter_madgwick_apt_falloff, 0.0f, 0.999f);
620626

621627
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
628+
if (m_reset)
629+
{
630+
m_reset = false;
631+
timeReset = now;
632+
}
633+
622634
std::chrono::duration<double, std::milli> resetDuration = now - timeReset;
623635

624636
if (resetDuration.count() < k_madgwick_reset_time)

src/psmoveservice/Filter/OrientationFilter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class OrientationFilterMadgwickARG : public OrientationFilter
6969
OrientationFilterMadgwickARG()
7070
: OrientationFilter()
7171
, m_beta(0.f)
72+
, m_reset(true)
7273
{
7374
timeReset = std::chrono::high_resolution_clock::now();
7475
}
@@ -78,6 +79,7 @@ class OrientationFilterMadgwickARG : public OrientationFilter
7879

7980
protected:
8081
float m_beta;
82+
float m_reset;
8183
std::chrono::time_point<std::chrono::high_resolution_clock> timeReset;
8284
};
8385

@@ -91,6 +93,7 @@ class OrientationFilterMadgwickMARG : public OrientationFilterMadgwickARG
9193
, m_omega_bias_y(0.f)
9294
, m_omega_bias_z(0.f)
9395
, m_beta(0.f)
96+
, m_reset(true)
9497
{
9598
timeReset = std::chrono::high_resolution_clock::now();
9699
}
@@ -103,6 +106,7 @@ class OrientationFilterMadgwickMARG : public OrientationFilterMadgwickARG
103106
float m_omega_bias_y;
104107
float m_omega_bias_z;
105108
float m_beta;
109+
float m_reset;
106110
std::chrono::time_point<std::chrono::high_resolution_clock> timeReset;
107111
};
108112

0 commit comments

Comments
 (0)