Skip to content

Commit

Permalink
refactor(osqp_interface): added autoware prefix to osqp_interface
Browse files Browse the repository at this point in the history
Signed-off-by: Esteve Fernandez <[email protected]>
  • Loading branch information
esteve committed Oct 9, 2024
1 parent 9d78e00 commit 3192ad6
Show file tree
Hide file tree
Showing 26 changed files with 81 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.14)
project(osqp_interface)
project(autoware_osqp_interface)

find_package(autoware_cmake REQUIRED)
autoware_package()
Expand All @@ -17,9 +17,9 @@ set(OSQP_INTERFACE_LIB_SRC
)

set(OSQP_INTERFACE_LIB_HEADERS
include/osqp_interface/csc_matrix_conv.hpp
include/osqp_interface/osqp_interface.hpp
include/osqp_interface/visibility_control.hpp
include/autoware/osqp_interface/csc_matrix_conv.hpp
include/autoware/osqp_interface/osqp_interface.hpp
include/autoware/osqp_interface/visibility_control.hpp
)

ament_auto_add_library(${PROJECT_NAME} SHARED
Expand All @@ -28,18 +28,18 @@ ament_auto_add_library(${PROJECT_NAME} SHARED
)
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-error=old-style-cast -Wno-error=useless-cast)

target_include_directories(osqp_interface
target_include_directories(${PROJECT_NAME}
SYSTEM PUBLIC
"${OSQP_INCLUDE_DIR}"
"${EIGEN3_INCLUDE_DIR}"
)

ament_target_dependencies(osqp_interface
ament_target_dependencies(${PROJECT_NAME}
Eigen3
osqp_vendor
)

# crucial so downstream package builds because osqp_interface exposes osqp.hpp
# crucial so downstream package builds because autoware_osqp_interface exposes osqp.hpp
ament_export_include_directories("${OSQP_INCLUDE_DIR}")
# crucial so the linking order is correct in a downstream package: libosqp_interface.a should come before libosqp.a
ament_export_libraries(osqp::osqp)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Interface for the OSQP library

This is the design document for the `osqp_interface` package.
This is the design document for the `autoware_osqp_interface` package.

## Purpose / Use cases

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef OSQP_INTERFACE__CSC_MATRIX_CONV_HPP_
#define OSQP_INTERFACE__CSC_MATRIX_CONV_HPP_
#ifndef AUTOWARE__OSQP_INTERFACE__CSC_MATRIX_CONV_HPP_
#define AUTOWARE__OSQP_INTERFACE__CSC_MATRIX_CONV_HPP_

#include "autoware/osqp_interface/visibility_control.hpp"
#include "osqp/glob_opts.h" // for 'c_int' type ('long' or 'long long')
#include "osqp_interface/visibility_control.hpp"

#include <Eigen/Core>

#include <vector>

namespace autoware
{
namespace common
{
namespace osqp
namespace autoware::osqp_interface
{
/// \brief Compressed-Column-Sparse Matrix
struct OSQP_INTERFACE_PUBLIC CSC_Matrix
Expand All @@ -46,8 +42,6 @@ OSQP_INTERFACE_PUBLIC CSC_Matrix calCSCMatrixTrapezoidal(const Eigen::MatrixXd &
/// \brief Print the given CSC matrix to the standard output
OSQP_INTERFACE_PUBLIC void printCSCMatrix(const CSC_Matrix & csc_mat);

} // namespace osqp
} // namespace common
} // namespace autoware
} // namespace autoware::osqp_interface

#endif // OSQP_INTERFACE__CSC_MATRIX_CONV_HPP_
#endif // AUTOWARE__OSQP_INTERFACE__CSC_MATRIX_CONV_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef OSQP_INTERFACE__OSQP_INTERFACE_HPP_
#define OSQP_INTERFACE__OSQP_INTERFACE_HPP_
#ifndef AUTOWARE__OSQP_INTERFACE__OSQP_INTERFACE_HPP_
#define AUTOWARE__OSQP_INTERFACE__OSQP_INTERFACE_HPP_

#include "autoware/osqp_interface/csc_matrix_conv.hpp"
#include "autoware/osqp_interface/visibility_control.hpp"
#include "osqp/osqp.h"
#include "osqp_interface/csc_matrix_conv.hpp"
#include "osqp_interface/visibility_control.hpp"

#include <Eigen/Core>
#include <rclcpp/rclcpp.hpp>
Expand All @@ -28,11 +28,7 @@
#include <tuple>
#include <vector>

namespace autoware
{
namespace common
{
namespace osqp
namespace autoware::osqp_interface
{
constexpr c_float INF = 1e30;

Expand Down Expand Up @@ -193,8 +189,6 @@ class OSQP_INTERFACE_PUBLIC OSQPInterface
void logUnsolvedStatus(const std::string & prefix_message = "") const;
};

} // namespace osqp
} // namespace common
} // namespace autoware
} // namespace autoware::osqp_interface

