-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
124 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
LIST(APPEND apps | ||
simple | ||
jacobian | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#include <gtest/gtest.h> | ||
#include <spiceweasel.hpp> | ||
#include <vector> | ||
// #include <vector> | ||
|
||
using namespace std; | ||
|
||
TEST(navigation, wgs84) { EXPECT_TRUE(true); } | ||
TEST(spiceweasel, kf) { EXPECT_TRUE(true); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
#pragma once | ||
|
||
/* | ||
1D Kalman Filter | ||
*/ | ||
class KalmanFilter1D { | ||
float P{1.0}; // Initial estimate error | ||
float F{1.0}; // Assuming constant velocity | ||
float x{1.0}; // state estimate | ||
float Q; // processes noise | ||
float R; // measurement noise | ||
|
||
public: | ||
KalmanFilter1D(float q, float r) { | ||
Q = q; | ||
R = r; | ||
} | ||
|
||
float filter(float z) { | ||
// Prediction | ||
float xx = x * F; | ||
float P = P + Q; | ||
|
||
// Update | ||
float K = P / (P + R); | ||
x = xx + K * (z - xx); | ||
P = (1.0f - K) * P; | ||
|
||
return x; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
#pragma once | ||
|
||
// #include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
// #include <string.h> | ||
|
||
// namespace spiceweasel { | ||
|
||
template<typename T, int WINDOW = 3> | ||
class MedianFilter { | ||
public: | ||
static_assert(WINDOW >= 3, "MedianFilter::window size must be >= 3"); | ||
static_assert(WINDOW % 2, "MedianFilter::window size must be odd"); | ||
|
||
MedianFilter() { | ||
memset(buffer,0,WINDOW*sizeof(T)); | ||
memset(sorted,0,WINDOW*sizeof(T)); | ||
} | ||
|
||
T filter(const T &sample) { | ||
p = (p + 1) % WINDOW; | ||
buffer[p] = sample; | ||
|
||
memcpy(sorted, buffer, sizeof(buffer)); | ||
qsort(&sorted, WINDOW, sizeof(T), cmp); | ||
|
||
return sorted[WINDOW / 2]; | ||
} | ||
|
||
protected: | ||
static int cmp(const void *a, const void *b) { | ||
// return (*(T *)a >= *(T *)b) ? 1 : -1; | ||
return (*static_cast<T*>(a) >= *static_cast<T*>(b)) ? 1 : -1; | ||
} | ||
|
||
T buffer[WINDOW]{0.0}; | ||
T sorted[WINDOW]{0.0}; | ||
uint8_t p{0}; | ||
}; | ||
|
||
// } // namespace spiceweasel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters