Skip to content

Commit 5ffa5d0

Browse files
no SQP dependency
1 parent e0c6aa5 commit 5ffa5d0

16 files changed

+356
-105
lines changed

ocs2_pipg/CMakeLists.txt

+3-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ set(CATKIN_PACKAGE_DEPENDENCIES
66
ocs2_mpc
77
ocs2_oc
88
ocs2_qp_solver
9-
ocs2_sqp
109
)
1110

1211
find_package(catkin REQUIRED COMPONENTS
@@ -46,9 +45,10 @@ include_directories(
4645
)
4746

4847
add_library(${PROJECT_NAME}
48+
src/Helpers.cpp
4949
src/PipgSettings.cpp
5050
src/PipgSolver.cpp
51-
src/Helpers.cpp
51+
src/SlpSettings.cpp
5252
src/mpc/PipgMpcSolver.cpp
5353
)
5454
add_dependencies(${PROJECT_NAME}
@@ -94,6 +94,7 @@ install(DIRECTORY include/${PROJECT_NAME}/
9494
catkin_add_gtest(test_${PROJECT_NAME}
9595
test/testHelpers.cpp
9696
test/testPipgSolver.cpp
97+
test/testSlpSolver.cpp
9798
)
9899
add_dependencies(test_${PROJECT_NAME}
99100
${catkin_EXPORTED_TARGETS}
@@ -103,15 +104,3 @@ target_link_libraries(test_${PROJECT_NAME}
103104
${catkin_LIBRARIES}
104105
gtest_main
105106
)
106-
107-
catkin_add_gtest(test_pipg_mpc
108-
test/testPipgMpc.cpp
109-
)
110-
add_dependencies(test_pipg_mpc
111-
${catkin_EXPORTED_TARGETS}
112-
)
113-
target_link_libraries(test_pipg_mpc
114-
${PROJECT_NAME}
115-
${catkin_LIBRARIES}
116-
gtest_main
117-
)

ocs2_pipg/include/ocs2_pipg/Helpers.h

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
1+
/******************************************************************************
2+
Copyright (c) 2020, Farbod Farshidian. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
* Neither the name of the copyright holder nor the names of its
15+
contributors may be used to endorse or promote products derived from
16+
this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
******************************************************************************/
29+
130
#pragma once
231

332
#include <ocs2_core/Types.h>
433
#include <ocs2_core/thread_support/ThreadPool.h>
534
#include <ocs2_oc/oc_problem/OcpSize.h>
635

736
namespace ocs2 {
8-
namespace pipg {
37+
namespace slp {
938

1039
vector_t hessianAbsRowSum(const OcpSize& ocpSize, const std::vector<ScalarFunctionQuadraticApproximation>& cost);
1140

1241
vector_t GGTAbsRowSumInParallel(const OcpSize& ocpSize, const std::vector<VectorFunctionLinearApproximation>& dynamics,
1342
const std::vector<VectorFunctionLinearApproximation>* constraints, const vector_array_t* scalingVectorsPtr,
1443
ThreadPool& threadPool);
15-
} // namespace pipg
44+
} // namespace slp
1645
} // namespace ocs2

ocs2_pipg/include/ocs2_pipg/PipgSettings.h

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

3030
#pragma once
3131

32-
#include <string>
33-
3432
#include <ocs2_core/Types.h>
3533

3634
namespace ocs2 {
@@ -56,6 +54,14 @@ struct Settings {
5654
bool displayShortSummary = false;
5755
};
5856

57+
/**
58+
* Loads the PIPG settings from a given file.
59+
*
60+
* @param [in] filename: File name which contains the configuration data.
61+
* @param [in] fieldName: Field name which contains the configuration data.
62+
* @param [in] verbose: Flag to determine whether to print out the loaded settings or not.
63+
* @return The settings
64+
*/
5965
Settings loadSettings(const std::string& filename, const std::string& fieldName = "pipg", bool verbose = true);
6066

6167
} // namespace pipg

ocs2_pipg/include/ocs2_pipg/PipgSolver.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4343

4444
namespace ocs2 {
4545

46+
/*
47+
* First order primal-dual method for solving optimal control problem based on:
48+
* "Proportional-Integral Projected Gradient Method for Model Predictive Control"
49+
* https://arxiv.org/abs/2009.06980
50+
*/
4651
class PipgSolver {
4752
public:
4853
/**
49-
* @brief Construct a new PIPG with pipg setting object.
54+
* @brief Constructor.
5055
*
5156
* @param Settings: PIPG setting
5257
*/

ocs2_pipg/include/ocs2_pipg/PipgSolverStatus.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ enum class SolverStatus {
4040
UNDEFINED,
4141
};
4242

43+
/** Transforms pipg::SolverStatus to string */
4344
inline std::string toString(SolverStatus s) {
4445
switch (s) {
4546
case SolverStatus::SUCCESS:
+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/******************************************************************************
2+
Copyright (c) 2020, Farbod Farshidian. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
* Neither the name of the copyright holder nor the names of its
15+
contributors may be used to endorse or promote products derived from
16+
this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
******************************************************************************/
29+
30+
#pragma once
31+
32+
#include <ocs2_core/Types.h>
33+
#include <ocs2_core/integration/SensitivityIntegrator.h>
34+
35+
#include "ocs2_pipg/PipgSettings.h"
36+
37+
namespace ocs2 {
38+
namespace slp {
39+
40+
/** Multiple-shooting SLP (Successive Linear Programming) settings */
41+
struct Settings {
42+
size_t slpIteration = 10; // Maximum number of SLP iterations
43+
scalar_t deltaTol = 1e-6; // Termination condition : RMS update of x(t) and u(t) are both below this value
44+
scalar_t costTol = 1e-4; // Termination condition : (cost{i+1} - (cost{i}) < costTol AND constraints{i+1} < g_min
45+
46+
// Linesearch - step size rules
47+
scalar_t alpha_decay = 0.5; // multiply the step size by this factor every time a linesearch step is rejected.
48+
scalar_t alpha_min = 1e-4; // terminate linesearch if the attempted step size is below this threshold
49+
50+
// Linesearch - step acceptance criteria with c = costs, g = the norm of constraint violation, and w = [x; u]
51+
scalar_t g_max = 1e6; // (1): IF g{i+1} > g_max REQUIRE g{i+1} < (1-gamma_c) * g{i}
52+
scalar_t g_min = 1e-6; // (2): ELSE IF (g{i} < g_min AND g{i+1} < g_min AND dc/dw'{i} * delta_w < 0) REQUIRE armijo condition
53+
scalar_t armijoFactor = 1e-4; // Armijo condition: c{i+1} < c{i} + armijoFactor * dc/dw'{i} * delta_w
54+
scalar_t gamma_c = 1e-6; // (3): ELSE REQUIRE c{i+1} < (c{i} - gamma_c * g{i}) OR g{i+1} < (1-gamma_c) * g{i}
55+
56+
// Discretization method
57+
scalar_t dt = 0.01; // user-defined time discretization
58+
SensitivityIntegratorType integratorType = SensitivityIntegratorType::RK2;
59+
60+
// Inequality penalty relaxed barrier parameters
61+
scalar_t inequalityConstraintMu = 0.0;
62+
scalar_t inequalityConstraintDelta = 1e-6;
63+
64+
// Printing
65+
bool printSolverStatus = false; // Print HPIPM status after solving the QP subproblem
66+
bool printSolverStatistics = false; // Print benchmarking of the multiple shooting method
67+
bool printLinesearch = false; // Print linesearch information
68+
69+
// Threading
70+
size_t nThreads = 4;
71+
int threadPriority = 50;
72+
73+
// LP subproblem solver settings
74+
pipg::Settings pipgSettings = pipg::Settings();
75+
};
76+
77+
/**
78+
* Loads the multiple shooting SLP settings from a given file.
79+
*
80+
* @param [in] filename: File name which contains the configuration data.
81+
* @param [in] fieldName: Field name which contains the configuration data.
82+
* @param [in] verbose: Flag to determine whether to print out the loaded settings or not.
83+
* @return The settings
84+
*/
85+
Settings loadSettings(const std::string& filename, const std::string& fieldName = "multiple_shooting", bool verbose = true);
86+
87+
} // namespace slp
88+
} // namespace ocs2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/******************************************************************************
2+
Copyright (c) 2020, Farbod Farshidian. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
* Neither the name of the copyright holder nor the names of its
15+
contributors may be used to endorse or promote products derived from
16+
this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
******************************************************************************/
29+
30+
#pragma once
31+
32+
#include <string>
33+
34+
#include <ocs2_core/Types.h>
35+
#include <ocs2_oc/oc_data/PerformanceIndex.h>
36+
#include <ocs2_oc/search_strategy/FilterLinesearch.h>
37+
38+
namespace ocs2 {
39+
namespace slp {
40+
41+
/** Different types of convergence */
42+
enum class Convergence { FALSE, ITERATIONS, STEPSIZE, METRICS, PRIMAL };
43+
44+
/** Struct to contain the result and logging data of the stepsize computation */
45+
struct StepInfo {
46+
// Step size and type
47+
scalar_t stepSize = 0.0;
48+
FilterLinesearch::StepType stepType = FilterLinesearch::StepType::UNKNOWN;
49+
50+
// Step in primal variables
51+
scalar_t dx_norm = 0.0; // norm of the state trajectory update
52+
scalar_t du_norm = 0.0; // norm of the input trajectory update
53+
54+
// Performance result after the step
55+
PerformanceIndex performanceAfterStep;
56+
scalar_t totalConstraintViolationAfterStep; // constraint metric used in the line search
57+
};
58+
59+
/** Transforms pipg::Convergence to string */
60+
inline std::string toString(const Convergence& convergence) {
61+
switch (convergence) {
62+
case Convergence::ITERATIONS:
63+
return "Maximum number of iterations reached";
64+
case Convergence::STEPSIZE:
65+
return "Step size below minimum";
66+
case Convergence::METRICS:
67+
return "Cost decrease and constraint satisfaction below tolerance";
68+
case Convergence::PRIMAL:
69+
return "Primal update below tolerance";
70+
case Convergence::FALSE:
71+
default:
72+
return "Not Converged";
73+
}
74+
}
75+
76+
} // namespace slp
77+
} // namespace ocs2

ocs2_pipg/include/ocs2_pipg/mpc/PipgMpcSolver.h

+7-9
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3939
#include <ocs2_oc/oc_solver/SolverBase.h>
4040
#include <ocs2_oc/search_strategy/FilterLinesearch.h>
4141

42-
#include <ocs2_sqp/SqpSettings.h>
43-
#include <ocs2_sqp/SqpSolverStatus.h>
44-
4542
#include "ocs2_pipg/PipgSolver.h"
43+
#include "ocs2_pipg/SlpSettings.h"
44+
#include "ocs2_pipg/SlpSolverStatus.h"
4645

4746
namespace ocs2 {
4847

@@ -51,12 +50,11 @@ class PipgMpcSolver : public SolverBase {
5150
/**
5251
* Constructor
5352
*
54-
* @param settings : settings for the multiple shooting solver.
53+
* @param settings : settings for the multiple shooting SLP solver.
5554
* @param [in] optimalControlProblem: The optimal control problem formulation.
5655
* @param [in] initializer: This class initializes the state-input for the time steps that no controller is available.
5756
*/
58-
PipgMpcSolver(sqp::Settings sqpSettings, pipg::Settings pipgSettings, const OptimalControlProblem& optimalControlProblem,
59-
const Initializer& initializer);
57+
PipgMpcSolver(slp::Settings settings, const OptimalControlProblem& optimalControlProblem, const Initializer& initializer);
6058

6159
~PipgMpcSolver() override;
6260

@@ -145,14 +143,14 @@ class PipgMpcSolver : public SolverBase {
145143
PrimalSolution toPrimalSolution(const std::vector<AnnotatedTime>& time, vector_array_t&& x, vector_array_t&& u);
146144

147145
/** Decides on the step to take and overrides given trajectories {x(t), u(t)} <- {x(t) + a*dx(t), u(t) + a*du(t)} */
148-
sqp::StepInfo takeStep(const PerformanceIndex& baseline, const std::vector<AnnotatedTime>& timeDiscretization, const vector_t& initState,
146+
slp::StepInfo takeStep(const PerformanceIndex& baseline, const std::vector<AnnotatedTime>& timeDiscretization, const vector_t& initState,
149147
const OcpSubproblemSolution& subproblemSolution, vector_array_t& x, vector_array_t& u);
150148

151149
/** Determine convergence after a step */
152-
sqp::Convergence checkConvergence(int iteration, const PerformanceIndex& baseline, const sqp::StepInfo& stepInfo) const;
150+
slp::Convergence checkConvergence(int iteration, const PerformanceIndex& baseline, const slp::StepInfo& stepInfo) const;
153151

154152
// Problem definition
155-
const sqp::Settings settings_;
153+
const slp::Settings settings_;
156154
DynamicsDiscretizer discretizer_;
157155
DynamicsSensitivityDiscretizer sensitivityDiscretizer_;
158156
std::vector<OptimalControlProblem> ocpDefinitions_;

ocs2_pipg/package.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<version>0.0.0</version>
55
<description>A numerical implementation of PIPG.</description>
66

7+
<maintainer email="[email protected]">Farbod Farshidian</maintainer>
78
<maintainer email="[email protected]">Zhengyu Fu</maintainer>
89

9-
<license>TODO</license>
10+
<license>BSD3</license>
1011

1112
<buildtool_depend>catkin</buildtool_depend>
1213
<depend>ocs2_core</depend>
13-
<depend>ocs2_oc</depend>
14-
<depend>ocs2_sqp</depend>
1514
<depend>ocs2_mpc</depend>
15+
<depend>ocs2_oc</depend>
1616

1717
<!-- Test dependancy -->
1818
<depend>ocs2_qp_solver</depend>

0 commit comments

Comments
 (0)