Skip to content

Commit

Permalink
renaming multishooting to sqp
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengrandia committed Jan 29, 2023
1 parent 43c548d commit 3c68c05
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ int main(int argc, char* argv[]) {
break;
}
case switched_model::Algorithm::SQP: {
const auto sqpSettings =
ocs2::multiple_shooting::loadSettings(anymal::getConfigFolderLoopshaping(configName) + "/multiple_shooting.info");
const auto sqpSettings = ocs2::sqp::loadSettings(anymal::getConfigFolderLoopshaping(configName) + "/multiple_shooting.info");
auto mpcPtr = getSqpMpc(*anymalInterface, mpcSettings, sqpSettings);
quadrupedLoopshapingMpcNode(nodeHandle, *anymalInterface, std::move(mpcPtr));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int main(int argc, char* argv[]) {
const auto mpcSettings = ocs2::mpc::loadSettings(taskFolder + configName + "/task.info");

std::unique_ptr<ocs2::MPC_BASE> mpcPtr;
const auto sqpSettings = ocs2::multiple_shooting::loadSettings(taskFolder + configName + "/multiple_shooting.info");
const auto sqpSettings = ocs2::sqp::loadSettings(taskFolder + configName + "/multiple_shooting.info");
switch (anymalInterface->modelSettings().algorithm_) {
case switched_model::Algorithm::DDP: {
const auto ddpSettings = ocs2::ddp::loadSettings(taskFolder + configName + "/task.info");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TestAnymalLoopshapingMpc : public ::testing::Test {
problem.targetTrajectoriesPtr = &targetTrajectories;

const auto mpcSettings = ocs2::mpc::loadSettings(configFolder + "/task.info");
const auto sqpSettings = ocs2::multiple_shooting::loadSettings(configFolder + "/multiple_shooting.info");
const auto sqpSettings = ocs2::sqp::loadSettings(configFolder + "/multiple_shooting.info");
mpcPtr = switched_model_loopshaping::getSqpMpc(*anymalInterface, mpcSettings, sqpSettings);

// Initialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TEST(TestAnymalLoopshapingMotionTracking, testSensitivity) {
const auto csvData = switched_model::readCsv(motionFilesPath + motionName + ".txt");
const auto motionData = switched_model::readMotion(csvData, 0.05);
const auto mpcSettings = ocs2::mpc::loadSettings(configFolder + "/task.info");
const auto sqpSettings = ocs2::multiple_shooting::loadSettings(configFolder + "/multiple_shooting.info");
const auto sqpSettings = ocs2::sqp::loadSettings(configFolder + "/multiple_shooting.info");
auto quadrupedSettings = switched_model::loadQuadrupedSettings(configFolder + "/task.info");
const auto frameDecl = anymal::frameDeclarationFromFile(configFolder + "/frame_declaration.info");
auto loopshapingDefinition = ocs2::loopshaping_property_tree::load(configFolder + "/loopshaping.info");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) {
break;
}
case switched_model::Algorithm::SQP: {
const auto sqpSettings = ocs2::multiple_shooting::loadSettings(anymal::getConfigFolder(configName) + "/multiple_shooting.info");
const auto sqpSettings = ocs2::sqp::loadSettings(anymal::getConfigFolder(configName) + "/multiple_shooting.info");
auto mpcPtr = getSqpMpc(*anymalInterface, mpcSettings, sqpSettings);
quadrupedMpcNode(nodeHandle, *anymalInterface, std::move(mpcPtr));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <ocs2_ddp/DDP_Settings.h>
#include <ocs2_mpc/MPC_BASE.h>
#include <ocs2_mpc/MPC_Settings.h>
#include <ocs2_sqp/MultipleShootingSettings.h>
#include <ocs2_sqp/SqpSettings.h>

#include "ocs2_quadruped_interface/QuadrupedInterface.h"

Expand All @@ -19,6 +19,6 @@ std::unique_ptr<ocs2::MPC_BASE> getDdpMpc(const QuadrupedInterface& quadrupedInt

/** Constructs an SQP MPC object */
std::unique_ptr<ocs2::MPC_BASE> getSqpMpc(const QuadrupedInterface& quadrupedInterface, const ocs2::mpc::Settings& mpcSettings,
const ocs2::multiple_shooting::Settings& sqpSettings);
const ocs2::sqp::Settings& sqpSettings);

} // namespace switched_model
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "ocs2_quadruped_interface/QuadrupedMpc.h"

#include <ocs2_ddp/GaussNewtonDDP_MPC.h>
#include <ocs2_sqp/MultipleShootingMpc.h>
#include <ocs2_sqp/SqpMpc.h>

namespace switched_model {

Expand All @@ -20,9 +20,9 @@ std::unique_ptr<ocs2::MPC_BASE> getDdpMpc(const QuadrupedInterface& quadrupedInt
}

std::unique_ptr<ocs2::MPC_BASE> getSqpMpc(const QuadrupedInterface& quadrupedInterface, const ocs2::mpc::Settings& mpcSettings,
const ocs2::multiple_shooting::Settings& sqpSettings) {
std::unique_ptr<ocs2::MPC_BASE> mpcPtr(new ocs2::MultipleShootingMpc(
mpcSettings, sqpSettings, quadrupedInterface.getOptimalControlProblem(), quadrupedInterface.getInitializer()));
const ocs2::sqp::Settings& sqpSettings) {
std::unique_ptr<ocs2::MPC_BASE> mpcPtr(
new ocs2::SqpMpc(mpcSettings, sqpSettings, quadrupedInterface.getOptimalControlProblem(), quadrupedInterface.getInitializer()));
mpcPtr->getSolverPtr()->setReferenceManager(quadrupedInterface.getReferenceManagerPtr());
mpcPtr->getSolverPtr()->setSynchronizedModules(quadrupedInterface.getSynchronizedModules());
return mpcPtr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <ocs2_ddp/DDP_Settings.h>
#include <ocs2_mpc/MPC_BASE.h>
#include <ocs2_mpc/MPC_Settings.h>
#include <ocs2_sqp/MultipleShootingSettings.h>
#include <ocs2_sqp/SqpSettings.h>

#include "ocs2_quadruped_loopshaping_interface/QuadrupedLoopshapingInterface.h"

Expand All @@ -19,6 +19,6 @@ std::unique_ptr<ocs2::MPC_BASE> getDdpMpc(const QuadrupedLoopshapingInterface& q

/** Constructs an SQP MPC object */
std::unique_ptr<ocs2::MPC_BASE> getSqpMpc(const QuadrupedLoopshapingInterface& quadrupedInterface, const ocs2::mpc::Settings& mpcSettings,
const ocs2::multiple_shooting::Settings& sqpSettings);
const ocs2::sqp::Settings& sqpSettings);

} // namespace switched_model_loopshaping
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "ocs2_quadruped_loopshaping_interface/QuadrupedLoopshapingMpc.h"

#include <ocs2_ddp/GaussNewtonDDP_MPC.h>
#include <ocs2_sqp/MultipleShootingMpc.h>
#include <ocs2_sqp/SqpMpc.h>

namespace switched_model_loopshaping {

Expand All @@ -20,9 +20,9 @@ std::unique_ptr<ocs2::MPC_BASE> getDdpMpc(const QuadrupedLoopshapingInterface& q
}

std::unique_ptr<ocs2::MPC_BASE> getSqpMpc(const QuadrupedLoopshapingInterface& quadrupedInterface, const ocs2::mpc::Settings& mpcSettings,
const ocs2::multiple_shooting::Settings& sqpSettings) {
std::unique_ptr<ocs2::MPC_BASE> mpcPtr(new ocs2::MultipleShootingMpc(
mpcSettings, sqpSettings, quadrupedInterface.getOptimalControlProblem(), quadrupedInterface.getInitializer()));
const ocs2::sqp::Settings& sqpSettings) {
std::unique_ptr<ocs2::MPC_BASE> mpcPtr(
new ocs2::SqpMpc(mpcSettings, sqpSettings, quadrupedInterface.getOptimalControlProblem(), quadrupedInterface.getInitializer()));
mpcPtr->getSolverPtr()->setReferenceManager(quadrupedInterface.getReferenceManagerPtr());
mpcPtr->getSolverPtr()->setSynchronizedModules({quadrupedInterface.getLoopshapingSynchronizedModule()});
return mpcPtr;
Expand Down
2 changes: 1 addition & 1 deletion ocs2_sqp/ocs2_sqp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ include_directories(

# Multiple shooting solver library
add_library(${PROJECT_NAME}
src/MultipleShootingLogging.cpp
src/SqpLogging.cpp
src/SqpSettings.cpp
src/SqpSolver.cpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <ocs2_core/Types.h>

#include <ocs2_oc/oc_solver/PerformanceIndex.h>
#include <ocs2_oc/oc_data/PerformanceIndex.h>

#include "ocs2_sqp/MultipleShootingSolverStatus.h"
#include "ocs2_sqp/SqpSolverStatus.h"

namespace ocs2 {
namespace multiple_shooting {
namespace sqp {

struct LogEntry {
// Problem info
Expand Down Expand Up @@ -143,5 +143,5 @@ void Logger<T>::write(std::ostream& stream) const {
}
}

} // namespace multiple_shooting
} // namespace sqp
} // namespace ocs2
5 changes: 3 additions & 2 deletions ocs2_sqp/ocs2_sqp/include/ocs2_sqp/SqpSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <hpipm_catkin/HpipmInterface.h>

#include "ocs2_sqp/MultipleShootingLogging.h"
#include "ocs2_sqp/SqpLogging.h"
#include "ocs2_sqp/SqpSettings.h"
#include "ocs2_sqp/SqpSolverStatus.h"

Expand Down Expand Up @@ -186,8 +186,9 @@ class SqpSolver : public SolverBase {
ProblemMetrics problemMetrics_;

// Benchmarking
size_t numProblems_{0};
size_t totalNumIterations_{0};
multiple_shooting::Logger<multiple_shooting::LogEntry> logger_;
sqp::Logger<sqp::LogEntry> logger_;
benchmark::RepeatedTimer initializationTimer_;
benchmark::RepeatedTimer linearQuadraticApproximationTimer_;
benchmark::RepeatedTimer solveQpTimer_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/

#include "ocs2_sqp/MultipleShootingLogging.h"
#include "ocs2_sqp/SqpLogging.h"

#include <iomanip>

namespace ocs2 {
namespace multiple_shooting {
namespace sqp {

std::ostream& operator<<(std::ostream& stream, const LogEntry& logEntry) {
const std::string delim = ", ";
Expand Down Expand Up @@ -90,5 +90,5 @@ std::string logHeader() {
return stream.str();
}

} // namespace multiple_shooting
} // namespace sqp
} // namespace ocs2
15 changes: 10 additions & 5 deletions ocs2_sqp/ocs2_sqp/src/SqpSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iostream>
#include <numeric>

#include <boost/filesystem.hpp>

#include <ocs2_oc/multiple_shooting/Helpers.h>
#include <ocs2_oc/multiple_shooting/Initialization.h>
#include <ocs2_oc/multiple_shooting/MetricsComputation.h>
Expand Down Expand Up @@ -98,11 +100,11 @@ SqpSolver::~SqpSolver() {
// Write to file
const std::string logFileName = settings_.logFilePath + "log_" + timeStamp + ".txt";
if (std::ofstream logfile{logFileName}) {
logfile << multiple_shooting::logHeader();
logfile << sqp::logHeader();
logger_.write(logfile);
std::cerr << "[MultipleShootingSolver] Log written to '" << logFileName << "'\n";
std::cerr << "[SqpSolver] Log written to '" << logFileName << "'\n";
} else {
std::cerr << "[MultipleShootingSolver] Unable to open '" << logFileName << "'\n";
std::cerr << "[SqpSolver] Unable to open '" << logFileName << "'\n";
}
}
}
Expand All @@ -114,8 +116,9 @@ void SqpSolver::reset() {
performanceIndeces_.clear();

// reset timers
numProblems_ = 0;
totalNumIterations_ = 0;
logger_ = multiple_shooting::Logger<multiple_shooting::LogEntry>(settings_.logSize);
logger_ = sqp::Logger<sqp::LogEntry>(settings_.logSize);
linearQuadraticApproximationTimer_.reset();
solveQpTimer_.reset();
linesearchTimer_.reset();
Expand Down Expand Up @@ -244,7 +247,7 @@ void SqpSolver::runImpl(scalar_t initTime, const vector_t& initState, scalar_t f
logEntry.solveQpTime = solveQpTimer_.getLastIntervalInMilliseconds();
logEntry.linesearchTime = linesearchTimer_.getLastIntervalInMilliseconds();
logEntry.baselinePerformanceIndex = baselinePerformance;
logEntry.totalConstraintViolationBaseline = totalConstraintViolation(baselinePerformance);
logEntry.totalConstraintViolationBaseline = FilterLinesearch::totalConstraintViolation(baselinePerformance);
logEntry.stepInfo = stepInfo;
logEntry.convergence = convergence;
logger_.advance();
Expand All @@ -255,6 +258,8 @@ void SqpSolver::runImpl(scalar_t initTime, const vector_t& initState, scalar_t f
++totalNumIterations_;
}

++numProblems_;

computeControllerTimer_.startTimer();
primalSolution_ = toPrimalSolution(timeDiscretization, std::move(x), std::move(u));
problemMetrics_ = multiple_shooting::toProblemMetrics(timeDiscretization, std::move(metrics));
Expand Down
4 changes: 2 additions & 2 deletions ocs2_sqp/ocs2_sqp/test/testLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <gtest/gtest.h>

#include "ocs2_sqp/MultipleShootingLogging.h"
#include "ocs2_sqp/SqpLogging.h"

using namespace ocs2;

TEST(test_logging, wrap_around) {
const int Ntest = 3;
multiple_shooting::Logger<int> logger(Ntest);
sqp::Logger<int> logger(Ntest);

std::stringstream stream;

Expand Down

0 comments on commit 3c68c05

Please sign in to comment.