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

Make Choreo use Sleipnir backend's exit conditions #77

Merged
merged 1 commit into from
Jan 8, 2024
Merged
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: 2 additions & 2 deletions cmake/modules/FetchSleipnir.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ macro(fetch_sleipnir)
fetchcontent_declare(
Sleipnir
GIT_REPOSITORY https://github.com/SleipnirGroup/Sleipnir.git
# main on 2024-01-07
GIT_TAG da2bd2bec834ab4154eb5b0010818e7edda37406
# main on 2024-01-08
GIT_TAG 02c5b2446975b45b38f35f4a40e54f988010d486
)

fetchcontent_getproperties(Sleipnir)
Expand Down
5 changes: 3 additions & 2 deletions include/trajopt/TrajectoryGenerationException.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#pragma once

#include <stdexcept>
#include <string>
#include <string_view>

#include "trajopt/SymbolExports.h"

Expand All @@ -22,7 +22,8 @@ class TRAJOPT_DLLEXPORT TrajectoryGenerationException
*
* @param message the string message
*/
explicit TrajectoryGenerationException(const std::string& message);
explicit TrajectoryGenerationException(std::string_view message);

/**
* @brief Construct a new Trajectory Generation Exception object with a string
* message.
Expand Down
7 changes: 3 additions & 4 deletions src/TrajectoryGenerationException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

#include "trajopt/TrajectoryGenerationException.h"

#include <stdexcept>
#include <string>

namespace trajopt {

TrajectoryGenerationException::TrajectoryGenerationException(
const std::string& message)
: logic_error(message) {}
std::string_view message)
: std::logic_error{std::string{message}} {}

TrajectoryGenerationException::TrajectoryGenerationException(
const char* message)
: logic_error(message) {}
: std::logic_error{message} {}
} // namespace trajopt
10 changes: 9 additions & 1 deletion src/optimization/SleipnirOpti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include <memory>
#include <vector>

#include <fmt/format.h>
#include <sleipnir/autodiff/Variable.hpp>
#include <sleipnir/optimization/Constraints.hpp>
#include <sleipnir/optimization/OptimizationProblem.hpp>

#include "DebugOptions.h"
#include "optimization/Cancellation.h"
#include "trajopt/TrajectoryGenerationException.h"

namespace trajopt {

Expand Down Expand Up @@ -107,7 +109,13 @@ void SleipnirOpti::Solve() {
opti.Callback([](const sleipnir::SolverIterationInfo&) -> bool {
return trajopt::GetCancellationFlag();
});
opti.Solve({.diagnostics = true});

auto status = opti.Solve({.diagnostics = true});

if (static_cast<int>(status.exitCondition) < 0) {
throw TrajectoryGenerationException{
sleipnir::ToMessage(status.exitCondition)};
}
}

double SleipnirOpti::SolutionValue(const SleipnirExpr& expression) const {
Expand Down
6 changes: 4 additions & 2 deletions src/optimization/algorithms/SwerveDiscreteOptimal.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <string>
#include <vector>

#include <fmt/format.h>

#include "DebugOptions.h"
#include "optimization/SwerveTrajoptUtil.h"
#include "optimization/TrajoptUtil.h"
Expand All @@ -25,8 +27,8 @@ SwerveSolution SwerveDiscreteOptimal<Expr, Opti>::Generate() {
return ConstructSwerveSolution(opti, x, y, theta, vx, vy, omega, ax, ay,
alpha, Fx, Fy, dt, N);
} catch (const std::exception& e) {
throw TrajectoryGenerationException("Error optimizing trajectory: " +
std::string(e.what()));
throw TrajectoryGenerationException{
fmt::format("Error optimizing trajectory: {}", e.what())};
}
}

Expand Down
Loading