Skip to content

Commit e432f3c

Browse files
Merge branch 'main' into feature/constraint_array
2 parents f7b3644 + 34be3bf commit e432f3c

File tree

283 files changed

+15634
-1585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

283 files changed

+15634
-1585
lines changed

.github/workflows/ros-build-test.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: System deps
3131
run: |
3232
apt-get update
33-
apt-get install -y git ninja-build liburdfdom-dev liboctomap-dev libassimp-dev checkinstall
33+
apt-get install -y git ninja-build liburdfdom-dev liboctomap-dev libassimp-dev checkinstall wget rsync
3434
3535
- uses: actions/checkout@v2
3636
with:
@@ -56,6 +56,14 @@ jobs:
5656
cmake .. -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
5757
make -j4 && checkinstall
5858
59+
- name: Install ONNX Runtime
60+
run: |
61+
wget https://github.com/microsoft/onnxruntime/releases/download/v1.7.0/onnxruntime-linux-x64-1.7.0.tgz -P tmp/microsoft
62+
tar xf tmp/microsoft/onnxruntime-linux-x64-1.7.0.tgz -C tmp/microsoft
63+
rsync -a tmp/microsoft/onnxruntime-linux-x64-1.7.0/include/ /usr/local/include/onnxruntime
64+
rsync -a tmp/microsoft/onnxruntime-linux-x64-1.7.0/lib/ /usr/local/lib
65+
rsync -a src/ocs2/ocs2_mpcnet/ocs2_mpcnet_core/misc/onnxruntime/cmake/ /usr/local/share/onnxruntime
66+
5967
- name: Build (${{ matrix.build_type }})
6068
shell: bash
6169
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ ocs2_ddp/test/ddp_test_generated/
2525
*.out
2626
*.synctex.gz
2727
.vscode/
28+
runs/

