This repository has been archived by the owner on Jul 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite trajectory generator and constraint handling
OptimalTrajectoryGenerator and SwerveDiscreteOptimal were merged into a new class SwerveTrajectoryGenerator. The constraints were rewritten based on the SwervePathBuilder interface. The geometry classes now overload operator== to produce equality constraints.
- Loading branch information
Showing
62 changed files
with
1,642 additions
and
2,521 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) TrajoptLib contributors | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
#include <functional> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <sleipnir/optimization/OptimizationProblem.hpp> | ||
|
||
#include "trajopt/path/SwervePathBuilder.hpp" | ||
#include "trajopt/solution/SwerveSolution.hpp" | ||
#include "trajopt/util/SymbolExports.hpp" | ||
#include "trajopt/util/expected" | ||
|
||
namespace trajopt { | ||
|
||
/** | ||
* This trajectory generator class contains functions to generate | ||
* time-optimal trajectories for several drivetrain types. | ||
*/ | ||
class TRAJOPT_DLLEXPORT SwerveTrajectoryGenerator { | ||
public: | ||
/** | ||
* Construct a new swerve trajectory optimization problem. | ||
* | ||
* @param pathBuilder The path builder. | ||
* @param handle An identifier for state callbacks. | ||
*/ | ||
explicit SwerveTrajectoryGenerator(SwervePathBuilder pathBuilder, | ||
int64_t handle = 0); | ||
|
||
/** | ||
* Generates an optimal trajectory. | ||
* | ||
* This function may take a long time to complete. | ||
* | ||
* @param diagnostics Enables diagnostic prints. | ||
* @return Returns a holonomic trajectory on success, or a string containing a | ||
* failure reason. | ||
*/ | ||
expected<SwerveSolution, std::string> Generate(bool diagnostics = false); | ||
|
||
private: | ||
/// Swerve path | ||
SwervePath path; | ||
|
||
/// State Variables | ||
std::vector<sleipnir::Variable> x; | ||
std::vector<sleipnir::Variable> y; | ||
std::vector<sleipnir::Variable> thetacos; | ||
std::vector<sleipnir::Variable> thetasin; | ||
std::vector<sleipnir::Variable> vx; | ||
std::vector<sleipnir::Variable> vy; | ||
std::vector<sleipnir::Variable> omega; | ||
std::vector<sleipnir::Variable> ax; | ||
std::vector<sleipnir::Variable> ay; | ||
std::vector<sleipnir::Variable> alpha; | ||
|
||
/// Input Variables | ||
std::vector<std::vector<sleipnir::Variable>> Fx; | ||
std::vector<std::vector<sleipnir::Variable>> Fy; | ||
|
||
/// Time Variables | ||
std::vector<sleipnir::Variable> dt; | ||
|
||
/// Discretization Constants | ||
std::vector<size_t> N; | ||
|
||
sleipnir::OptimizationProblem problem; | ||
std::vector<std::function<void()>> callbacks; | ||
|
||
void ApplyInitialGuess(const SwerveSolution& solution); | ||
|
||
SwerveSolution ConstructSwerveSolution(); | ||
}; | ||
|
||
} // namespace trajopt |
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
include/trajopt/constraint/AngularVelocityEqualityConstraint.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) TrajoptLib contributors | ||
|
||
#pragma once | ||
|
||
#include <sleipnir/optimization/OptimizationProblem.hpp> | ||
|
||
#include "trajopt/geometry/Pose2.hpp" | ||
#include "trajopt/geometry/Translation2.hpp" | ||
#include "trajopt/util/SymbolExports.hpp" | ||
|
||
namespace trajopt { | ||
|
||
/** | ||
* Angular velocity equality constraint. | ||
*/ | ||
class TRAJOPT_DLLEXPORT AngularVelocityEqualityConstraint { | ||
public: | ||
/** | ||
* Constructs an AngularVelocityEqualityConstraint. | ||
* | ||
* @param angularVelocity The angular velocity. | ||
*/ | ||
explicit AngularVelocityEqualityConstraint(double angularVelocity) | ||
: m_angularVelocity{angularVelocity} {} | ||
|
||
/** | ||
* Applies this constraint to the given problem. | ||
* | ||
* @param problem The optimization problem. | ||
* @param pose The robot's pose. | ||
* @param linearVelocity The robot's linear velocity. | ||
* @param angularVelocity The robot's angular velocity. | ||
*/ | ||
void Apply(sleipnir::OptimizationProblem& problem, | ||
[[maybe_unused]] const Pose2v& pose, | ||
[[maybe_unused]] const Translation2v& linearVelocity, | ||
const sleipnir::Variable& angularVelocity) { | ||
problem.SubjectTo(angularVelocity == m_angularVelocity); | ||
} | ||
|
||
private: | ||
double m_angularVelocity; | ||
}; | ||
|
||
} // namespace trajopt |
55 changes: 55 additions & 0 deletions
55
include/trajopt/constraint/AngularVelocityMaxMagnitudeConstraint.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) TrajoptLib contributors | ||
|
||
#pragma once | ||
|
||
#include <cassert> | ||
|
||
#include <sleipnir/optimization/OptimizationProblem.hpp> | ||
|
||
#include "trajopt/geometry/Pose2.hpp" | ||
#include "trajopt/geometry/Translation2.hpp" | ||
#include "trajopt/util/SymbolExports.hpp" | ||
|
||
namespace trajopt { | ||
|
||
/** | ||
* Angular velocity max magnitude inequality constraint. | ||
*/ | ||
class TRAJOPT_DLLEXPORT AngularVelocityMaxMagnitudeConstraint { | ||
public: | ||
/** | ||
* Constructs an AngularVelocityMaxMagnitudeConstraint. | ||
* | ||
* @param maxMagnitude The maximum angular velocity magnitude. Must be | ||
* nonnegative. | ||
*/ | ||
explicit AngularVelocityMaxMagnitudeConstraint(double maxMagnitude) | ||
: m_maxMagnitude{maxMagnitude} { | ||
assert(maxMagnitude >= 0.0); | ||
} | ||
|
||
/** | ||
* Applies this constraint to the given problem. | ||
* | ||
* @param problem The optimization problem. | ||
* @param pose The robot's pose. | ||
* @param linearVelocity The robot's linear velocity. | ||
* @param angularVelocity The robot's angular velocity. | ||
*/ | ||
void Apply(sleipnir::OptimizationProblem& problem, | ||
[[maybe_unused]] const Pose2v& pose, | ||
[[maybe_unused]] const Translation2v& linearVelocity, | ||
const sleipnir::Variable& angularVelocity) { | ||
if (m_maxMagnitude == 0.0) { | ||
problem.SubjectTo(angularVelocity == 0.0); | ||
} else { | ||
problem.SubjectTo(angularVelocity >= -m_maxMagnitude); | ||
problem.SubjectTo(angularVelocity <= m_maxMagnitude); | ||
} | ||
} | ||
|
||
private: | ||
double m_maxMagnitude; | ||
}; | ||
|
||
} // namespace trajopt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.