Skip to content

Commit

Permalink
Avoid calling colcon twice and passing CMake args to Acados (#25)
Browse files Browse the repository at this point in the history
* download tera renderer

* download acados sources to avoid recalling colcon

* forward CMake args to Acados

* CMAKE linting

* add pip-casadi deps

* update README

* make CI happy

---------

Co-authored-by: tpoignonec <[email protected]>
  • Loading branch information
oKermorgant and tpoignonec authored Jul 4, 2024
1 parent eb322ad commit b0fb230
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 33 deletions.
90 changes: 64 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ option(BUILD_ACADOS_TEMPLATE
ON
)

# ACADOS options on External libs
option(ACADOS_WITH_QPOASES "qpOASES solver" OFF)
option(ACADOS_WITH_DAQP "DAQP solver" OFF)
option(ACADOS_WITH_HPMPC "HPMPC solver" OFF)
option(ACADOS_WITH_QORE "QORE solver" OFF)
option(ACADOS_WITH_OOQP "OOQP solver" OFF)
option(ACADOS_WITH_QPDUNES "qpDUNES solver" OFF)
option(ACADOS_WITH_OSQP "OSQP solver" OFF)

# Setup
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17) # Default to C++17
Expand All @@ -28,39 +37,71 @@ ament_vendor(acados_vendor_ros2
SATISFIED ${acados_FOUND}
VCS_URL https://github.com/acados/acados.git
VCS_VERSION v0.3.2
CMAKE_ARGS
"-DACADOS_WITH_QPOASES=${ACADOS_WITH_QPOASES};\
-DACADOS_WITH_DAQP=${ACADOS_WITH_DAQP};\
-DACADOS_WITH_HPMPC=${ACADOS_WITH_HPMPC};\
-DACADOS_WITH_QORE=${ACADOS_WITH_QORE};\
-DACADOS_WITH_OOQP=${ACADOS_WITH_OOQP};\
-DACADOS_WITH_QPDUNES=${ACADOS_WITH_QPDUNES};\
-DACADOS_WITH_OSQP=${ACADOS_WITH_OSQP}"
)
ament_export_dependencies(acados)

set(ACADOS_SOURCE_DIR ${CMAKE_INSTALL_PREFIX}/opt/acados_vendor_ros2) # lib + include
set(ACADOS_SOURCE_BUILD_DIR ${CMAKE_BINARY_DIR}/acados_vendor_ros2-prefix/src/acados_vendor_ros2) # Source files

# Source files
set(ACADOS_PYTHON_INTERFACE_PATH none) # Python package after install, set below if package built

if(${BUILD_ACADOS_TEMPLATE})
set(ACADOS_PYTHON_INTERFACE_PCK_DIR "${ACADOS_SOURCE_BUILD_DIR}/interfaces/acados_template/acados_template")
if(EXISTS "${ACADOS_PYTHON_INTERFACE_PCK_DIR}/__init__.py")
ament_python_install_package(
acados_template
PACKAGE_DIR ${ACADOS_PYTHON_INTERFACE_PCK_DIR}
)
set(ACADOS_PYTHON_INTERFACE_PATH ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_DIR}/acados_template) # Python package after install
message(
STATUS
"The Python interface (acados_template) \
found in '${ACADOS_PYTHON_INTERFACE_PCK_DIR}' will be installed in \
'${ACADOS_PYTHON_INTERFACE_PATH}'."
)

if(NOT EXISTS "${ACADOS_PYTHON_INTERFACE_PCK_DIR}")
message(STATUS "Cloning Acados source")
file(MAKE_DIRECTORY ${ACADOS_SOURCE_BUILD_DIR})
execute_process(COMMAND git clone -c advice.detachedHead=false --quiet --recursive https://github.com/acados/acados.git -b v0.3.2 .
WORKING_DIRECTORY ${ACADOS_SOURCE_BUILD_DIR}
RESULT_VARIABLE ACADOS_GIT_OUT
OUTPUT_VARIABLE ACADOS_GIT_OUT)
else()
# Force a CMAKE regeneration at next 'colcon build' call
include("${CMAKE_CURRENT_LIST_DIR}/cmake/force_regenerate.cmake")
force_regenerate_at_next_build()

message(
WARNING
"The Python interface (acados_template) could not be built \
because the external project was not yet downloaded!\n \
Please re-build the project once again.\n \
Note: if it doesn't work, please try with the cmake arg '-DBUILD_ACADOS_TEMPLATE=ON'!"
)
message(STATUS "${ACADOS_SOURCE_BUILD_DIR} already exists")
endif()

ament_python_install_package(
acados_template
PACKAGE_DIR ${ACADOS_PYTHON_INTERFACE_PCK_DIR}
)
set(ACADOS_PYTHON_INTERFACE_PATH ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_DIR}/acados_template) # Python package after install
message(
STATUS
"The Python interface (acados_template) \
found in '${ACADOS_PYTHON_INTERFACE_PCK_DIR}' will be installed in \
'${ACADOS_PYTHON_INTERFACE_PATH}'."
)

set(TERA_RENDERER "${ACADOS_SOURCE_DIR}/bin/t_renderer")
if(NOT EXISTS "${TERA_RENDERER}")
# Add empty bin directory (used to download the tera renderer)
install(DIRECTORY DESTINATION "opt/${PROJECT_NAME}/bin")
message(STATUS "Downloading tera renderer")

set(TERA_VERSION "0.0.34")
if(UNIX AND NOT APPLE)
set(TERA_SUFFIX linux)
elseif(APPLE)
set(TERA_SUFFIX osx)
else()
set(TERA_SUFFIX windows)
endif()

file(DOWNLOAD
"https://github.com/acados/tera_renderer/releases/download/v${TERA_VERSION}/t_renderer-v${TERA_VERSION}-${TERA_SUFFIX}"
${TERA_RENDERER})
file(CHMOD
${TERA_RENDERER}
PERMISSIONS
OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif()
endif()
ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/env-hooks/${PROJECT_NAME}.sh.in")
Expand Down Expand Up @@ -96,7 +137,4 @@ install(
share/${PROJECT_NAME}/cmake/Modules
)

# Add empty bin directory (used to download the tera renderer)
install(DIRECTORY DESTINATION "opt/${PROJECT_NAME}/bin")

ament_package(CONFIG_EXTRAS acados_vendor_ros2-extras.cmake)
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ git clone https://github.com/ICube-Robotics/acados_vendor_ros2.git
# Download the source and install the c interface (lib "acados")
cd ..
rosdep install --ignore-src --from-paths . -y -r
colcon build && colcon build
colcon build
```
Note that `colcon build` is called twice.

> N.B., this is necessary because `ament_vendor(...)` takes effect after the `ament_python_install_package(...)` command.
However, the later tests for the existence of an `__init__.py` file in the path, hence resulting in an error since the Python package is not yet present.

>**TODO:** Allow unique build to avoid potential downstream build tests failures.

>**NOTE:** If the `ament_cmake_vendor_package` is missing, you can install it manually:
```bash
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<buildtool_depend>ament_cmake_vendor_package</buildtool_depend>
<buildtool_depend>pkg-config</buildtool_depend>

<exec_depend>casadi-pip</exec_depend>

<buildtool_export_depend>pkg-config</buildtool_export_depend>

<test_depend>ament_cmake_copyright</test_depend>
Expand Down

0 comments on commit b0fb230

Please sign in to comment.