Skip to content

Commit 43c548d

Browse files
committed
Merge branch 'main' into feature/ocs2_anymal_perception
# Conflicts: # ocs2_sqp/ocs2_sqp/CMakeLists.txt # ocs2_sqp/ocs2_sqp/include/ocs2_sqp/SqpSolver.h # ocs2_sqp/ocs2_sqp/src/SqpSolver.cpp
2 parents cb368eb + 8b64496 commit 43c548d

File tree

386 files changed

+24680
-3039
lines changed

Some content is hidden

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

386 files changed

+24680
-3039
lines changed

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

+21-2
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
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:
@@ -46,14 +46,33 @@ jobs:
4646
git clone --recurse-submodules https://github.com/leggedrobotics/pinocchio.git src/pinocchio
4747
git clone --recurse-submodules https://github.com/leggedrobotics/hpp-fcl.git src/hpp-fcl
4848
git clone https://github.com/leggedrobotics/ocs2_robotic_assets.git src/ocs2_robotic_assets
49+
50+
- name: Install RaiSim
51+
run: |
52+
git clone --depth 1 https://github.com/raisimTech/raisimLib.git -b v1.1.01 src/raisim_tech
53+
cd src/raisim_tech
54+
mkdir build
55+
cd build
56+
cmake .. -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
57+
make -j4 && checkinstall
58+
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+
4967
- name: Build (${{ matrix.build_type }})
5068
shell: bash
5169
run: |
5270
source /opt/ros/noetic/setup.bash
53-
catkin_make_isolated --use-ninja --merge --only-pkg-with-deps ocs2 --ignore-pkg ocs2_raisim --cmake-args -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
71+
catkin_make_isolated --use-ninja --merge --only-pkg-with-deps ocs2 --cmake-args -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
5472
5573
- name: Test
5674
shell: bash
5775
run: |
5876
source devel_isolated/setup.bash
5977
catkin_make_isolated --use-ninja --merge --only-pkg-with-deps ocs2 --catkin-make-args run_tests
78+
catkin_test_results

.gitignore

+1
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

+1-1
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

+3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
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>
2223
<exec_depend>ocs2_pinocchio</exec_depend>
2324
<exec_depend>ocs2_robotic_tools</exec_depend>
25+
<exec_depend>ocs2_perceptive</exec_depend>
2426
<exec_depend>ocs2_robotic_examples</exec_depend>
2527
<exec_depend>ocs2_thirdparty</exec_depend>
2628
<exec_depend>ocs2_raisim</exec_depend>
29+
<exec_depend>ocs2_mpcnet</exec_depend>
2730

2831
<export>
2932
<metapackage />

ocs2_core/cmake/ocs2_cxx_flags.cmake

+1-1
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/Types.h

+3-12
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,8 @@ using matrix_array2_t = std::vector<matrix_array_t>;
7171
/** Array of arrays of dynamic matrix trajectory type. */
7272
using matrix_array3_t = std::vector<matrix_array2_t>;
7373