#endif // OSQP_INTERFACE__OSQP_INTERFACE_HPP_
#endif // AUTOWARE__OSQP_INTERFACE__OSQP_INTERFACE_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef OSQP_INTERFACE__VISIBILITY_CONTROL_HPP_
#define OSQP_INTERFACE__VISIBILITY_CONTROL_HPP_
#ifndef AUTOWARE__OSQP_INTERFACE__VISIBILITY_CONTROL_HPP_
#define AUTOWARE__OSQP_INTERFACE__VISIBILITY_CONTROL_HPP_

////////////////////////////////////////////////////////////////////////////////
#if defined(__WIN32)
Expand All @@ -34,4 +34,4 @@
#error "Unsupported Build Configuration"
#endif

#endif // OSQP_INTERFACE__VISIBILITY_CONTROL_HPP_
#endif // AUTOWARE__OSQP_INTERFACE__VISIBILITY_CONTROL_HPP_
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>osqp_interface</name>
<name>autoware_osqp_interface</name>
<version>1.0.0</version>
<description>Interface for the OSQP solver</description>
<maintainer email="[email protected]">Maxime CLEMENT</maintainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "osqp_interface/csc_matrix_conv.hpp"
#include "autoware/osqp_interface/csc_matrix_conv.hpp"

#include <Eigen/Core>
#include <Eigen/SparseCore>
Expand All @@ -21,11 +21,7 @@
#include <iostream>
#include <vector>

namespace autoware
{
namespace common
{
namespace osqp
namespace autoware::osqp_interface
{
CSC_Matrix calCSCMatrix(const Eigen::MatrixXd & mat)
{
Expand Down Expand Up @@ -136,6 +132,4 @@ void printCSCMatrix(const CSC_Matrix & csc_mat)
std::cout << "]\n";
}

} // namespace osqp
} // namespace common
} // namespace autoware
} // namespace autoware::osqp_interface
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "osqp_interface/osqp_interface.hpp"
#include "autoware/osqp_interface/osqp_interface.hpp"

#include "autoware/osqp_interface/csc_matrix_conv.hpp"
#include "osqp/osqp.h"
#include "osqp_interface/csc_matrix_conv.hpp"

#include <chrono>
#include <iostream>
Expand All @@ -25,11 +25,7 @@
#include <tuple>
#include <vector>

namespace autoware
{
namespace common
{
namespace osqp
namespace autoware::osqp_interface
{
OSQPInterface::OSQPInterface(const c_float eps_abs, const bool polish)
: m_work{nullptr, OSQPWorkspaceDeleter}
Expand Down Expand Up @@ -436,6 +432,4 @@ void OSQPInterface::logUnsolvedStatus(const std::string & prefix_message) const
// log with warning
RCLCPP_WARN(rclcpp::get_logger("osqp_interface"), output_message.c_str());
}
} // namespace osqp
} // namespace common
} // namespace autoware
} // namespace autoware::osqp_interface
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "autoware/osqp_interface/csc_matrix_conv.hpp"
#include "gtest/gtest.h"
#include "osqp_interface/csc_matrix_conv.hpp"

#include <Eigen/Core>

Expand All @@ -23,8 +23,8 @@

