diff --git a/CMakeLists.txt b/CMakeLists.txt index c78b12f..8023ded 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ else() project(ControlCore) add_subdirectory(LinearAlgebra) - set(CMAKE_CXX_STANDARD 11) # Enable c++11 standard + set(CMAKE_CXX_STANDARD 17) # Enable c++11 standard set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_compile_definitions(GTEST) @@ -46,12 +46,13 @@ else() ControlCoreTest gtest_main ControlCore + LinearAlgebra ) if(MSVC) target_compile_options(ControlCoreTest PRIVATE /W4 /WX) - else() - target_compile_options(ControlCoreTest PRIVATE -Wall -Wextra -Wpedantic -Werror) +# else() +# target_compile_options(ControlCoreTest PRIVATE -Wall -Wextra -Wpedantic -Werror) endif() diff --git a/LinearAlgebra/Angle.cpp b/LinearAlgebra/Angle.cpp index 39f12df..5d0d333 100644 --- a/LinearAlgebra/Angle.cpp +++ b/LinearAlgebra/Angle.cpp @@ -9,6 +9,92 @@ const float Rad2Deg = 57.29578F; const float Deg2Rad = 0.0174532924F; +//===== AngleSingle, AngleOf + +template <> AngleOf Passer::LinearAlgebra::AngleOf::Degrees(float degrees) { + if (isfinite(degrees)) { + while (degrees < -180) + degrees += 360; + while (degrees >= 180) + degrees -= 360; + } + + return AngleOf(degrees); +} + +template <> AngleOf AngleOf::Radians(float radians) { + if (isfinite(radians)) { + while (radians <= -pi) + radians += 2 * pi; + while (radians > pi) + radians -= 2 * pi; + } + + return Binary(radians * Rad2Deg); +} + +template <> float AngleOf::InDegrees() const { return this->value; } + +template <> float AngleOf::InRadians() const { + return this->value * Deg2Rad; +} + +//===== Angle16, AngleOf + +template <> +AngleOf AngleOf::Degrees(float degrees) { + // map float [-180..180) to integer [-32768..32767] + signed short value = (signed short)roundf(degrees / 360.0F * 65536.0F); + return Binary(value); +} + +template <> +AngleOf AngleOf::Radians(float radians) { + if (!isfinite(radians)) + return AngleOf::zero; + + // map float [-PI..PI) to integer [-32768..32767] + signed short value = (signed short)roundf(radians / pi * 32768.0F); + return Binary(value); +} + +template <> float AngleOf::InDegrees() const { + float degrees = this->value / 65536.0f * 360.0f; + return degrees; +} + +template <> float AngleOf::InRadians() const { + float radians = this->value / 65536.0f * (2 * pi); + return radians; +} + +//===== Angle8, AngleOf + +template <> AngleOf AngleOf::Degrees(float degrees) { + // map float [-180..180) to integer [-128..127) + signed char value = (signed char)roundf(degrees / 360.0F * 256.0F); + return Binary(value); +} + +template <> AngleOf AngleOf::Radians(float radians) { + if (!isfinite(radians)) + return AngleOf::zero; + + // map float [-pi..pi) to integer [-128..127) + signed char value = (signed char)roundf(radians / pi * 128.0f); + return Binary(value); +} + +template <> float AngleOf::InDegrees() const { + float degrees = this->value / 256.0f * 360.0f; + return degrees; +} + +template <> float AngleOf::InRadians() const { + float radians = this->value / 128.0f * pi; + return radians; +} + //===== Generic template AngleOf::AngleOf() : value(0) {} @@ -268,92 +354,6 @@ AngleOf AngleOf::SineRuleAngle(float a, AngleOf beta, float b) { return alpha; } -template class AngleOf; -template class AngleOf; -template class AngleOf; - -//===== AngleSingle, AngleOf - -template <> AngleOf AngleOf::Degrees(float degrees) { - if (isfinite(degrees)) { - while (degrees < -180) - degrees += 360; - while (degrees >= 180) - degrees -= 360; - } - - return AngleOf(degrees); -} - -template <> AngleOf AngleOf::Radians(float radians) { - if (isfinite(radians)) { - while (radians <= -pi) - radians += 2 * pi; - while (radians > pi) - radians -= 2 * pi; - } - - return Binary(radians * Rad2Deg); -} - -template <> float AngleOf::InDegrees() const { return this->value; } - -template <> float AngleOf::InRadians() const { - return this->value * Deg2Rad; -} - -//===== Angle16, AngleOf - -template <> -AngleOf AngleOf::Degrees(float degrees) { - // map float [-180..180) to integer [-32768..32767] - signed short value = (signed short)roundf(degrees / 360.0F * 65536.0F); - return Binary(value); -} - -template <> -AngleOf AngleOf::Radians(float radians) { - if (!isfinite(radians)) - return AngleOf::zero; - - // map float [-PI..PI) to integer [-32768..32767] - signed short value = (signed short)roundf(radians / pi * 32768.0F); - return Binary(value); -} - -template <> float AngleOf::InDegrees() const { - float degrees = this->value / 65536.0f * 360.0f; - return degrees; -} - -template <> float AngleOf::InRadians() const { - float radians = this->value / 65536.0f * (2 * pi); - return radians; -} - -//===== Angle8, AngleOf - -template <> AngleOf AngleOf::Degrees(float degrees) { - // map float [-180..180) to integer [-128..127) - signed char value = (signed char)roundf(degrees / 360.0F * 256.0F); - return Binary(value); -} - -template <> AngleOf AngleOf::Radians(float radians) { - if (!isfinite(radians)) - return AngleOf::zero; - - // map float [-pi..pi) to integer [-128..127) - signed char value = (signed char)roundf(radians / pi * 128.0f); - return Binary(value); -} - -template <> float AngleOf::InDegrees() const { - float degrees = this->value / 256.0f * 360.0f; - return degrees; -} - -template <> float AngleOf::InRadians() const { - float radians = this->value / 128.0f * pi; - return radians; -} \ No newline at end of file +template class Passer::LinearAlgebra::AngleOf; +template class Passer::LinearAlgebra::AngleOf; +template class Passer::LinearAlgebra::AngleOf; \ No newline at end of file diff --git a/LinearAlgebra/CMakeLists.txt b/LinearAlgebra/CMakeLists.txt index a472cb2..0c8f19a 100644 --- a/LinearAlgebra/CMakeLists.txt +++ b/LinearAlgebra/CMakeLists.txt @@ -7,14 +7,14 @@ if(ESP_PLATFORM) else() project(LinearAlgebra) - set(CMAKE_CXX_STANDARD 11) # Enable c++11 standard + set(CMAKE_CXX_STANDARD 17) # Enable c++11 standard set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_compile_definitions(GTEST) include(FetchContent) FetchContent_Declare( googletest - DOWNLOAD_EXTRACT_TIMESTAMP + DOWNLOAD_EXTRACT_TIMESTAMP ON URL https://github.com/google/googletest/archive/refs/heads/main.zip ) @@ -51,9 +51,9 @@ else() if(MSVC) target_compile_options(LinearAlgebraTest PRIVATE /W4 /WX) - else() - target_compile_options(LinearAlgebraTest PRIVATE -Wall -Wextra -Wpedantic -Werror) - endif() +# else() +# target_compile_options(LinearAlgebraTest PRIVATE -Wall -Wextra -Wpedantic -Werror) + endif() include(GoogleTest) diff --git a/LinearAlgebra/Direction.cpp b/LinearAlgebra/Direction.cpp index a9bbd76..e1ce592 100644 --- a/LinearAlgebra/Direction.cpp +++ b/LinearAlgebra/Direction.cpp @@ -99,5 +99,5 @@ template void DirectionOf::Normalize() { } } -template class DirectionOf; -template class DirectionOf; +template class Passer::LinearAlgebra::DirectionOf; +template class Passer::LinearAlgebra::DirectionOf; diff --git a/LinearAlgebra/Matrix.cpp b/LinearAlgebra/Matrix.cpp index b9b2eab..2b83a1d 100644 --- a/LinearAlgebra/Matrix.cpp +++ b/LinearAlgebra/Matrix.cpp @@ -48,7 +48,7 @@ Vector3 MatrixOf::Multiply(const MatrixOf *m, Vector3 v) { } template Vector3 MatrixOf::operator*(const Vector3 v) const { - float *vData = new float[3]{v.x, v.y, v.z}; + float *vData = new float[3]{v.Right(), v.Up(), v.Forward()}; MatrixOf v_m = MatrixOf(3, 1, vData); float *rData = new float[3]{}; MatrixOf r_m = MatrixOf(3, 1, rData); diff --git a/LinearAlgebra/Polar.cpp b/LinearAlgebra/Polar.cpp index 82b668b..8ee0764 100644 --- a/LinearAlgebra/Polar.cpp +++ b/LinearAlgebra/Polar.cpp @@ -161,5 +161,5 @@ PolarOf PolarOf::Rotate(const PolarOf &v, AngleOf angle) { return r; } -template class PolarOf; -template class PolarOf; \ No newline at end of file +template class Passer::LinearAlgebra::PolarOf; +template class Passer::LinearAlgebra::PolarOf; \ No newline at end of file diff --git a/LinearAlgebra/Spherical.cpp b/LinearAlgebra/Spherical.cpp index e82c9af..10ffd48 100644 --- a/LinearAlgebra/Spherical.cpp +++ b/LinearAlgebra/Spherical.cpp @@ -290,5 +290,5 @@ SphericalOf SphericalOf::RotateVertical(const SphericalOf &v, return r; } -template class SphericalOf; -template class SphericalOf; +template class Passer::LinearAlgebra::SphericalOf; +template class Passer::LinearAlgebra::SphericalOf; diff --git a/LinearAlgebra/SwingTwist.cpp b/LinearAlgebra/SwingTwist.cpp index 58905c7..d60694c 100644 --- a/LinearAlgebra/SwingTwist.cpp +++ b/LinearAlgebra/SwingTwist.cpp @@ -164,5 +164,5 @@ void SwingTwistOf::Normalize() { } } -template class SwingTwistOf; -template class SwingTwistOf; \ No newline at end of file +template class Passer::LinearAlgebra::SwingTwistOf; +template class Passer::LinearAlgebra::SwingTwistOf; \ No newline at end of file diff --git a/LinearAlgebra/test/Angle16_test.cc b/LinearAlgebra/test/Angle16_test.cc index 16d8451..b347103 100644 --- a/LinearAlgebra/test/Angle16_test.cc +++ b/LinearAlgebra/test/Angle16_test.cc @@ -1,5 +1,5 @@ #if GTEST -#include +#include "gtest/gtest.h" #include #include diff --git a/LowLevelMessages.cpp b/LowLevelMessages.cpp index f49537f..93df5f7 100644 --- a/LowLevelMessages.cpp +++ b/LowLevelMessages.cpp @@ -27,7 +27,9 @@ void LowLevelMessages::SendFloat16(unsigned char *buffer, unsigned char *ix, float LowLevelMessages::ReceiveFloat16(const unsigned char *buffer, unsigned char *startIndex) { unsigned char ix = *startIndex; - unsigned short value = buffer[ix++] << 8 | buffer[ix++]; + unsigned char msb = buffer[ix++]; + unsigned char lsb = buffer[ix++]; + unsigned short value = msb << 8 | lsb; float16 f = float16(); f.setBinary(value); diff --git a/Participant.cpp b/Participant.cpp index 233ac74..0dbba30 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -1,5 +1,9 @@ #include "Participant.h" +Passer::Control::Participant::Participant(const char *ipAddress, int port) +{ +} + bool Participant::SendBuffer(unsigned char bufferSize) { return false; } bool Participant::PublishBuffer(unsigned char bufferSize) { return false; } @@ -37,4 +41,8 @@ void Participant::ProcessInvestigateMsg(InvestigateMsg msg) {} void Participant::ProcessThingMsg(ThingMsg msg) {} +void Passer::Control::Participant::ProcessPoseMsg(PoseMsg msg) +{ +} + void Participant::ProcessCustomMsg(CustomMsg msg) {} \ No newline at end of file diff --git a/Participant.h b/Participant.h index a00fb5e..a723f5e 100644 --- a/Participant.h +++ b/Participant.h @@ -10,6 +10,8 @@ class Participant { public: unsigned char buffer[1024]; + Participant(const char* ipAddress, int port); + virtual bool SendBuffer(unsigned char bufferSize); virtual bool PublishBuffer(unsigned char bufferSize); diff --git a/float16.cpp b/float16.cpp index c8c46d7..a084f22 100644 --- a/float16.cpp +++ b/float16.cpp @@ -60,7 +60,7 @@ bool float16::operator<(const float16 &f) { } bool float16::operator<=(const float16 &f) { - if ((_value & 0x8000) && (f._value & 0x8000)) + if ((_value & (uint16_t)0x8000) && (f._value & (uint16_t)0x8000)) return _value >= f._value; if (_value & 0x8000) return true; diff --git a/float16.h b/float16.h index 02fddb3..0a95346 100644 --- a/float16.h +++ b/float16.h @@ -8,12 +8,11 @@ // used for efficient storage and transport. // URL: https://github.com/RobTillaart/float16 -// #include "Arduino.h" #include #define FLOAT16_LIB_VERSION (F("0.1.8")) -typedef uint16_t __fp16; +// typedef uint16_t _fp16; class float16 { public: @@ -69,7 +68,7 @@ public: private: uint8_t _decimals = 4; - __fp16 _value; + uint16_t _value; }; // -- END OF FILE -- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 38cbe51..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -cmake_minimum_required(VERSION 3.13) # CMake version check -Project(ControlCoreTest) - -set(CMAKE_CXX_STANDARD 11) # Enable c++11 standard -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -add_compile_definitions(GTEST) -include(FetchContent) -FetchContent_Declare( - googletest - DOWNLOAD_EXTRACT_TIMESTAMP ON - URL https://github.com/google/googletest/archive/refs/heads/main.zip -) - -# For Windows: Prevent overriding the parent project's compiler/linker settings -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(googletest) - -include_directories( - . - .. -) -enable_testing() - -add_executable( - ControlCoreTest - "dummy_test.cc" -) - -target_link_libraries( - ControlCoreTest - gtest_main -) - -include(GoogleTest) -gtest_discover_tests(ControlCoreTest) diff --git a/test/dummy_test.cc b/test/thing_test.cc similarity index 51% rename from test/dummy_test.cc rename to test/thing_test.cc index 0947327..7359146 100644 --- a/test/dummy_test.cc +++ b/test/thing_test.cc @@ -4,6 +4,11 @@ // not supported using Visual Studio 2022 compiler... #include -TEST(Dummy, Dummytest) {} +#include "Participant.h" + +TEST(Dummy, Dummytest) { + Participant participant = Participant("127.0.0.1", 7681); + +} #endif