Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trajoptlib] Run C++ examples in CI #629

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/trajoptlib-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ jobs:
working-directory: trajoptlib
- run: cmake --install build --config RelWithDebInfo --prefix pkg
working-directory: trajoptlib
- run: ./build/Swerve
working-directory: trajoptlib
- run: ./build/Differential
working-directory: trajoptlib

- uses: actions/upload-artifact@v4
with:
Expand Down
59 changes: 52 additions & 7 deletions trajoptlib/examples/Differential/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

#include <numbers>

#include <sleipnir/optimization/SolverExitCondition.hpp>
#include <trajopt/DifferentialTrajectoryGenerator.hpp>

#include "fmt/base.h"

// DifferentialPathBuilder is used to build paths that are optimized into full
// trajectories.
//
Expand Down Expand Up @@ -36,8 +39,14 @@ int main() {
path.ControlIntervalCounts({40});

trajopt::DifferentialTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 1: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 2: Differential, basic curve
Expand All @@ -51,8 +60,14 @@ int main() {
path.ControlIntervalCounts({40});

trajopt::DifferentialTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 2: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 3: Differential, three waypoints
Expand All @@ -67,8 +82,14 @@ int main() {
path.ControlIntervalCounts({50, 50});

trajopt::DifferentialTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 3: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 4: Differential, ending velocity
Expand All @@ -81,8 +102,14 @@ int main() {
path.ControlIntervalCounts({40});

trajopt::DifferentialTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 4: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 5: Differential, circle obstacle
Expand Down Expand Up @@ -112,8 +139,14 @@ int main() {
path.ControlIntervalCounts({40});

trajopt::DifferentialTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 5: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 6: Approach a pick up station at a certain direction
Expand Down Expand Up @@ -148,8 +181,14 @@ int main() {
path.ControlIntervalCounts({40, 30, 30, 40});

trajopt::DifferentialTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 6: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 7: Circular path with a point-point constraint
Expand Down Expand Up @@ -179,7 +218,13 @@ int main() {
path.ControlIntervalCounts({50});

trajopt::DifferentialTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 7: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}
}
56 changes: 49 additions & 7 deletions trajoptlib/examples/Swerve/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ int main() {
path.ControlIntervalCounts({40});

trajopt::SwerveTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 1: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 2: Swerve, basic curve
Expand All @@ -51,8 +57,14 @@ int main() {
path.ControlIntervalCounts({40});

trajopt::SwerveTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 2 {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 3: Swerve, three waypoints
Expand All @@ -67,8 +79,14 @@ int main() {
path.ControlIntervalCounts({40, 40});

trajopt::SwerveTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 3 {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 4: Swerve, ending velocity
Expand All @@ -81,8 +99,14 @@ int main() {
path.ControlIntervalCounts({40});

trajopt::SwerveTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 4: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 5: Swerve, circle obstacle
Expand Down Expand Up @@ -113,8 +137,14 @@ int main() {
path.ControlIntervalCounts({40});

trajopt::SwerveTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 5: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 6: Approach a pick up station at a certain direction
Expand Down Expand Up @@ -149,8 +179,14 @@ int main() {
path.ControlIntervalCounts({40, 30, 30, 40});

trajopt::SwerveTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 6: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}

// Example 7: Circular path with a point-point constraint
Expand Down Expand Up @@ -180,7 +216,13 @@ int main() {
path.ControlIntervalCounts({30});

trajopt::SwerveTrajectoryGenerator generator{path};
[[maybe_unused]]
auto solution = generator.Generate(true);
if (!(solution.error() == sleipnir::SolverExitCondition::kSuccess ||
solution.error() ==
sleipnir::SolverExitCondition::kSolvedToAcceptableTolerance)) {
fmt::println("Error in example 7: {}",
sleipnir::ToMessage(solution.error()));
return static_cast<int>(solution.error());
}
}
}
Loading