jenkins-pipeline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
library 'continuous_integration_pipeline'
2-
ciPipeline("--ros-distro noetic --publish-doxygen --recipes raisimlib\
2+
ciPipeline("--ros-distro noetic --publish-doxygen --recipes onnxruntime raisimlib\
33
--dependencies '[email protected]:leggedrobotics/hpp-fcl.git;master;git'\
44
'[email protected]:leggedrobotics/pinocchio.git;master;git'\
55
'[email protected]:leggedrobotics/ocs2_robotic_assets.git;main;git'\

ocs2/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<exec_depend>ocs2_oc</exec_depend>
1717
<exec_depend>ocs2_qp_solver</exec_depend>
1818
<exec_depend>ocs2_ddp</exec_depend>
19+
<exec_depend>ocs2_slp</exec_depend>
1920
<exec_depend>ocs2_sqp</exec_depend>
2021
<exec_depend>ocs2_ros_interfaces</exec_depend>
2122
<exec_depend>ocs2_python_interface</exec_depend>
@@ -25,6 +26,7 @@
2526
<exec_depend>ocs2_robotic_examples</exec_depend>
2627
<exec_depend>ocs2_thirdparty</exec_depend>
2728
<exec_depend>ocs2_raisim</exec_depend>
29+
<exec_depend>ocs2_mpcnet</exec_depend>
2830

2931
<export>
3032
<metapackage />

ocs2_core/cmake/ocs2_cxx_flags.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ list(APPEND OCS2_CXX_FLAGS
2222
)
2323

2424
# Cpp standard version
25-
set(CMAKE_CXX_STANDARD 11)
25+
set(CMAKE_CXX_STANDARD 14)
2626
set(CMAKE_CXX_STANDARD_REQUIRED ON)

ocs2_core/include/ocs2_core/control/ControllerType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ namespace ocs2 {
3434
/**
3535
* Enum class for specifying controller type
3636
*/
37-
enum class ControllerType { UNKNOWN, FEEDFORWARD, LINEAR, NEURAL_NETWORK };
37+
enum class ControllerType { UNKNOWN, FEEDFORWARD, LINEAR, ONNX, BEHAVIORAL };
3838

3939
} // namespace ocs2

ocs2_core/include/ocs2_core/misc/LinearAlgebra.h

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838
namespace ocs2 {
3939
namespace LinearAlgebra {
4040

41-
// forward declarations
42-
void makePsdEigenvalue(matrix_t& squareMatrix, scalar_t minEigenvalue);
43-
44-
void makePsdCholesky(matrix_t& A, scalar_t minEigenvalue);
45-
46-
void computeConstraintProjection(const matrix_t& Dm, const matrix_t& RmInvUmUmT, matrix_t& DmDagger, matrix_t& DmDaggerTRmDmDaggerUUT,
47-
matrix_t& RmInvConstrainedUUT);
48-
4941
/**
5042
* Set the eigenvalues of a triangular matrix to a minimum magnitude (maintaining the sign).
5143
*/
52-
inline void setTriangularMinimumEigenvalues(matrix_t& Lr, scalar_t minEigenValue = numeric_traits::weakEpsilon<scalar_t>()) {
53-
for (Eigen::Index i = 0; i < Lr.rows(); ++i) {
54-
scalar_t& eigenValue = Lr(i, i); // diagonal element is the eigenvalue
55-
if (eigenValue < 0.0) {
56-
eigenValue = std::min(-minEigenValue, eigenValue);
57-
} else {
58-
eigenValue = std::max(minEigenValue, eigenValue);
59-
}
60-
}
61-
}
44+
void setTriangularMinimumEigenvalues(matrix_t& Lr, scalar_t minEigenValue = numeric_traits::weakEpsilon<scalar_t>());
6245

6346
/**
6447
* Makes the input matrix PSD using a eigenvalue decomposition.
6548
*
66-
* @tparam Derived type.
67-
* @param squareMatrix: The matrix to become PSD.
49+
* @param [in, out] squareMatrix: The matrix to become PSD.
6850
* @param [in] minEigenvalue: minimum eigenvalue.
6951
*/
70-
template <typename Derived>
71-
void makePsdEigenvalue(Eigen::MatrixBase<Derived>& squareMatrix, scalar_t minEigenvalue = numeric_traits::limitEpsilon<scalar_t>()) {
72-
matrix_t mat = squareMatrix;
73-
makePsdEigenvalue(mat, minEigenvalue);
74-
squareMatrix = mat;
75-
}
52+
void makePsdEigenvalue(matrix_t& squareMatrix, scalar_t minEigenvalue = numeric_traits::limitEpsilon<scalar_t>());
7653

7754
/**
7855
* Makes the input matrix PSD based on Gershgorin circle theorem. If the input matrix is positive definite and diagonally dominant,
@@ -89,20 +66,10 @@ void makePsdEigenvalue(Eigen::MatrixBase<Derived>& squareMatrix, scalar_t minEig
8966
* (1) Aii < minEigenvalue + Ri ==> minEigenvalue < lambda < minEigenvalue + 2 Ri
9067
* (2) Aii > minEigenvalue + Ri ==> minEigenvalue < Aii - Ri < lambda < Aii + Ri
9168
*
92-
* @tparam Derived type.
93-
* @param squareMatrix: The matrix to become PSD.
69+
* @param [in, out] squareMatrix: The matrix to become PSD.
9470
* @param [in] minEigenvalue: minimum eigenvalue.
9571
*/
96-
template <typename Derived>
97-
void makePsdGershgorin(Eigen::MatrixBase<Derived>& squareMatrix, scalar_t minEigenvalue = numeric_traits::limitEpsilon<scalar_t>()) {
98-
assert(squareMatrix.rows() == squareMatrix.cols());
99-
squareMatrix = 0.5 * (squareMatrix + squareMatrix.transpose()).eval();
100-
for (size_t i = 0; i < squareMatrix.rows(); i++) {
101-
// Gershgorin radius: since the matrix is symmetric we use column sum instead of row sum
102-
auto Ri = squareMatrix.col(i).cwiseAbs().sum() - std::abs(squareMatrix(i, i));
103-
squareMatrix(i, i) = std::max(squareMatrix(i, i), Ri + minEigenvalue);
104-
}
105-
}
72+
void makePsdGershgorin(matrix_t& squareMatrix, scalar_t minEigenvalue = numeric_traits::limitEpsilon<scalar_t>());
10673

10774
/**
10875
* Makes the input matrix PSD based on modified Cholesky decomposition.
@@ -116,32 +83,19 @@ void makePsdGershgorin(Eigen::MatrixBase<Derived>& squareMatrix, scalar_t minEig
11683
* References : C-J. Lin and J. J. Moré, Incomplete Cholesky Factorizations with Limited memory, SIAM J. Sci. Comput.
11784
* 21(1), pp. 24-45, 1999
11885
*
119-
* @tparam Derived type.
120-
* @param A: The matrix to become PSD.
86+
* @param [in, out] A: The matrix to become PSD.
12187
* @param [in] minEigenvalue: minimum eigenvalue.
12288
*/
123-
template <typename Derived>
124-
void makePsdCholesky(Eigen::MatrixBase<Derived>& A, scalar_t minEigenvalue = numeric_traits::limitEpsilon<scalar_t>()) {
125-
matrix_t mat = A;
126-
makePsdCholesky(mat, minEigenvalue);
127-
A = mat;
128-
}
89+
void makePsdCholesky(matrix_t& A, scalar_t minEigenvalue = numeric_traits::limitEpsilon<scalar_t>());
12990

13091
/**
13192
* Computes the U*U^T decomposition associated to the inverse of the input matrix, where U is an upper triangular
13293
* matrix. Note that the U*U^T decomposition is different from the Cholesky decomposition (U^T*U).
13394
*
134-
* @tparam Derived type.
13595
* @param [in] Am: A symmetric square positive definite matrix
13696
* @param [out] AmInvUmUmT: The upper-triangular matrix associated to the UUT decomposition of inv(Am) matrix.
13797
*/
138-
template <typename Derived>
139-
void computeInverseMatrixUUT(const Derived& Am, Derived& AmInvUmUmT) {
140-
// Am = Lm Lm^T --> inv(Am) = inv(Lm^T) inv(Lm) where Lm^T is upper triangular
141-
Eigen::LLT<Derived> lltOfA(Am);
142-
AmInvUmUmT.setIdentity(Am.rows(), Am.cols()); // for dynamic size matrices
143-
lltOfA.matrixU().solveInPlace(AmInvUmUmT);
144-
}
98+
void computeInverseMatrixUUT(const matrix_t& Am, matrix_t& AmInvUmUmT);
14599

146100
/**
147101
* Computes constraint projection for linear constraints C*x + D*u - e = 0, with the weighting inv(Rm)
@@ -154,11 +108,36 @@ void computeInverseMatrixUUT(const Derived& Am, Derived& AmInvUmUmT) {
154108
* @param [out] RmInvConstrainedUUT: The VVT decomposition of (I-DmDagger*Dm) * inv(Rm) * (I-DmDagger*Dm)^T where V is of
155109
* the dimension n_u*(n_u-n_c) with n_u = Rm.rows() and n_c = Dm.rows().
156110
*/
157-
template <typename DerivedInputMatrix>
158-
void computeConstraintProjection(const matrix_t& Dm, const DerivedInputMatrix& RmInvUmUmT, matrix_t& DmDagger,
159-
matrix_t& DmDaggerTRmDmDaggerUUT, matrix_t& RmInvConstrainedUUT) {
160-
computeConstraintProjection(Dm, matrix_t(RmInvUmUmT), DmDagger, DmDaggerTRmDmDaggerUUT, RmInvConstrainedUUT);
161-
}
111+
void computeConstraintProjection(const matrix_t& Dm, const matrix_t& RmInvUmUmT, matrix_t& DmDagger, matrix_t& DmDaggerTRmDmDaggerUUT,
112+
matrix_t& RmInvConstrainedUUT);
113+
114+
/**
115+
* Returns the linear projection
116+
* u = Pu * \tilde{u} + Px * x + Pe
117+
*
118+
* s.t. C*x + D*u + e = 0 is satisfied for any \tilde{u}
119+
*
120+
* Implementation based on the QR decomposition
121+
*
122+
* @param [in] constraint : C = dfdx, D = dfdu, e = f;
123+
* @return Projection terms Px = dfdx, Pu = dfdu, Pe = f (first) and left pseudo-inverse of D^T (second);
124+
*/
125+
std::pair<VectorFunctionLinearApproximation, matrix_t> qrConstraintProjection(const VectorFunctionLinearApproximation& constraint);
126+
127+
/**
128+
* Returns the linear projection
129+
* u = Pu * \tilde{u} + Px * x + Pe
130+
*
131+
* s.t. C*x + D*u + e = 0 is satisfied for any \tilde{u}
132+
*
133+
* Implementation based on the LU decomposition
134+
*
135+
* @param [in] constraint : C = dfdx, D = dfdu, e = f;
136+
* @param [in] extractPseudoInverse : If true, left pseudo-inverse of D^T is returned. If false, an empty matrix is returned;
137+
* @return Projection terms Px = dfdx, Pu = dfdu, Pe = f (first) and left pseudo-inverse of D^T (second);
138+
*/
139+
std::pair<VectorFunctionLinearApproximation, matrix_t> luConstraintProjection(const VectorFunctionLinearApproximation& constraint,
140+
bool extractPseudoInverse = false);
162141

163142
/** Computes the rank of a matrix */
164143
template <typename Derived>

ocs2_core/include/ocs2_core/model_data/Metrics.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ struct LagrangianMetricsConstRef {
5858
* cost : The total cost in a particular time point.
5959
* stateEqConstraint : An array of all state equality constraints.
6060
* stateInputEqConstraint : An array of all state-input equality constraints.
61+
* stateIneqConstraint : An array of all state inequality constraints.
62+
* stateInputIneqConstraint : An array of all state-input inequality constraints.
6163
* stateEqLagrangian : An array of state equality constraint terms handled by Lagrangian method.
6264
* stateIneqLagrangian : An array of state inequality constraint terms handled by Lagrangian method.
6365
* stateInputEqLagrangian : An array of state-input equality constraint terms handled by Lagrangian method.
@@ -74,6 +76,10 @@ struct Metrics {
7476
vector_array_t stateEqConstraint;
7577
vector_array_t stateInputEqConstraint;
7678

79+
// Inequality constraints
80+
vector_array_t stateIneqConstraint;
81+
vector_array_t stateInputIneqConstraint;
82+
7783
// Lagrangians
7884
std::vector<LagrangianMetrics> stateEqLagrangian;
7985
std::vector<LagrangianMetrics> stateIneqLagrangian;
@@ -89,6 +95,9 @@ struct Metrics {
8995
// Equality constraints
9096
stateEqConstraint.swap(other.stateEqConstraint);
9197
stateInputEqConstraint.swap(other.stateInputEqConstraint);
98+
// Inequality constraints
99+
stateIneqConstraint.swap(other.stateIneqConstraint);
100+
stateInputIneqConstraint.swap(other.stateInputIneqConstraint);
92101
// Lagrangians
93102
stateEqLagrangian.swap(other.stateEqLagrangian);
94103
stateIneqLagrangian.swap(other.stateIneqLagrangian);
@@ -105,6 +114,9 @@ struct Metrics {
105114
// Equality constraints
106115
stateEqConstraint.clear();
107116
stateInputEqConstraint.clear();
117+
// Inequality constraints
118+
stateIneqConstraint.clear();
119+
stateInputIneqConstraint.clear();
108120
// Lagrangians
109121
stateEqLagrangian.clear();
110122
stateIneqLagrangian.clear();
@@ -185,7 +197,7 @@ std::vector<LagrangianMetrics> toLagrangianMetrics(const size_array_t& termsSize
185197
* @param [in] termsSize : An array of constraint terms size. It as the same size as the output array.
186198
* @param [in] vec : Serialized array of constraint terms of the format :
187199
* (..., constraintArray[i], ...)
188-
* @return An array of LagrangianMetrics structures associated to an array of constraint terms
200+
* @return An array of constraint terms.
189201
*/
190202
vector_array_t toConstraintArray(const size_array_t& termsSize, const vector_t& vec);
191203

ocs2_core/include/ocs2_core/penalties/augmented/ModifiedRelaxedBarrierPenalty.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ModifiedRelaxedBarrierPenalty final : public AugmentedPenaltyBase {
7676

7777
/** Factory function */
7878
static std::unique_ptr<ModifiedRelaxedBarrierPenalty> create(Config config) {
79-
return std::unique_ptr<ModifiedRelaxedBarrierPenalty>(new ModifiedRelaxedBarrierPenalty(std::move(config)));
79+
return std::make_unique<ModifiedRelaxedBarrierPenalty>(std::move(config));
8080
}
8181

8282
~ModifiedRelaxedBarrierPenalty() override = default;

ocs2_core/include/ocs2_core/penalties/augmented/QuadraticPenalty.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ class QuadraticPenalty final : public AugmentedPenaltyBase {
7272
explicit QuadraticPenalty(Config config) : config_(std::move(config)) {}
7373

7474
/** Factory function */
75-
static std::unique_ptr<QuadraticPenalty> create(Config config) {
76-
return std::unique_ptr<QuadraticPenalty>(new QuadraticPenalty(std::move(config)));
77-
}
75+
static std::unique_ptr<QuadraticPenalty> create(Config config) { return std::make_unique<QuadraticPenalty>(std::move(config)); }
7876

7977
~QuadraticPenalty() override = default;
8078
QuadraticPenalty* clone() const override { return new QuadraticPenalty(*this); }

0 commit comments

Comments
 (0)