目录
注意事项
- 此教程针对ubuntu+ros+catkin用户
基础环境
- ubuntu 18.04
- ros melodic
依赖
- clang
sudo apt-get update
sudo apt-get install clang
- clang-format
sudo apt-get install clang-format
- Doxygen
sudo apt-get install doxygen
- Eigen 3
sudo apt-get install libeigen3-dev
- boost
sudo apt-get install libboost-all-dev
- Ipopt & Snopt
sudo apt-get install ros-melodic-ifopt
- cppad
git clone https://github.com/coin-or/CppAD.git cppad.git
cd cppad.git
mkdir build
cd build
cmake ..
make -j8
sudo make install
- cppadcogen
git clone https://github.com/joaoleal/CppADCodeGen.git CppADCodeGen
mkdir cppadcg-build
cd cppadcg-build
cmake ../CppADCodeGen
sudo make install
- blasfeo
git clone https://github.com/giaf/blasfeo.git
cd blasfeo
将blasfeo根目录下的CMakeLists.txt
修改为如下形式,以生成动态库
# build shared library
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
mkdir build
cd build
cmake …
make
sudo make install
sudo sh -c "echo '/opt/blasfeo/lib/' >> /etc/ld.so.conf"
sudo ldconfig
- hpipm
git clone https://github.com/giaf/hpipm.git
cd hpipm
将hpipm根目录下的CMakeLists.txt
修改为如下形式,以生成动态库
# build shared library
set(BUILD_SHARED_LIBS ON CACHE STRING "Build shared libraries")
mkdir build
cd build
cmake …
make
sudo make install
sudo sh -c "echo '/opt/hpipm/lib/' >> /etc/ld.so.conf"
sudo ldconfig
安装
拉取代码
cd ~/your_catkin_workspace/src
git clone https://github.com/ANYbotics/kindr.git
git clone https://github.com/ethz-adrl/control-toolbox.git
git clone https://github.com/ethz-adrl/ct_ros.git
代码调整
control-toolbox
- 按照如下代码调整
to-your-control-toolbox/ct_models/CMakeLists.txt
if(NOT TARGET ${ct_rbd})
find_package(ct_rbd REQUIRED)
endif()
find_package(Boost REQUIRED system filesystem)
find_package(blasfeo QUIET)
find_package(hpipm QUIET)
# extract interface compile definitions from previous ct packages as options
importInterfaceCompileDefinitionsAsOptions(ct_core)
importInterfaceCompileDefinitionsAsOptions(ct_optcon)
importInterfaceCompileDefinitionsAsOptions(ct_rbd)
- 按照如下代码调整
to-your-control-toolbox/ct_optcon/CMakeLists.txt
if(blasfeo_FOUND AND hpipm_FOUND)
message(STATUS "Found HPIPM and BLASFEO")
set(HPIPM ON)
list(APPEND HPIPM_LIBS hpipm blasfeo)
list(APPEND ct_optcon_COMPILE_DEFINITIONS HPIPM)
list(APPEND blasfeo_INCLUDE_DIRS /opt/blasfeo/include)
list(APPEND hpipm_INCLUDE_DIRS /opt/hpipm/include)
else()
message(WARNING "Could not find HPIPM or BLASFEO")
endif()
- 按照如下代码调整
to-your-control-toolbox/ct_rbd/include/ct/rbd/systems/FixBaseFDSystem.h
const ct::core::ControlVector<BASE::NJOINTS> torqueRef = this->computeIDTorques(jStateRef);
ct_ros
若仅需要control-toolbox则可以不执行本小节内容
- 按照如下代码调整
to-your-ct_ros/ct_ros_nodes/CMakeLists.txt
开启hyq示例程序编译
option(BUILD_HYQ_FULL "Compile all examples for HyQ (takes long, should use clang)" on)
加载blasfeo和hpipm库
# after SET(CMAKE_CXX_FLAGS ...)
find_package(blasfeo)
find_package(hpipm)
开启倒立摆示例程序编译
add_executable(InvertedPendulumNLOC examples/InvertedPendulum/InvertedPendulumNLOC.cpp)
target_link_libraries(InvertedPendulumNLOC ${catkin_LIBRARIES} ct_models)
add_executable(InvertedPendulumNLOC_actDyn examples/InvertedPendulum/InvertedPendulumNLOC_actDyn.cpp)
target_link_libraries(InvertedPendulumNLOC_actDyn ${catkin_LIBRARIES} ct_models)
开启HyANLOC_ObstacleAcc示例程序编译
option(CPPADCG "Compile HyANLOC_ObstacleAcc example" on)
if(CPPADCG)
add_executable(HyANLOC_ObstacleAcc examples/HyA/HyANLOC_ObstacleAcc.cpp)
target_link_libraries(HyANLOC_ObstacleAcc ${catkin_LIBRARIES} ct_ros_visualization ct_models)
endif()
编译
cd ~/your_catkin_workspace
catkin build -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=true
上述编译步骤耗时约15min(i5-10210U+16G RAM)
示例运行
control-toolbox
ex_NLOC_boxConstrained
cd ~/your_catkin_workspace
source ~/.bashrc
source devel/setup.bash
rosrun ct_optcon ex_NLOC_boxConstrained
结果
ct_ros
hya_nloc_example
cd ~/your_catkin_workspace
source ~/.bashrc
source devel/setup.bash
roslaunch ct_ros_nodes hya_nloc_example.launch
结果
invertedPendulum_actDyn
cd ~/your_catkin_workspace
source ~/.bashrc
source devel/setup.bash
roslaunch ct_ros_nodes invertedPendulum_actDyn.launch
结果