diff --git a/.github/workflows/build-rust.yml b/.github/workflows/build-rust.yml index ec9044b3..b1b47765 100644 --- a/.github/workflows/build-rust.yml +++ b/.github/workflows/build-rust.yml @@ -21,7 +21,7 @@ jobs: rust-target: x86_64-apple-darwin - artifact-name: Rust Native - macOS arm64 (CasADi) - os: macOS-13 + os: macOS-14 rust-target: aarch64-apple-darwin - artifact-name: Rust Native - Linux x86_64 (CasADi) @@ -47,7 +47,7 @@ jobs: targets: ${{matrix.rust-target}} - name: Set up Clang - if: matrix.os != 'macOS-13' + if: ${{ !startsWith(matrix.os, 'macOS') }} uses: egor-tensin/setup-clang@v1 with: version: latest diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c56f99d4..bb5960e2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,42 +8,40 @@ concurrency: jobs: build-cpp: + timeout-minutes: 30 strategy: fail-fast: false matrix: include: - artifact-name: Native - Windows (CasADi) - cmake-config-env-vars: cmake-flags: "-G \"MinGW Makefiles\" -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++" optimizer: casadi os: windows-2022 - artifact-name: Native - macOS x86_64 (CasADi) - cmake-config-env-vars: CFLAGS="$CFLAGS -arch x86_64" CXXFLAGS="$CXXFLAGS -arch x86_64" cmake-flags: "-DCMAKE_APPLE_SILICON_PROCESSOR=x86_64" optimizer: casadi os: macOS-13 - artifact-name: Native - macOS arm64 (CasADi) - cmake-config-env-vars: CFLAGS="$CFLAGS -arch arm64" CXXFLAGS="$CXXFLAGS -arch arm64" cmake-flags: "-DCMAKE_APPLE_SILICON_PROCESSOR=arm64" optimizer: casadi - os: macOS-13 + os: macOS-14 - artifact-name: Native - Linux (CasADi) - cmake-config-env-vars: cmake-flags: optimizer: casadi os: ubuntu-latest - artifact-name: Native - Windows (Sleipnir) - cmake-config-env-vars: cmake-flags: optimizer: sleipnir os: windows-2022 - - artifact-name: Native - macOS universal (Sleipnir) - cmake-config-env-vars: CFLAGS="$CFLAGS -arch x86_64 -arch arm64" CXXFLAGS="$CXXFLAGS -arch x86_64 -arch arm64" + - artifact-name: Native - macOS x86_64 (Sleipnir) cmake-flags: optimizer: sleipnir os: macOS-13 + - artifact-name: Native - macOS arm64 (Sleipnir) + cmake-flags: + optimizer: sleipnir + os: macOS-14 - artifact-name: Native - Linux (Sleipnir) - cmake-config-env-vars: cmake-flags: optimizer: sleipnir os: ubuntu-latest @@ -62,11 +60,15 @@ jobs: version: 12.2.0 - name: configure - run: ${{ matrix.cmake-config-env-vars }} cmake -B build -S . ${{ matrix.cmake-flags }} -DOPTIMIZER_BACKEND=${{ matrix.optimizer }} -DWITH_JAVA=ON -DJAVA_INSTALL_JAR=OFF + run: cmake -B build -S . ${{ matrix.cmake-flags }} -DOPTIMIZER_BACKEND=${{ matrix.optimizer }} -DWITH_JAVA=ON -DJAVA_INSTALL_JAR=OFF - name: build run: cmake --build build --config RelWithDebInfo --parallel $(nproc) + - name: test + working-directory: build + run: ctest -C RelWithDebInfo --output-on-failure + - name: install run: cmake --install build --config RelWithDebInfo --prefix pkg diff --git a/CMakeLists.txt b/CMakeLists.txt index b4aa56e8..34a40653 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,9 +82,6 @@ target_compile_definitions(TrajoptLib PRIVATE TRAJOPT_EXPORTS) include(FetchContent) # fmt dependency -set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS}) -set(BUILD_SHARED_LIBS OFF) -set(CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS_SAVE}) set(FMT_INSTALL ON) fetchcontent_declare( fmt @@ -92,11 +89,9 @@ fetchcontent_declare( GIT_TAG 10.2.1 ) fetchcontent_makeavailable(fmt) -set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE}) if( ${OPTIMIZER_BACKEND} STREQUAL "casadi" - AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" ) target_compile_definitions(fmt PRIVATE _GLIBCXX_USE_CXX11_ABI=0) @@ -105,8 +100,6 @@ endif() target_link_libraries(TrajoptLib PUBLIC fmt::fmt) # json dependency -set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS}) -set(BUILD_SHARED_LIBS OFF) set(JSON_BuildTests OFF) set(JSON_Install ON) fetchcontent_declare( @@ -115,7 +108,6 @@ fetchcontent_declare( GIT_TAG v3.11.2 ) fetchcontent_makeavailable(nlohmann_json) -set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE}) target_link_libraries(TrajoptLib PUBLIC nlohmann_json::nlohmann_json) @@ -203,11 +195,9 @@ install( DESTINATION lib/cmake/TrajoptLib ) -# GoogleTest dependency (static linkage) -set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS}) -set(BUILD_SHARED_LIBS OFF) +# GoogleTest dependency option(INSTALL_GMOCK "Install GoogleTest's GMock" OFF) -option(INSTALL_GTEST "Install GoogleTest's GTest" OFF) +option(INSTALL_GTEST "Install GoogleTest's GTest" ON) fetchcontent_declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git @@ -217,20 +207,26 @@ fetchcontent_declare( FIND_PACKAGE_ARGS NAMES GTest ) fetchcontent_makeavailable(googletest) -set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE}) include(CMakeDependentOption) cmake_dependent_option( BUILD_TESTING "Enable creation of tests." - OFF + ON "PROJECT_IS_TOP_LEVEL" OFF ) if(BUILD_TESTING) enable_testing() include(GoogleTest) + if( + ${OPTIMIZER_BACKEND} STREQUAL "casadi" + AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" + ) + target_compile_definitions(gtest PUBLIC "_GLIBCXX_USE_CXX11_ABI=0") + target_compile_definitions(gtest_main PUBLIC "_GLIBCXX_USE_CXX11_ABI=0") + endif() endif() # Build TrajoptLib tests @@ -247,7 +243,7 @@ if(BUILD_TESTING) ) target_link_libraries( TrajoptLibTest - PRIVATE TrajoptLib fmt::fmt GTest::gtest GTest::gtest_main + PRIVATE TrajoptLib fmt::fmt GTest::gtest_main ) if(NOT CMAKE_TOOLCHAIN_FILE) gtest_discover_tests(TrajoptLibTest) @@ -289,7 +285,7 @@ foreach(example ${EXAMPLES}) ) target_link_libraries( ${example}Test - PRIVATE TrajoptLib GTest::gtest GTest::gtest_main + PRIVATE TrajoptLib GTest::gtest_main ) if(NOT CMAKE_TOOLCHAIN_FILE) gtest_discover_tests(${example}Test) diff --git a/cmake/modules/TrajoptLibCompilerFlags.cmake b/cmake/modules/TrajoptLibCompilerFlags.cmake index 48e787f9..3e050287 100644 --- a/cmake/modules/TrajoptLibCompilerFlags.cmake +++ b/cmake/modules/TrajoptLibCompilerFlags.cmake @@ -24,7 +24,6 @@ macro(trajoptlib_compiler_flags target) if( ${OPTIMIZER_BACKEND} STREQUAL "casadi" - AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" ) target_compile_definitions( diff --git a/examples/.styleguide b/examples/.styleguide new file mode 100644 index 00000000..0ea80545 --- /dev/null +++ b/examples/.styleguide @@ -0,0 +1,32 @@ +cppHeaderFileInclude { + \.h$ + \.hpp$ + \.inc$ +} + +cppSrcFileInclude { + \.cpp$ +} + +modifiableFileExclude { + jni/jni\.h$ + jni/darwin/jni_md\.h$ + jni/linux/jni_md\.h$ + jni/win32/jni_md\.h$ + \.jar$ +} + +licenseUpdateExclude { + java/src/main/java/org/team2363/util/DependencyExtractor\.java$ + java/src/main/java/org/team2363/util/RuntimeDetector\.java$ + java/src/main/java/org/team2363/util/RuntimeLoader\.java$ +} + +includeOtherLibs { + ^Eigen/ + ^fmt/ + ^casadi/ + ^sleipnir/ + ^trajopt/ + ^gtest/ +} diff --git a/examples/Swerve/src/Main.cpp b/examples/Swerve/src/Main.cpp index 4f197ba9..50326fa1 100644 --- a/examples/Swerve/src/Main.cpp +++ b/examples/Swerve/src/Main.cpp @@ -6,23 +6,23 @@ #include #include - -#include "trajopt/IncompatibleTrajectoryException.h" -#include "trajopt/OptimalTrajectoryGenerator.h" -#include "trajopt/constraint/Constraint.h" -#include "trajopt/constraint/TranslationConstraint.h" -#include "trajopt/constraint/holonomic/HolonomicConstraint.h" -#include "trajopt/drivetrain/SwerveDrivetrain.h" -#include "trajopt/obstacle/Obstacle.h" -#include "trajopt/path/InitialGuessPoint.h" -#include "trajopt/path/Path.h" -#include "trajopt/path/SwervePathBuilder.h" -#include "trajopt/set/ConeSet2d.h" -#include "trajopt/solution/SwerveSolution.h" -#include "trajopt/trajectory/HolonomicTrajectory.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include int main() { using namespace trajopt; + SwerveDrivetrain swerveDrivetrain{.mass = 45, .moi = 6, .modules = {{+0.6, +0.6, 0.04, 70, 2}, diff --git a/include/trajopt/path/SwervePathBuilder.h b/include/trajopt/path/SwervePathBuilder.h index c7488cf9..852f65fc 100644 --- a/include/trajopt/path/SwervePathBuilder.h +++ b/include/trajopt/path/SwervePathBuilder.h @@ -52,6 +52,7 @@ class TRAJOPT_DLLEXPORT SwervePathBuilder { * @param heading the heading */ void PoseWpt(size_t idx, double x, double y, double heading); + /** * Create a translation waypoint constraint on the waypoint at the * provided index, and add an initial guess point with the same translation. @@ -123,6 +124,7 @@ class TRAJOPT_DLLEXPORT SwervePathBuilder { * @param vtheta velocity vector polar angle */ void WptVelocityPolar(size_t idx, double vr, double vtheta); + /** * Specify the required angular velocity of the robot to be zero * at a waypoint diff --git a/rust/build.rs b/rust/build.rs index cf9a02d6..043f507d 100644 --- a/rust/build.rs +++ b/rust/build.rs @@ -5,7 +5,8 @@ fn main() -> miette::Result<()> { cmake_config .profile("RelWithDebInfo") - .define("OPTIMIZER_BACKEND", "casadi"); + .define("OPTIMIZER_BACKEND", "casadi") + .define("BUILD_TESTING", "OFF"); if cfg!(target_os = "windows") { cmake_config diff --git a/test/.styleguide b/test/.styleguide new file mode 100644 index 00000000..0ea80545 --- /dev/null +++ b/test/.styleguide @@ -0,0 +1,32 @@ +cppHeaderFileInclude { + \.h$ + \.hpp$ + \.inc$ +} + +cppSrcFileInclude { + \.cpp$ +} + +modifiableFileExclude { + jni/jni\.h$ + jni/darwin/jni_md\.h$ + jni/linux/jni_md\.h$ + jni/win32/jni_md\.h$ + \.jar$ +} + +licenseUpdateExclude { + java/src/main/java/org/team2363/util/DependencyExtractor\.java$ + java/src/main/java/org/team2363/util/RuntimeDetector\.java$ + java/src/main/java/org/team2363/util/RuntimeLoader\.java$ +} + +includeOtherLibs { + ^Eigen/ + ^fmt/ + ^casadi/ + ^sleipnir/ + ^trajopt/ + ^gtest/ +} diff --git a/test/src/ObstacleTest.cpp b/test/src/ObstacleTest.cpp index 4223e952..80fa98f2 100644 --- a/test/src/ObstacleTest.cpp +++ b/test/src/ObstacleTest.cpp @@ -3,46 +3,26 @@ #include #include +#include +#include +#include -#include "path/InitialGuessPoint.h" -#include "path/SwervePathBuilder.h" - -TEST(ObstacleTest, GenerateLinearInitialGuess) { +TEST(ObstacleTest, DISABLED_GenerateLinearInitialGuess) { using namespace trajopt; + + SwerveDrivetrain swerveDrivetrain{.mass = 45, + .moi = 6, + .modules = {{+0.6, +0.6, 0.04, 70, 2}, + {+0.6, -0.6, 0.04, 70, 2}, + {-0.6, +0.6, 0.04, 70, 2}, + {-0.6, -0.6, 0.04, 70, 2}}}; + trajopt::SwervePathBuilder path; - path.SetDrivetrain({45, 6, - [{ - x : 0.6, - y : 0.6, - wheel_radius : 0.04, - wheel_max_angular_velocity : 70.0, - wheel_max_torque : 2.0, - }, - { - x : 0.6, - y : -0.6, - wheel_radius : 0.04, - wheel_max_angular_velocity : 70.0, - wheel_max_torque : 2.0, - }, - { - x : -0.6, - y : 0.6, - wheel_radius : 0.04, - wheel_max_angular_velocity : 70.0, - wheel_max_torque : 2.0, - }, - { - x : -0.6, - y : -0.6, - wheel_radius : 0.04, - wheel_max_angular_velocity : 70.0, - wheel_max_torque : 2.0, - }]}); path.PoseWpt(0, 0.0, 0.0, 0.0); path.PoseWpt(1, 2.0, 2.0, 0.0); - const length = 0.7; + constexpr double length = 0.7; + constexpr double width = 0.7; path.AddBumpers(trajopt::Bumpers{.safetyDistance = 0.1, .points = {{+length / 2, +width / 2}, {-length / 2, +width / 2}, diff --git a/test/src/SwervePathBuilderTest.cpp b/test/src/SwervePathBuilderTest.cpp index 19840474..43e2ca4c 100644 --- a/test/src/SwervePathBuilderTest.cpp +++ b/test/src/SwervePathBuilderTest.cpp @@ -3,9 +3,8 @@ #include #include - -#include "path/InitialGuessPoint.h" -#include "path/SwervePathBuilder.h" +#include +#include TEST(SwervePathBuilderTest, GenerateLinearInitialGuess) { using namespace trajopt; diff --git a/test/src/SwerveTrajoptProblemTest.cpp b/test/src/SwerveTrajoptProblemTest.cpp index 30cf55bf..f75ec159 100644 --- a/test/src/SwerveTrajoptProblemTest.cpp +++ b/test/src/SwerveTrajoptProblemTest.cpp @@ -3,12 +3,12 @@ #include #include +#include +#include #include "TestOpti.h" #include "optimization/SwerveTrajoptUtil.h" #include "optimization/TrajoptUtil.h" -#include "path/InitialGuessPoint.h" -#include "set/IntervalSet1d.h" TEST(TrajoptUtilTest, ApplyKinematicsConstraints) { TestOpti opti; diff --git a/test/src/TrajoptUtilTest.cpp b/test/src/TrajoptUtilTest.cpp index 19a7acfd..9072ac43 100644 --- a/test/src/TrajoptUtilTest.cpp +++ b/test/src/TrajoptUtilTest.cpp @@ -3,11 +3,11 @@ #include #include +#include +#include #include "TestOpti.h" #include "optimization/TrajoptUtil.h" -#include "path/InitialGuessPoint.h" -#include "set/IntervalSet1d.h" TEST(TrajoptUtilTest, GetIdx) { auto result0 = trajopt::GetIdx({2, 3}, 0, 0);