clang-tidy fixes, documentation, refactoring.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include <scmp/geom/Quaternion.h>
|
||||
#include <scmp/Math.h>
|
||||
|
||||
#include <scmp/filter/Madgwick.h>
|
||||
#include <scmp/estimation/Madgwick.h>
|
||||
#include <sctest/Assert.h>
|
||||
#include <sctest/Checks.h>
|
||||
#include <sctest/SimpleSuite.h>
|
||||
@@ -20,22 +20,22 @@ using namespace scmp;
|
||||
bool
|
||||
SimpleAngularOrientationFloat()
|
||||
{
|
||||
filter::Madgwickf mflt;
|
||||
const geom::Vector3F gyro{0.174533, 0.0, 0.0}; // 10° X rotation.
|
||||
estimation::Madgwickf estimation;
|
||||
const geom::Vector3F gyro{0.174533, 0.0, 0.0}; // 10° X rotation.
|
||||
const geom::Quaternionf frame20Deg{0.984808, 0.173648, 0, 0}; // 20° final Orientation.
|
||||
const float delta = 0.00917; // assume 109 updates per second, as per the paper.
|
||||
const float twentyDegrees = scmp::DegreesToRadiansF(20.0);
|
||||
const float delta = 0.00917; // assume 109 updates per second, as per the paper.
|
||||
const float twentyDegrees = scmp::DegreesToRadiansF(20.0);
|
||||
|
||||
// The paper specifies a minimum of 109 IMU readings to stabilize; for
|
||||
// two seconds, that means 218 updates.
|
||||
for (int i = 0; i < 218; i++) {
|
||||
mflt.UpdateAngularOrientation(gyro, delta);
|
||||
estimation.UpdateAngularOrientation(gyro, delta);
|
||||
}
|
||||
|
||||
|
||||
SCTEST_CHECK_EQ(mflt.Orientation(), frame20Deg);
|
||||
SCTEST_CHECK_EQ(estimation.Orientation(), frame20Deg);
|
||||
|
||||
auto euler = mflt.Euler();
|
||||
auto euler = estimation.Euler();
|
||||
SCTEST_CHECK_FEQ_EPS(euler[0], twentyDegrees, 0.01);
|
||||
SCTEST_CHECK_FEQ_EPS(euler[1], 0.0, 0.01);
|
||||
SCTEST_CHECK_FEQ_EPS(euler[2], 0.0, 0.01);
|
||||
@@ -47,7 +47,7 @@ SimpleAngularOrientationFloat()
|
||||
bool
|
||||
SimpleAngularOrientationFloatDefaultDT()
|
||||
{
|
||||
filter::Madgwickf mflt;
|
||||
estimation::Madgwickf mflt;
|
||||
const geom::Vector3F gyro{0.174533, 0.0, 0.0}; // 10° X rotation.
|
||||
const geom::Quaternionf frame20Deg{0.984808, 0.173648, 0, 0}; // 20° final Orientation.
|
||||
const float delta = 0.00917; // assume 109 updates per second, as per the paper.
|
||||
@@ -75,7 +75,7 @@ SimpleAngularOrientationFloatDefaultDT()
|
||||
bool
|
||||
VerifyUpdateWithZeroDeltaTFails()
|
||||
{
|
||||
filter::Madgwickf mflt;
|
||||
estimation::Madgwickf mflt;
|
||||
const geom::Vector3F gyro{0.174533, 0.0, 0.0}; // 10° X rotation.
|
||||
const geom::Quaternionf frame20Deg{0.984808, 0.173648, 0, 0}; // 20° final Orientation.
|
||||
const float twentyDegrees = scmp::DegreesToRadiansF(20.0);
|
||||
@@ -100,7 +100,7 @@ VerifyUpdateWithZeroDeltaTFails()
|
||||
bool
|
||||
SimpleAngularOrientationDouble()
|
||||
{
|
||||
filter::Madgwickd mflt;
|
||||
estimation::Madgwickd mflt;
|
||||
const geom::Vector3D gyro{0.174533, 0.0, 0.0}; // 10° X rotation.
|
||||
const geom::Quaterniond frame20Deg{0.984808, 0.173648, 0, 0}; // 20° final Orientation.
|
||||
const double delta = 0.00917; // assume 109 updates per second, as per the paper.
|
||||
@@ -127,7 +127,7 @@ bool
|
||||
SimpleAngularOrientation2InitialVector3f()
|
||||
{
|
||||
const geom::Vector3F initialFrame{0, 0, 0};
|
||||
filter::Madgwickf mflt(initialFrame);
|
||||
estimation::Madgwickf mflt(initialFrame);
|
||||
const geom::Vector3F gyro{0.174533, 0.0, 0.0}; // 10° X rotation.
|
||||
const geom::Quaternionf frame20Deg{0.984808, 0.173648, 0, 0}; // 20° final Orientation.
|
||||
const float delta = 0.00917; // assume 109 updates per second, as per the paper.
|
||||
@@ -154,7 +154,7 @@ bool
|
||||
SimpleAngularOrientation2InitialQuaternionf()
|
||||
{
|
||||
const auto initialFrame = geom::FloatQuaternionFromEuler({0, 0, 0});
|
||||
filter::Madgwickf mflt(initialFrame);
|
||||
estimation::Madgwickf mflt(initialFrame);
|
||||
const geom::Vector3F gyro{0.174533, 0.0, 0.0}; // 10° X rotation.
|
||||
const geom::Quaternionf frame20Deg{0.984808, 0.173648, 0, 0}; // 20° final Orientation.
|
||||
const float delta = 0.00917; // assume 109 updates per second, as per the paper.
|
||||
@@ -181,7 +181,7 @@ bool
|
||||
SimpleAngularOrientation2InitialVector3d()
|
||||
{
|
||||
const geom::Vector3D initialFrame{0, 0, 0};
|
||||
filter::Madgwickd mflt(initialFrame);
|
||||
estimation::Madgwickd mflt(initialFrame);
|
||||
const geom::Vector3D gyro{0.174533, 0.0, 0.0}; // 10° X rotation.
|
||||
const geom::Quaterniond frame20Deg{0.984808, 0.173648, 0, 0}; // 20° final Orientation.
|
||||
const double delta = 0.00917; // assume 109 updates per second, as per the paper.
|
||||
@@ -208,7 +208,7 @@ bool
|
||||
SimpleAngularOrientation2InitialQuaterniond()
|
||||
{
|
||||
const auto initialFrame = geom::DoubleQuaternionFromEuler({0, 0, 0});
|
||||
filter::Madgwickd mflt(initialFrame);
|
||||
estimation::Madgwickd mflt(initialFrame);
|
||||
const geom::Vector3D gyro{0.174533, 0.0, 0.0}; // 10° X rotation.
|
||||
const geom::Quaterniond frame20Deg{0.984808, 0.173648, 0, 0}; // 20° final Orientation.
|
||||
const double delta = 0.00917; // assume 109 updates per second, as per the paper.
|
||||
@@ -236,8 +236,8 @@ main(int argc, char **argv)
|
||||
{
|
||||
auto quiet = false;
|
||||
auto noReport = false;
|
||||
auto flags = new scsl::Flags("test_madgwick",
|
||||
"This test validates the Madgwick filter code");
|
||||
auto *flags = new scsl::Flags("test_madgwick",
|
||||
"This test validates the Madgwick estimation code");
|
||||
flags->Register("-n", false, "don't print the report");
|
||||
flags->Register("-q", false, "suppress test output");
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ UnitConversions_RadiansToDegreesD()
|
||||
bool
|
||||
Orientation2f_Heading()
|
||||
{
|
||||
geom::Vector2F a{2.0, 2.0};
|
||||
geom::Vector2F const a{2.0, 2.0};
|
||||
|
||||
SCTEST_CHECK_FEQ(geom::Heading2F(a), scmp::DegreesToRadiansF(45));
|
||||
|
||||
@@ -56,9 +56,9 @@ Orientation2f_Heading()
|
||||
bool
|
||||
Orientation3f_Heading()
|
||||
{
|
||||
geom::Vector3F a{2.0, 2.0, 2.0};
|
||||
geom::Vector3F const a{2.0, 2.0, 2.0};
|
||||
|
||||
SCTEST_CHECK_FEQ(geom::Heading3f(a), scmp::DegreesToRadiansF(45));
|
||||
SCTEST_CHECK_FEQ(geom::Heading3F(a), scmp::DegreesToRadiansF(45));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -67,18 +67,18 @@ Orientation3f_Heading()
|
||||
bool
|
||||
Orientation2d_Heading()
|
||||
{
|
||||
geom::Vector2D a{2.0, 2.0};
|
||||
geom::Vector2D const a{2.0, 2.0};
|
||||
|
||||
return scmp::WithinTolerance(geom::Heading2d(a), scmp::DegreesToRadiansD(45), 0.000001);
|
||||
return scmp::WithinTolerance(geom::Heading2D(a), scmp::DegreesToRadiansD(45), 0.000001) != 0.0;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Orientation3d_Heading()
|
||||
{
|
||||
geom::Vector3D a{2.0, 2.0, 2.0};
|
||||
geom::Vector3D const a{2.0, 2.0, 2.0};
|
||||
|
||||
return scmp::WithinTolerance(geom::Heading3d(a), scmp::DegreesToRadiansD(45), 0.000001);
|
||||
return scmp::WithinTolerance(geom::Heading3D(a), scmp::DegreesToRadiansD(45), 0.000001) != 0.0;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ main(int argc, char *argv[])
|
||||
{
|
||||
auto noReport = false;
|
||||
auto quiet = false;
|
||||
auto flags = new scsl::Flags("test_orientation",
|
||||
auto *flags = new scsl::Flags("test_orientation",
|
||||
"This test validates various orientation-related components in scmp.");
|
||||
flags->Register("-n", false, "don't print the report");
|
||||
flags->Register("-q", false, "suppress test output");
|
||||
|
||||
@@ -42,30 +42,30 @@ TestTrimming(std::string line, std::string lExpected, std::string rExpected, std
|
||||
std::string result;
|
||||
std::string message;
|
||||
|
||||
result = U::S::TrimLeadingWhitespaceDup(line);
|
||||
result = string::TrimLeadingWhitespaceDup(line);
|
||||
message = "TrimLeadingDup(\"" + line + "\"): '" + result + "'";
|
||||
sctest::Assert(result == lExpected, message);
|
||||
|
||||
result = U::S::TrimTrailingWhitespaceDup(line);
|
||||
result = string::TrimTrailingWhitespaceDup(line);
|
||||
message = "TrimTrailingDup(\"" + line + "\"): '" + result + "'";
|
||||
sctest::Assert(result == rExpected, message);
|
||||
|
||||
result = U::S::TrimWhitespaceDup(line);
|
||||
result = string::TrimWhitespaceDup(line);
|
||||
message = "TrimDup(\"" + line + "\"): '" + result + "'";
|
||||
sctest::Assert(result == expected, message);
|
||||
|
||||
result = line;
|
||||
U::S::TrimLeadingWhitespace(result);
|
||||
string::TrimLeadingWhitespace(result);
|
||||
message = "TrimLeadingDup(\"" + line + "\"): '" + result + "'";
|
||||
sctest::Assert(result == lExpected, message);
|
||||
|
||||
result = line;
|
||||
U::S::TrimTrailingWhitespace(result);
|
||||
string::TrimTrailingWhitespace(result);
|
||||
message = "TrimTrailingDup(\"" + line + "\"): '" + result + "'";
|
||||
sctest::Assert(result == rExpected, message);
|
||||
|
||||
result = line;
|
||||
U::S::TrimWhitespace(result);
|
||||
string::TrimWhitespace(result);
|
||||
message = "TrimDup(\"" + line + "\"): '" + result + "'";
|
||||
sctest::Assert(result == expected, message);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ std::function<bool()>
|
||||
TestSplit(std::string line, std::string delim, size_t maxCount, std::vector<std::string> expected)
|
||||
{
|
||||
return [line, delim, maxCount, expected]() {
|
||||
return U::S::SplitN(line, delim, maxCount) == expected;
|
||||
return string::SplitN(line, delim, maxCount) == expected;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -86,7 +86,7 @@ TestSplitChar()
|
||||
{
|
||||
auto expected = std::vector<std::string>{"hello", "world"};
|
||||
const auto *inputLine = "hello=world\n";
|
||||
auto actual = U::S::SplitKeyValuePair(inputLine, '=');
|
||||
auto actual = string::SplitKeyValuePair(inputLine, '=');
|
||||
|
||||
return actual == expected;
|
||||
}
|
||||
@@ -109,11 +109,11 @@ TestWrapping()
|
||||
"hope so.",
|
||||
};
|
||||
|
||||
auto wrapped = U::S::WrapText(testLine, 16);
|
||||
auto wrapped = string::WrapText(testLine, 16);
|
||||
if (wrapped.size() != expected.size()) {
|
||||
std::cerr << U::S::VectorToString(wrapped)
|
||||
std::cerr << string::VectorToString(wrapped)
|
||||
<< " != "
|
||||
<< U::S::VectorToString(expected)
|
||||
<< string::VectorToString(expected)
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ TestWrapping()
|
||||
return false;
|
||||
}
|
||||
|
||||
// U::S::WriteTabIndented(std::cout, wrapped, 4, true);
|
||||
// string::WriteTabIndented(std::cout, wrapped, 4, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ main(int argc, char *argv[])
|
||||
{
|
||||
auto noReport = false;
|
||||
auto quiet = false;
|
||||
auto flags = new scsl::Flags("test_orientation",
|
||||
auto *flags = new scsl::Flags("test_orientation",
|
||||
"This test validates various orientation-related components in scmp.");
|
||||
flags->Register("-n", false, "don't print the report");
|
||||
flags->Register("-q", false, "suppress test output");
|
||||
|
||||
Reference in New Issue
Block a user