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.
Add linear acceleration max magnitude constraint
- Loading branch information
Showing
5 changed files
with
115 additions
and
0 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
61 changes: 61 additions & 0 deletions
61
include/trajopt/constraint/LinearAccelerationMaxMagnitudeConstraint.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,61 @@ | ||
// Copyright (c) TrajoptLib contributors | ||
|
||
#pragma once | ||
|
||
#include <cassert> | ||
|
||
#include <sleipnir/autodiff/Variable.hpp> | ||
#include <sleipnir/optimization/OptimizationProblem.hpp> | ||
|
||
#include "trajopt/geometry/Pose2.hpp" | ||
#include "trajopt/geometry/Translation2.hpp" | ||
#include "trajopt/util/SymbolExports.hpp" | ||
|
||
namespace trajopt { | ||
|
||
/** | ||
* Linear acceleration max magnitude inequality constraint. | ||
*/ | ||
class TRAJOPT_DLLEXPORT LinearAccelerationMaxMagnitudeConstraint { | ||
public: | ||
/** | ||
* Constructs a LinearAccelerationMaxMagnitudeConstraint. | ||
* | ||
* @param maxMagnitude The maximum linear acceleration magnitude. Must be | ||
* nonnegative. | ||
*/ | ||
explicit LinearAccelerationMaxMagnitudeConstraint(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. | ||
* @param linearAcceleration The robot's linear acceleration. | ||
* @param angularAcceleration The robot's angular acceleration. | ||
*/ | ||
void Apply(sleipnir::OptimizationProblem& problem, | ||
[[maybe_unused]] const Pose2v& pose, | ||
[[maybe_unused]] const Translation2v& linearVelocity, | ||
[[maybe_unused]] const sleipnir::Variable& angularVelocity, | ||
const Translation2v& linearAcceleration, | ||
[[maybe_unused]] const sleipnir::Variable& angularAcceleration) { | ||
if (m_maxMagnitude == 0.0) { | ||
problem.SubjectTo(linearAcceleration.X() == 0.0); | ||
problem.SubjectTo(linearAcceleration.Y() == 0.0); | ||
} else { | ||
problem.SubjectTo(linearAcceleration.SquaredNorm() <= | ||
m_maxMagnitude * 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 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