TEST(TestCscMatrixConv, Nominal)
{
using autoware::common::osqp::calCSCMatrix;
using autoware::common::osqp::CSC_Matrix;
using autoware::osqp_interface::calCSCMatrix;
using autoware::osqp_interface::CSC_Matrix;

Eigen::MatrixXd rect1(1, 2);
rect1 << 0.0, 1.0;
Expand Down Expand Up @@ -117,8 +117,8 @@ TEST(TestCscMatrixConv, Nominal)
}
TEST(TestCscMatrixConv, Trapezoidal)
{
using autoware::common::osqp::calCSCMatrixTrapezoidal;
using autoware::common::osqp::CSC_Matrix;
using autoware::osqp_interface::calCSCMatrixTrapezoidal;
using autoware::osqp_interface::CSC_Matrix;

Eigen::MatrixXd square1(2, 2);
Eigen::MatrixXd square2(3, 3);
Expand Down Expand Up @@ -166,10 +166,10 @@ TEST(TestCscMatrixConv, Trapezoidal)
}
TEST(TestCscMatrixConv, Print)
{
using autoware::common::osqp::calCSCMatrix;
using autoware::common::osqp::calCSCMatrixTrapezoidal;
using autoware::common::osqp::CSC_Matrix;
using autoware::common::osqp::printCSCMatrix;
using autoware::osqp_interface::calCSCMatrix;
using autoware::osqp_interface::calCSCMatrixTrapezoidal;
using autoware::osqp_interface::CSC_Matrix;
using autoware::osqp_interface::printCSCMatrix;
Eigen::MatrixXd square1(2, 2);
Eigen::MatrixXd rect1(1, 2);
square1 << 1.0, 2.0, 2.0, 4.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "autoware/osqp_interface/osqp_interface.hpp"
#include "gtest/gtest.h"
#include "osqp_interface/osqp_interface.hpp"

#include <Eigen/Core>

Expand All @@ -39,9 +39,9 @@ namespace

TEST(TestOsqpInterface, BasicQp)
{
using autoware::common::osqp::calCSCMatrix;
using autoware::common::osqp::calCSCMatrixTrapezoidal;
using autoware::common::osqp::CSC_Matrix;
using autoware::osqp_interface::calCSCMatrix;
using autoware::osqp_interface::calCSCMatrixTrapezoidal;
using autoware::osqp_interface::CSC_Matrix;

auto check_result =
[](const std::tuple<std::vector<double>, std::vector<double>, int, int, int> & result) {
Expand All @@ -66,20 +66,20 @@ TEST(TestOsqpInterface, BasicQp)
const Eigen::MatrixXd P = (Eigen::MatrixXd(2, 2) << 4, 1, 1, 2).finished();
const Eigen::MatrixXd A = (Eigen::MatrixXd(4, 2) << 1, 1, 1, 0, 0, 1, 0, 1).finished();
const std::vector<double> q = {1.0, 1.0};
const std::vector<double> l = {1.0, 0.0, 0.0, -autoware::common::osqp::INF};
const std::vector<double> u = {1.0, 0.7, 0.7, autoware::common::osqp::INF};
const std::vector<double> l = {1.0, 0.0, 0.0, -autoware::osqp_interface::INF};
const std::vector<double> u = {1.0, 0.7, 0.7, autoware::osqp_interface::INF};

{
// Define problem during optimization
autoware::common::osqp::OSQPInterface osqp;
autoware::osqp_interface::OSQPInterface osqp;
std::tuple<std::vector<double>, std::vector<double>, int, int, int> result =
osqp.optimize(P, A, q, l, u);
check_result(result);
}

{
// Define problem during initialization
autoware::common::osqp::OSQPInterface osqp(P, A, q, l, u, 1e-6);
autoware::osqp_interface::OSQPInterface osqp(P, A, q, l, u, 1e-6);
std::tuple<std::vector<double>, std::vector<double>, int, int, int> result = osqp.optimize();
check_result(result);
}
Expand All @@ -92,7 +92,7 @@ TEST(TestOsqpInterface, BasicQp)
std::vector<double> q_ini(2, 0.0);
std::vector<double> l_ini(4, 0.0);
std::vector<double> u_ini(4, 0.0);
autoware::common::osqp::OSQPInterface osqp(P_ini, A_ini, q_ini, l_ini, u_ini, 1e-6);
autoware::osqp_interface::OSQPInterface osqp(P_ini, A_ini, q_ini, l_ini, u_ini, 1e-6);
osqp.optimize();

// Redefine problem before optimization
Expand All @@ -105,7 +105,7 @@ TEST(TestOsqpInterface, BasicQp)
// Define problem during initialization with csc matrix
CSC_Matrix P_csc = calCSCMatrixTrapezoidal(P);
CSC_Matrix A_csc = calCSCMatrix(A);
autoware::common::osqp::OSQPInterface osqp(P_csc, A_csc, q, l, u, 1e-6);
autoware::osqp_interface::OSQPInterface osqp(P_csc, A_csc, q, l, u, 1e-6);
std::tuple<std::vector<double>, std::vector<double>, int, int, int> result = osqp.optimize();
check_result(result);
}
Expand All @@ -118,7 +118,7 @@ TEST(TestOsqpInterface, BasicQp)
std::vector<double> q_ini(2, 0.0);
std::vector<double> l_ini(4, 0.0);
std::vector<double> u_ini(4, 0.0);
autoware::common::osqp::OSQPInterface osqp(P_ini_csc, A_ini_csc, q_ini, l_ini, u_ini, 1e-6);
autoware::osqp_interface::OSQPInterface osqp(P_ini_csc, A_ini_csc, q_ini, l_ini, u_ini, 1e-6);
osqp.optimize();

// Redefine problem before optimization
Expand All @@ -138,7 +138,7 @@ TEST(TestOsqpInterface, BasicQp)
std::vector<double> q_ini(2, 0.0);
std::vector<double> l_ini(4, 0.0);
std::vector<double> u_ini(4, 0.0);
autoware::common::osqp::OSQPInterface osqp(P_ini_csc, A_ini_csc, q_ini, l_ini, u_ini, 1e-6);
autoware::osqp_interface::OSQPInterface osqp(P_ini_csc, A_ini_csc, q_ini, l_ini, u_ini, 1e-6);
osqp.optimize();

// Redefine problem before optimization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define AUTOWARE__MPC_LATERAL_CONTROLLER__QP_SOLVER__QP_SOLVER_OSQP_HPP_

#include "autoware/mpc_lateral_controller/qp_solver/qp_solver_interface.hpp"
#include "osqp_interface/osqp_interface.hpp"
#include "autoware/osqp_interface/osqp_interface.hpp"
#include "rclcpp/rclcpp.hpp"

namespace autoware::motion::control::mpc_lateral_controller
Expand Down Expand Up @@ -58,7 +58,7 @@ class QPSolverOSQP : public QPSolverInterface
double getObjVal() const override { return osqpsolver_.getObjVal(); }

private:
autoware::common::osqp::OSQPInterface osqpsolver_;
autoware::osqp_interface::OSQPInterface osqpsolver_;
rclcpp::Logger logger_;
};
} // namespace autoware::motion::control::mpc_lateral_controller
Expand Down
2 changes: 1 addition & 1 deletion control/autoware_mpc_lateral_controller/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<depend>autoware_control_msgs</depend>
<depend>autoware_interpolation</depend>
<depend>autoware_motion_utils</depend>
<depend>autoware_osqp_interface</depend>
<depend>autoware_planning_msgs</depend>
<depend>autoware_trajectory_follower_base</depend>
<depend>autoware_universe_utils</depend>
Expand All @@ -29,7 +30,6 @@
<depend>diagnostic_updater</depend>
<depend>eigen</depend>
<depend>geometry_msgs</depend>
<depend>osqp_interface</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>std_msgs</depend>
Expand Down
2 changes: 1 addition & 1 deletion control/autoware_trajectory_follower_base/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<depend>autoware_control_msgs</depend>
<depend>autoware_interpolation</depend>
<depend>autoware_motion_utils</depend>
<depend>autoware_osqp_interface</depend>
<depend>autoware_planning_msgs</depend>
<depend>autoware_universe_utils</depend>
<depend>autoware_vehicle_info_utils</depend>
Expand All @@ -31,7 +32,6 @@
<depend>diagnostic_updater</depend>
<depend>eigen</depend>
<depend>geometry_msgs</depend>
<depend>osqp_interface</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>std_msgs</depend>
Expand Down
Loading

0 comments on commit 3192ad6

Please sign in to comment.