74-
/** Eigen scalar type. */
75-
using eigen_scalar_t = Eigen::Matrix<scalar_t, 1, 1>;
76-
/** Eigen scalar trajectory type. */
77-
using eigen_scalar_array_t = std::vector<eigen_scalar_t>;
78-
/** Array of eigen scalar trajectory type. */
79-
using eigen_scalar_array2_t = std::vector<eigen_scalar_array_t>;
80-
/** Array of arrays of eigen scalar trajectory type. */
81-
using eigen_scalar_array3_t = std::vector<eigen_scalar_array2_t>;
82-
8374
/**
84-
* Defines the linear approximation
75+
* Defines the linear approximation of a scalar function
8576
* f(x,u) = dfdx' dx + dfdu' du + f
8677
*/
8778
struct ScalarFunctionLinearApproximation {
@@ -134,7 +125,7 @@ std::ostream& operator<<(std::ostream& out, const ScalarFunctionLinearApproximat
134125
*
135126
* @param[in] stateDim: Number of states.
136127
* @param[in] inputDim: Number of inputs.
137-
* @param[in] data: Given quadratic approximation.
128+
* @param[in] data: Given linear approximation.
138129
* @param[in] dataName: The name of the data which appears in the output error message.
139130
* @return The description of the error. If there was no error it would be empty;
140131
*/
@@ -148,7 +139,7 @@ inline ScalarFunctionLinearApproximation operator*(scalar_t scalar, ScalarFuncti
148139
}
149140

150141
/**
151-
* Defines the quadratic approximation
142+
* Defines the quadratic approximation of a scalar function
152143
* f(x,u) = 1/2 dx' dfdxx dx + du' dfdux dx + 1/2 du' dfduu du + dfdx' dx + dfdu' du + f
153144
*/
154145
struct ScalarFunctionQuadraticApproximation {

ocs2_core/include/ocs2_core/constraint/StateConstraintCollection.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ class StateConstraintCollection : public Collection<StateConstraint> {
4949
~StateConstraintCollection() override = default;
5050
StateConstraintCollection* clone() const override;
5151

52-
/** Returns the number of active constraints at given time. */
53-
virtual size_t getNumConstraints(scalar_t time) const;
52+
/** Returns the number of active constraints at a given time. */
53+
size_t getNumConstraints(scalar_t time) const;
5454

55-
/** Get the constraint vector value */
56-
virtual vector_t getValue(scalar_t time, const vector_t& state, const PreComputation& preComp) const;
55+
/** Returns the number of active constraints at a given time for each term. If a term is inactive, its size is zero. */
56+
size_array_t getTermsSize(scalar_t time) const;
57+
58+
/** Get an array of all constraints. If a term is inactive, the corresponding element is a vector of size zero. */
59+
virtual vector_array_t getValue(scalar_t time, const vector_t& state, const PreComputation& preComp) const;
5760

5861
/** Get the constraint linear approximation */
5962
virtual VectorFunctionLinearApproximation getLinearApproximation(scalar_t time, const vector_t& state,
@@ -68,4 +71,4 @@ class StateConstraintCollection : public Collection<StateConstraint> {
6871
StateConstraintCollection(const StateConstraintCollection& other);
6972
};
7073

71-
} // namespace ocs2
74+
} // namespace ocs2

ocs2_core/include/ocs2_core/constraint/StateInputConstraintCollection.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ class StateInputConstraintCollection : public Collection<StateInputConstraint> {
4949
~StateInputConstraintCollection() override = default;
5050
StateInputConstraintCollection* clone() const override;
5151

52-
/** Returns the number of active constraints at given time. */
53-
virtual size_t getNumConstraints(scalar_t time) const;
52+
/** Returns the number of active constraints at a given time. */
53+
size_t getNumConstraints(scalar_t time) const;
5454

55-
/** Get the constraint vector value */
56-
virtual vector_t getValue(scalar_t time, const vector_t& state, const vector_t& input, const PreComputation& preComp) const;
55+
/** Returns the number of active constraints at a given time for each term. If a term is inactive, its size is zero. */
56+
size_array_t getTermsSize(scalar_t time) const;
57+
58+
/** Get an array of all constraints. If a term is inactive, the corresponding element is a vector of size zero. */
59+
virtual vector_array_t getValue(scalar_t time, const vector_t& state, const vector_t& input, const PreComputation& preComp) const;
5760

5861
/** Get the constraint linear approximation */
5962
virtual VectorFunctionLinearApproximation getLinearApproximation(scalar_t time, const vector_t& state, const vector_t& input,
@@ -68,4 +71,4 @@ class StateInputConstraintCollection : public Collection<StateInputConstraint> {
6871
StateInputConstraintCollection(const StateInputConstraintCollection& other);
6972
};
7073

71-
} // namespace ocs2
74+
} // namespace ocs2

ocs2_core/include/ocs2_core/control/ControllerType.h

+1-1
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/integration/TrapezoidalIntegration.h

+16-6
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,32 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

3030
#pragma once
3131

32+
#include <cassert>
3233
#include <vector>
3334

3435
namespace ocs2 {
3536

36-
template <typename SCALAR_T>
37-
SCALAR_T trapezoidalIntegration(const std::vector<SCALAR_T>& timeTrajectory, const std::vector<SCALAR_T>& valueTrajectory) {
37+
/**
38+
* Compute the trapezoidal integration of a trajectory of VALUE_T given the time stamp timeTrajectory and initial value initialValue.
39+
*
40+
* @note It requires that the VALUE_T has overwrite operator+(VALUE_T, VALUE_T) and define VALUE_T::operator*(SCALAR_T)
41+
*/
42+
template <typename SCALAR_T, typename VALUE_T>
43+
VALUE_T trapezoidalIntegration(const std::vector<SCALAR_T>& timeTrajectory, const std::vector<VALUE_T>& valueTrajectory,
44+
VALUE_T initialValue) {
45+
assert(timeTrajectory.size() == valueTrajectory.size());
46+
3847
if (timeTrajectory.size() < 2) {
39-
return 0.0;
48+
return initialValue;
4049
}
4150

42-
SCALAR_T areaUnderCurve = 0.0;
4351
for (size_t k = 1; k < timeTrajectory.size(); k++) {
44-
areaUnderCurve += 0.5 * (valueTrajectory[k] + valueTrajectory[k - 1]) * (timeTrajectory[k] - timeTrajectory[k - 1]);
52+
auto temp = valueTrajectory[k - 1] + valueTrajectory[k];
53+
temp *= (0.5 * (timeTrajectory[k] - timeTrajectory[k - 1]));
54+
initialValue += temp;
4555
} // end of k loop
4656

47-
return areaUnderCurve;
57+
return initialValue;
4858
}
4959

5060
} // namespace ocs2

ocs2_core/include/ocs2_core/loopshaping/constraint/LoopshapingStateConstraint.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ class LoopshapingStateConstraint final : public StateConstraintCollection {
4747

4848
LoopshapingStateConstraint* clone() const override { return new LoopshapingStateConstraint(*this); }
4949

50-
vector_t getValue(scalar_t time, const vector_t& state, const PreComputation& preComp) const override;
50+
vector_array_t getValue(scalar_t time, const vector_t& state, const PreComputation& preComp) const override;
5151
VectorFunctionLinearApproximation getLinearApproximation(scalar_t time, const vector_t& state,
5252
const PreComputation& preComp) const override;
53+
5354
VectorFunctionQuadraticApproximation getQuadraticApproximation(scalar_t time, const vector_t& state,
5455
const PreComputation& preComp) const override;
5556

ocs2_core/include/ocs2_core/loopshaping/constraint/LoopshapingStateInputConstraint.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class LoopshapingStateInputConstraint : public StateInputConstraintCollection {
4141
public:
4242
~LoopshapingStateInputConstraint() override = default;
4343

44-
vector_t getValue(scalar_t time, const vector_t& state, const vector_t& input, const PreComputation& preComp) const override;
44+
vector_array_t getValue(scalar_t time, const vector_t& state, const vector_t& input, const PreComputation& preComp) const override;
4545

4646
protected:
4747
LoopshapingStateInputConstraint(const StateInputConstraintCollection& systemConstraint,

ocs2_core/include/ocs2_core/misc/LinearAlgebra.h

+38-59
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>

0 commit comments

Comments
 (0)