Squashed 'third_party/ct/' content from commit 0048d02
Change-Id: Ia7e5360cbb414f92ce4f118bd9613ea23597db52
git-subtree-dir: third_party/ct
git-subtree-split: 0048d027531b6cf1ea730da17b68a0b7ef9070b1
diff --git a/ct/CMakeLists.txt b/ct/CMakeLists.txt
new file mode 100644
index 0000000..b96f74b
--- /dev/null
+++ b/ct/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 2.6)
+project(ct)
+find_package(catkin REQUIRED)
+catkin_metapackage()
+
+#Make sure metapackage does not fail when building documentation
+add_custom_target(doc
+ COMMAND ${CMAKE_COMMAND} -E echo_append "Building CT Documentation..."
+ VERBATIM)
+
+add_custom_target(clang-format
+ COMMAND ${CMAKE_COMMAND} -E echo_append "Running clang-format on CT..."
+ VERBATIM)
+
+add_custom_target(clang-tidy
+ COMMAND ${CMAKE_COMMAND} -E echo_append "Running clang-tidy on CT..."
+ VERBATIM)
\ No newline at end of file
diff --git a/ct/cmake/clang-cxx-dev-tools.cmake b/ct/cmake/clang-cxx-dev-tools.cmake
new file mode 100644
index 0000000..0a1ed1e
--- /dev/null
+++ b/ct/cmake/clang-cxx-dev-tools.cmake
@@ -0,0 +1,115 @@
+# CLANG-TIDY AND CLANG-FORMAT
+##############################
+
+# Additional targets to perform clang-format/clang-tidy
+
+
+# function to exclude user-defined folders from the clang format- and tidy process
+function(filter_ct_directories allItems excludeDir)
+ foreach (TMP_PATH ${${allItems}})
+ if ("${TMP_PATH}" MATCHES ${excludeDir})
+ list (REMOVE_ITEM ${allItems} ${TMP_PATH})
+ endif()
+ endforeach(TMP_PATH)
+ set(${allItems} ${${allItems}} PARENT_SCOPE)
+endfunction(filter_ct_directories)
+
+function(ct_get_all_srcs ADD_HEADERS)
+
+ set(EXTENSIONS "*.cpp")
+ if (ADD_HEADERS)
+ list(APPEND EXTENSIONS "*.hpp" "*.h")
+ endif()
+
+ # Get all project files
+ file(GLOB_RECURSE
+ ALL_CXX_SOURCE_FILES
+ ${PROJECT_SOURCE_DIR}
+ ${EXTENSIONS}
+ )
+
+
+ # list "external" sources, to be excluded from the format- and tidy process:
+ filter_ct_directories(ALL_CXX_SOURCE_FILES "/external/") # excludes CppAD
+ filter_ct_directories(ALL_CXX_SOURCE_FILES ".tpl.cpp") # excludes CppAD
+ filter_ct_directories(ALL_CXX_SOURCE_FILES "/iit/rbd/") # excludes iit rbd folders
+ filter_ct_directories(ALL_CXX_SOURCE_FILES "/testIrb4600/generated/") # excludes generated code
+ filter_ct_directories(ALL_CXX_SOURCE_FILES "/testhyq/generated/") # excludes generated code
+ filter_ct_directories(ALL_CXX_SOURCE_FILES "/HyA/generated/") # excludes generated code
+ filter_ct_directories(ALL_CXX_SOURCE_FILES "/HyQ/generated/") # excludes generated code
+ filter_ct_directories(ALL_CXX_SOURCE_FILES "/QuadrotorWithLoad/generated/") # excludes generated code
+ filter_ct_directories(ALL_CXX_SOURCE_FILES "transform6d.cpp") #excludes generated inverse kinematics code
+ filter_ct_directories(ALL_CXX_SOURCE_FILES "/ikfast/ikfast.h") #excludes ik fast header
+
+ #message(FATAL_ERROR "sources list: ${ALL_CXX_SOURCE_FILES}")
+ set(ALL_CXX_SOURCE_FILES ${ALL_CXX_SOURCE_FILES} PARENT_SCOPE)
+endfunction()
+
+
+
+# Adding clang-format target if executable is found
+ct_get_all_srcs(TRUE)
+find_program(CLANG_FORMAT_BIN "clang-format")
+if(NOT CLANG_FORMAT_BIN)
+ find_program(CLANG_FORMAT_BIN "clang-format-3.9")
+endif()
+message(WARNING "CLANG FORMAT IS: " ${CLANG_FORMAT_BIN})
+if(NOT CLANG_FORMAT_BIN)
+ message (WARNING "CLANG-FORMAT not found. You can ignore this message if you are not a CT developer.")
+ add_custom_target(clang-format
+ COMMAND ${CMAKE_COMMAND} -E echo_append "clang-format executable not found"
+ VERBATIM)
+else()
+ message (WARNING "FOUND CLANG-FORMAT")
+ add_custom_target(
+ clang-format
+ COMMAND ${CLANG_FORMAT_BIN}
+ -i
+ -style=file
+ ${ALL_CXX_SOURCE_FILES}
+ VERBATIM
+ )
+endif()
+
+# Adding clang-tidy target if clang-tidy executable is found
+function(ct_configure_clang_tidy TIDY_INC_DIRS)
+
+ ct_get_all_srcs(FALSE)
+
+ set(CURRENT_INC_DIRS "")
+
+ #message(FATAL_ERROR "Inc dirs: ${${TIDY_INC_DIRS}}")
+
+ foreach (THIS_INC_DIR ${${TIDY_INC_DIRS}})
+ #message(WARNING "this inc dir: ${THIS_INC_DIR}")
+ list(APPEND CURRENT_INC_DIRS "-I${THIS_INC_DIR}")
+ endforeach()
+
+ #message(FATAL_ERROR "Current inc dirs: ${CURRENT_INC_DIRS}")
+
+ find_program(CLANG_TIDY_BIN "clang-tidy")
+ if(NOT CLANG_TIDY_BIN)
+ find_program(CLANG_TIDY_BIN "clang-tidy-3.9")
+ endif()
+ if(NOT CLANG_TIDY_BIN)
+ find_program(CLANG_TIDY_BIN "clang_tidy")
+ endif()
+ message(${CLANG_TIDY_BIN})
+ if(NOT CLANG_TIDY_BIN)
+ add_custom_target(clang-tidy
+ COMMAND ${CMAKE_COMMAND} -E echo_append "clang-tidy executable not found"
+ VERBATIM)
+ else()
+ message (WARNING "FOUND CLANG-TIDY")
+ set(CLANG_TIDY_COMMAND COMMAND ${CLANG_TIDY_BIN} ${ALL_CXX_SOURCE_FILES} -config='' -header-filter=\".*\\/ct\\/.*\" -- -std=c++11 -fopenmp ${CURRENT_INC_DIRS})
+
+ add_custom_target(
+ clang-tidy
+ COMMAND ${CLANG_TIDY_COMMAND}
+ COMMENT "Launching clang-tidy"
+ WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
+
+ )
+ endif() #CLANG_TIDY_BIN
+
+endfunction()
diff --git a/ct/cmake/compilerSettings.cmake b/ct/cmake/compilerSettings.cmake
new file mode 100644
index 0000000..083cc81
--- /dev/null
+++ b/ct/cmake/compilerSettings.cmake
@@ -0,0 +1,41 @@
+option(USE_CLANG "Use CLANG instead of gcc for faster compilation" false)
+option(USE_INTEL "Use Intel ICC compiler" false)
+option(BUILD_EXAMPLES "Compile all examples for ct" false)
+option(BUILD_HYQ_FULL "Compile all examples for HyQ (takes long, should use clang)" false)
+option(BUILD_HYQ_LINEARIZATION_TIMINGS "Build linearization timing tests for HyQ (takes long, should use clang)" false)
+option(BUILD_HYA_LINEARIZATION_TIMINGS "Build linearization timing tests for HyA (takes long, should use clang)" false)
+option(USE_LAPACKE "Use lapacke bindings for Eigen" false)
+option(USE_BLAS "Use blas bindings for Eigen" false)
+option(HPIPM "Build HPIPM Optimal Control solver" false)
+
+if (USE_CLANG AND USE_INTEL)
+ message (FATAL_ERROR "Please choose either intel or clang compiler or neither.")
+endif()
+
+set(CLANG_C_COMPILER "/usr/bin/clang-3.5" CACHE STRING "Path to Clang C compiler binary")
+set(CLANG_CXX_COMPILER "/usr/bin/clang++-3.5" CACHE STRING "Path to Clang C++ compiler binary")
+set(INTEL_C_COMPILER "/opt/intel/bin/icc" CACHE STRING "Path to Intel C compiler binary")
+set(INTEL_CXX_COMPILER "/opt/intel/bin/icpc" CACHE STRING "Path to Intel C++ compiler binary")
+
+if(USE_CLANG)
+ message (WARNING "USING CLANG with bin ${CLANG_C_COMPILER} and ${CLANG_CXX_COMPILER}. This will make compilation faster but execution could be slower.")
+ SET (CMAKE_C_COMPILER ${CLANG_C_COMPILER})
+ SET (CMAKE_CXX_COMPILER ${CLANG_CXX_COMPILER})
+endif(USE_CLANG)
+
+if(USE_INTEL)
+ message (WARNING "USING INTEL compiler with bin ${CLANG_C_COMPILER} and ${CLANG_CXX_COMPILER}.")
+ SET (CMAKE_C_COMPILER ${INTEL_C_COMPILER})
+ SET (CMAKE_CXX_COMPILER ${INTEL_CXX_COMPILER})
+ set(CMAKE_CXX_LINKER_FLAGS "${CMAKE_CXX_LINKER_FLAGS} -L${MKLROOT}/lib/intel64 -llibblas -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -llapacke -lblas -llapack -lliblapack -liblapacke")
+endif(USE_INTEL)
+
+
+if(USE_LAPACKE)
+ add_definitions(-DEIGEN_USE_LAPACKE)
+ set(CMAKE_CXX_LINKER_FLAGS "${CMAKE_CXX_LINKER_FLAGS} -llapacke -lblas ")
+endif()
+
+if(USE_BLAS)
+ add_definitions(-DEIGEN_USE_BLAS)
+endif()
\ No newline at end of file
diff --git a/ct/cmake/explicitTemplateHelpers.cmake b/ct/cmake/explicitTemplateHelpers.cmake
new file mode 100644
index 0000000..589b20e
--- /dev/null
+++ b/ct/cmake/explicitTemplateHelpers.cmake
@@ -0,0 +1,125 @@
+# reads the templates from file
+function(ct_getDimensionsFromLine LineContent)
+ string(REGEX REPLACE "," ";" LineContent ${LineContent})
+
+ foreach(NameAndValue ${LineContent})
+ # Strip leading spaces
+ string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
+ # Find variable name
+ string(REGEX MATCH "^[^=]+" Name ${NameAndValue})
+ # Find the value
+ string(REPLACE "${Name}=" "" Value ${NameAndValue})
+
+ # Set the variable
+ if(Name STREQUAL "STATE_DIM")
+ set(STATE_DIM_PRESPEC "${Value}" PARENT_SCOPE)
+ endif()
+
+ # Set the variable
+ if(Name STREQUAL "CONTROL_DIM")
+ set(CONTROL_DIM_PRESPEC "${Value}" PARENT_SCOPE)
+ endif()
+
+ if(Name STREQUAL "SCALAR")
+ set(SCALAR_PRESPEC "${Value}" PARENT_SCOPE)
+ endif()
+
+ if(Name STREQUAL "POS_DIM")
+ set(POS_DIM_PRESPEC "${Value}" PARENT_SCOPE)
+ endif()
+
+ if(Name STREQUAL "VEL_DIM")
+ set(VEL_DIM_PRESPEC "${Value}" PARENT_SCOPE)
+ endif()
+ endforeach()
+
+endfunction()
+
+
+# reads explicit templates from config file and gathers sources and libs
+function(ct_configure_explicit_templates ConfigFile ConfigDir LibPrefix)
+
+ FILE(READ "${ConfigFile}" contents)
+
+ STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
+ STRING(REGEX REPLACE "\n" ";" contents "${contents}")
+
+ #message(WARNING "file content: ${contents}")
+
+ foreach(line ${contents})
+ #message(WARNING "extracting variables from line: ${line}")
+ set(STATE_DIM_PRESPEC "")
+ set(CONTROL_DIM_PRESPEC "")
+ set(SCALAR_PRESPEC "")
+ set(POS_DIM_PRESPEC "0")
+ set(VEL_DIM_PRESPEC "0")
+ set(CURRENT_SRCS "")
+
+ ct_getDimensionsFromLine(${line})
+
+ #message(WARNING "extracted: STATE_DIM=${STATE_DIM_PRESPEC}, CONTROL_DIM=${STATE_DIM_PRESPEC}, SCALAR=${SCALAR_PRESPEC}")
+
+ string(REGEX REPLACE "[^0-9a-zA-Z]+" "" SCALAR_PRESPEC_CLEAN ${SCALAR_PRESPEC})
+ set(CURRENT_LIB_NAME "${LibPrefix}-${STATE_DIM_PRESPEC}-${CONTROL_DIM_PRESPEC}-${SCALAR_PRESPEC_CLEAN}-${POS_DIM_PRESPEC}-${VEL_DIM_PRESPEC}")
+
+ if(STATE_DIM_PRESPEC AND CONTROL_DIM_PRESPEC AND SCALAR_PRESPEC)
+ #message(WARNING "Will configure now")
+ ct_configureFiles(${ConfigDir} ${STATE_DIM_PRESPEC}, ${CONTROL_DIM_PRESPEC}, ${SCALAR_PRESPEC} ${POS_DIM_PRESPEC} ${VEL_DIM_PRESPEC})
+ elseif()
+ #message(WARNING "Nothing to configure")
+ endif()
+
+ if(CURRENT_SRCS)
+ set(${CURRENT_LIB_NAME}_SRCS ${CURRENT_SRCS} PARENT_SCOPE)
+ list(APPEND LIB_NAMES "${CURRENT_LIB_NAME}")
+ endif()
+ endforeach()
+
+ set(PRESPEC_LIB_NAMES ${LIB_NAMES} PARENT_SCOPE)
+
+endfunction()
+
+
+# finds cpp.in files and configures them
+function(ct_configureFiles ConfigDir STATE_DIM_PRESPEC, CONTROL_DIM_PRESPEC, SCALAR_PRESPEC, POS_DIM_PREPSEC, VEL_DIM_PRESPEC)
+ set(CURRENT_SRCS "")
+ file(GLOB_RECURSE files "${ConfigDir}*.in")
+ #message(WARNING "files to configure in directory ${ConfigDir}:\n ${files}")
+ foreach(file ${files})
+ string(REGEX REPLACE "[^0-9a-zA-Z]+" "" SCALAR_PRESPEC_CLEAN ${SCALAR_PRESPEC})
+ string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" outputFile ${file})
+ string(REPLACE ".cpp.in" "" outputFile ${outputFile})
+ set(outputFile "${outputFile}-${STATE_DIM_PRESPEC}-${CONTROL_DIM_PRESPEC}-${SCALAR_PRESPEC_CLEAN}-${POS_DIM_PRESPEC}-${VEL_DIM_PRESPEC}.cpp")
+ #message(WARNING "configuring file \n ${file} to \n ${outputFile} ")
+ set(DOUBLE_OR_FLOAT false)
+ if(SCALAR_PRESPEC STREQUAL "double" OR SCALAR_PRESPEC STREQUAL "float")
+ set(DOUBLE_OR_FLOAT true)
+ endif()
+ configure_file(${file} ${outputFile})
+ list(APPEND CURRENT_SRCS ${outputFile})
+ endforeach()
+
+ #(WARNING "CURRENT_SRCS: ${CURRENT_SRCS}")
+ set(CURRENT_SRCS "${CURRENT_SRCS}" PARENT_SCOPE)
+endfunction()
+
+
+# creates a target for each explicit template lib and adds its sources to it
+function(ct_add_explicit_template_libs)
+ foreach(lib_name ${PRESPEC_LIB_NAMES})
+ #get_filename_component(raw_filename ${file} NAME_WE)
+ #message(WARNING "sources for lib ${lib_name}: \n ${${lib_name}_SRCS}")
+ add_library(${lib_name}
+ ${${lib_name}_SRCS}
+ )
+ target_link_libraries(${lib_name} ${catkin_LIBRARIES} ${PYTHON_LIBRARY})
+ endforeach()
+endfunction()
+
+
+# link external library (for example to link optcon against lapack)
+function(ct_link_external_library extLibs)
+foreach(lib_name ${PRESPEC_LIB_NAMES})
+ target_link_libraries(${lib_name} "${extLibs}")
+ endforeach()
+endfunction()
\ No newline at end of file
diff --git a/ct/config/explicit_templates.cfg b/ct/config/explicit_templates.cfg
new file mode 100644
index 0000000..2cc8f25
--- /dev/null
+++ b/ct/config/explicit_templates.cfg
@@ -0,0 +1,4 @@
+STATE_DIM=2, CONTROL_DIM=1, POS_DIM=1, VEL_DIM=1, SCALAR=double
+STATE_DIM=12, CONTROL_DIM=4, POS_DIM=6, VEL_DIM=6, SCALAR=double
+STATE_DIM=12, CONTROL_DIM=6, POS_DIM=6, VEL_DIM=6, SCALAR=double
+#STATE_DIM=2, CONTROL_DIM=2, POS_DIM=1, VEL_DIM=1, SCALAR=ct::core::ADScalar
diff --git a/ct/package.xml b/ct/package.xml
new file mode 100644
index 0000000..7356131
--- /dev/null
+++ b/ct/package.xml
@@ -0,0 +1,16 @@
+<package>
+ <name>ct</name>
+ <version>0.2.1</version>
+ <description>
+ ADRL Control Toolbox v2.1
+ </description>
+ <maintainer email="mgiftthaler@ethz.ch">Markus Giftthaler</maintainer>
+ <maintainer email="neunertm@gmail.com">Michael Neunert</maintainer>
+ <license>Apache v2</license>
+
+ <buildtool_depend>catkin</buildtool_depend>
+
+ <export>
+ <metapackage />
+ </export>
+</package>
\ No newline at end of file