Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Fix test compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Feb 16, 2024
1 parent 299aea8 commit 2cfcb13
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 85 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
22 changes: 12 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
28 changes: 12 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,16 @@ 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
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
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)
Expand All @@ -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(
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion cmake/modules/TrajoptLibCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
32 changes: 32 additions & 0 deletions examples/.styleguide
Original file line number Diff line number Diff line change
@@ -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/
}
28 changes: 14 additions & 14 deletions examples/Swerve/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
#include <vector>

#include <fmt/core.h>

#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 <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>

int main() {
using namespace trajopt;

SwerveDrivetrain swerveDrivetrain{.mass = 45,
.moi = 6,
.modules = {{+0.6, +0.6, 0.04, 70, 2},
Expand Down
2 changes: 2 additions & 0 deletions include/trajopt/path/SwervePathBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions test/.styleguide
Original file line number Diff line number Diff line change
@@ -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/
}
48 changes: 14 additions & 34 deletions test/src/ObstacleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,26 @@
#include <vector>

#include <gtest/gtest.h>
#include <trajopt/OptimalTrajectoryGenerator.h>
#include <trajopt/path/InitialGuessPoint.h>
#include <trajopt/path/SwervePathBuilder.h>

#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},
Expand Down
5 changes: 2 additions & 3 deletions test/src/SwervePathBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
#include <vector>

#include <gtest/gtest.h>

#include "path/InitialGuessPoint.h"
#include "path/SwervePathBuilder.h"
#include <trajopt/path/InitialGuessPoint.h>
#include <trajopt/path/SwervePathBuilder.h>

TEST(SwervePathBuilderTest, GenerateLinearInitialGuess) {
using namespace trajopt;
Expand Down
Loading

0 comments on commit 2cfcb13

Please sign in to comment.