Skip to content

Commit

Permalink
Fix #12 (#15)
Browse files Browse the repository at this point in the history
- update Travis script (now is compatible with ubuntu xenial and bionic)
- fix MPCExample.cpp
  • Loading branch information
GiulioRomualdi authored Nov 12, 2018
1 parent 9dd71e6 commit dcbefc7
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 129 deletions.
10 changes: 10 additions & 0 deletions .ci/install_debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
set -e

apt-get update

# noninteractive tzdata ( https://stackoverflow.com/questions/44331836/apt-get-install-tzdata-noninteractive )
export DEBIAN_FRONTEND=noninteractive

# CI specific packages
apt-get install -y clang wget unzip build-essential cmake libeigen3-dev git
7 changes: 7 additions & 0 deletions .ci/install_debian_and_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e

DIR=$(dirname "$(readlink -f "$0")")

sh $DIR/install_debian.sh
sh $DIR/script.sh
36 changes: 36 additions & 0 deletions .ci/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
set -e

# google test
wget https://github.com/google/googletest/archive/release-1.8.0.zip
unzip release-1.8.0.zip
cd googletest-release-1.8.0
mkdir build
cd build
cmake -G"${TRAVIS_CMAKE_GENERATOR}" -DBUILD_GTEST=ON -DBUILD_SHARED_LIBS=ON ..
cmake --build . --config ${TRAVIS_BUILD_TYPE} --target install
cd ../..

# osqp
git clone --recursive https://github.com/oxfordcontrol/osqp.git
cd osqp
mkdir build
cd build
cmake -G"${TRAVIS_CMAKE_GENERATOR}" -DCMAKE_BUILD_TYPE=${TRAVIS_BUILD_TYPE} -DUNITTESTS=OFF ..
cmake --build . --config ${TRAVIS_BUILD_TYPE} --target install
cd ../..

# Build, test and install osqp-eigen
cd $TRAVIS_BUILD_DIR
mkdir build
cd build
cmake -G"${TRAVIS_CMAKE_GENERATOR}" -DCMAKE_BUILD_TYPE=${TRAVIS_BUILD_TYPE} -DBUILD_TESTING=ON ..
cmake --build . --config ${TRAVIS_BUILD_TYPE} --target install
ctest --output-on-failure --build-config ${TRAVIS_BUILD_TYPE}

# Build osqp-eigen example
cd ../example
mkdir build
cd build
cmake -G"${TRAVIS_CMAKE_GENERATOR}" -DCMAKE_BUILD_TYPE=${TRAVIS_BUILD_TYPE} ..
cmake --build . --config ${TRAVIS_BUILD_TYPE}
193 changes: 81 additions & 112 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,126 +1,95 @@
sudo: required
dist: trusty
language: cpp
services: docker

matrix:
include:

# Linux C++14 GCC builds
- os: linux
compiler: gcc
addons: &gcc6
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6']
env: COMPILER='g++-6' BUILD_TYPE='Release'

- os: linux
compiler: gcc
addons: *gcc6
env: COMPILER='g++-6' BUILD_TYPE='Debug'

# Linux C++14 Clang builds
- os: linux
compiler: clang
addons: &clang39
apt:
sources: ['llvm-toolchain-precise-3.9', 'ubuntu-toolchain-r-test']
packages: ['clang-3.9', 'g++-6']
env: COMPILER='clang++-3.9' BUILD_TYPE='Release'

- os: linux
compiler: clang
addons: *clang39
env: COMPILER='clang++-3.9' BUILD_TYPE='Debug'

# OSX C++14 Clang Build
- os: osx
osx_image: xcode8.3
compiler: clang
env: COMPILER='clang++' BUILD_TYPE='Debug'
os: linux

- os: osx
osx_image: xcode8.3
compiler: clang
env: COMPILER='clang++' BUILD_TYPE='Release'

install:
- export CXX=${COMPILER}
cache:
directories:
- $HOME/.ccache
- $HOME/Library/Caches/Homebrew

- ${CXX} --version
stages:
- test # Default stage with job matrix
- osx

# Dependencies required by the CI are installed in ${TRAVIS_BUILD_DIR}/deps/
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
- mkdir -p "${DEPS_DIR}"
- cd "${DEPS_DIR}"
compiler:
- gcc

# Travis machines have 2 cores
- JOBS=2
env:
global:
- TRAVIS_CMAKE_GENERATOR="Unix Makefiles"
matrix:
- TRAVIS_BUILD_TYPE="Release" UBUNTU="xenial"
- TRAVIS_BUILD_TYPE="Debug" UBUNTU="xenial"
- TRAVIS_BUILD_TYPE="Release" UBUNTU="bionic"
- TRAVIS_BUILD_TYPE="Debug" UBUNTU="bionic"

- |
LLVM_INSTALL=${DEPS_DIR}/llvm/install
# if in linux and compiler clang and llvm not installed
if [[ "${TRAVIS_OS_NAME}" == "linux" && "${CXX%%+*}" == "clang" && -n "$(ls -A ${LLVM_INSTALL})" ]]; then
if [[ "${CXX}" == "clang++-3.6" ]]; then LLVM_VERSION="3.6.2";
elif [[ "${CXX}" == "clang++-3.7" ]]; then LLVM_VERSION="3.7.1";
elif [[ "${CXX}" == "clang++-3.8" ]]; then LLVM_VERSION="3.8.1";
elif [[ "${CXX}" == "clang++-3.9" ]]; then LLVM_VERSION="3.9.1";
fi
LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz"
LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz"
LIBCXXABI_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxxabi-${LLVM_VERSION}.src.tar.xz"
mkdir -p llvm llvm/build llvm/projects/libcxx llvm/projects/libcxxabi
travis_retry wget -O - ${LLVM_URL} | tar --strip-components=1 -xJ -C llvm
travis_retry wget -O - ${LIBCXX_URL} | tar --strip-components=1 -xJ -C llvm/projects/libcxx
travis_retry wget -O - ${LIBCXXABI_URL} | tar --strip-components=1 -xJ -C llvm/projects/libcxxabi
(cd llvm/build && cmake .. -DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL})
(cd llvm/build/projects/libcxx && make install -j2)
(cd llvm/build/projects/libcxxabi && make install -j2)
export CXXFLAGS="-isystem ${LLVM_INSTALL}/include/c++/v1"
export LDFLAGS="-L ${LLVM_INSTALL}/lib -l c++ -l c++abi"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${LLVM_INSTALL}/lib"
fi
# ===================
# STAGE: test (linux)
# ===================

before_script:

- mkdir ~/robot-code
- mkdir ~/robot-install

- export ROBOT_CODE=~/robot-code
- export ROBOT_INSTALL=~/robot-install

- cd $ROBOT_CODE
- wget https://github.com/google/googletest/archive/release-1.8.0.zip
- unzip release-1.8.0.zip
- cd googletest-release-1.8.0
- mkdir build
- cd build
- cmake ../ -DBUILD_GTEST=ON -DBUILD_SHARED_LIBS=ON
- sudo make install

- cd $ROBOT_CODE
- git clone https://github.com/eigenteam/eigen-git-mirror.git
- cd eigen-git-mirror
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ../
- sudo make install

- cd $ROBOT_CODE
- git clone --recursive https://github.com/oxfordcontrol/osqp.git
- cd osqp
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=$ROBOT_INSTALL -DUNITTESTS=OFF ../
- make install
- export osqp_DIR=$ROBOT_INSTALL
- docker pull ubuntu:$UBUNTU

script:
- cd $TRAVIS_BUILD_DIR
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DBUILD_TESTING=ON ../
- make
- make test
- >-
docker run -it \
-v $TRAVIS_BUILD_DIR:$TRAVIS_BUILD_DIR \
-v $HOME/.ccache:$HOME/.ccache \
-w $TRAVIS_BUILD_DIR \
--env CC \
--env CXX \
--env TRAVIS_BUILD_DIR \
--env TRAVIS_BUILD_TYPE \
--env TRAVIS_CMAKE_GENERATOR \
ubuntu:$UBUNTU \
sh .ci/install_debian_and_script.sh
# ==========
# STAGE: osx
# ==========

stage_osx:
install: &osx_install
# Setup ccache
- brew update
- brew install ccache
- export PATH="/usr/local/opt/ccache/libexec:$PATH"
# Install dependencies
- brew install eigen pkg-config
script: &osx_script
- cd $TRAVIS_BUILD_DIR/.ci
- sh ./script.sh

# ======================
# BUILD JOBS FROM STAGES
# ======================

jobs:
include:
# ---------
# STAGE OSX
# ---------
- &osx_template
stage: osx
os: osx
osx_image: xcode9.4
before_install: skip
install: *osx_install
before_script: skip
script: *osx_script
after_failure: skip
after_success: skip
after_script: skip
env:
TRAVIS_CMAKE_GENERATOR="Xcode"
TRAVIS_BUILD_TYPE="Debug"
- <<: *osx_template
compiler: clang
env:
TRAVIS_CMAKE_GENERATOR="Unix Makefiles"
TRAVIS_BUILD_TYPE="Debug"

notifications:
email: false
6 changes: 3 additions & 3 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ cmake_minimum_required(VERSION 3.1)

set (CMAKE_CXX_STANDARD 11)

project(OSQPWrapper-Example)
project(OsqpEigen-Example)

find_package(OSQPWrapper)
find_package(OsqpEigen)

include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})

#MPCExample
add_executable(MPCExample src/MPCExample.cpp)
target_link_libraries(MPCExample OSQPWrapper::OSQPWrapper osqp::osqp)
target_link_libraries(MPCExample OsqpEigen::OsqpEigen osqp::osqp)
28 changes: 14 additions & 14 deletions example/src/MPCExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ void setInequalityConstraints(Eigen::Matrix<double, 12, 1> &xMax, Eigen::Matrix<
13 - u0;

// state inequality constraints
xMin << -M_PI/6,-M_PI/6,-OSQPWrapper::INFINTY,-OSQPWrapper::INFINTY,-OSQPWrapper::INFINTY,-1.,
-OSQPWrapper::INFINTY, -OSQPWrapper::INFINTY,-OSQPWrapper::INFINTY,-OSQPWrapper::INFINTY,
-OSQPWrapper::INFINTY,-OSQPWrapper::INFINTY;
xMin << -M_PI/6,-M_PI/6,-OsqpEigen::INFTY,-OsqpEigen::INFTY,-OsqpEigen::INFTY,-1.,
-OsqpEigen::INFTY, -OsqpEigen::INFTY,-OsqpEigen::INFTY,-OsqpEigen::INFTY,
-OsqpEigen::INFTY,-OsqpEigen::INFTY;

xMax << M_PI/6,M_PI/6, OSQPWrapper::INFINTY,OSQPWrapper::INFINTY,OSQPWrapper::INFINTY,
OSQPWrapper::INFINTY, OSQPWrapper::INFINTY,OSQPWrapper::INFINTY,OSQPWrapper::INFINTY,
OSQPWrapper::INFINTY,OSQPWrapper::INFINTY,OSQPWrapper::INFINTY;
xMax << M_PI/6,M_PI/6, OsqpEigen::INFTY,OsqpEigen::INFTY,OsqpEigen::INFTY,
OsqpEigen::INFTY, OsqpEigen::INFTY,OsqpEigen::INFTY,OsqpEigen::INFTY,
OsqpEigen::INFTY,OsqpEigen::INFTY,OsqpEigen::INFTY;
}

void setWeightMatrices(Eigen::DiagonalMatrix<double, 12> &Q, Eigen::DiagonalMatrix<double, 4> &R)
Expand Down Expand Up @@ -248,20 +248,20 @@ int main()
castMPCToQPConstraintVectors(xMax, xMin, uMax, uMin, x0, mpcWindow, lowerBound, upperBound);

// instantiate the solver
OSQPWrapper::OptimizatorSolver solver;
OsqpEigen::Solver solver;

// settings
//solver.settings()->setVerbosity(false);
solver.settings()->setWarmStart(true);

// set the initial data of the QP solver
solver.initData()->setNumberOfVariables(12 * (mpcWindow + 1) + 4 * mpcWindow);
solver.initData()->setNumberOfConstraints(2 * 12 * (mpcWindow + 1) + 4 * mpcWindow);
if(!solver.initData()->setHessianMatrix(hessian)) return 1;
if(!solver.initData()->setGradient(gradient)) return 1;
if(!solver.initData()->setLinearConstraintsMatrix(linearMatrix)) return 1;
if(!solver.initData()->setLowerBound(lowerBound)) return 1;
if(!solver.initData()->setUpperBound(upperBound)) return 1;
solver.data()->setNumberOfVariables(12 * (mpcWindow + 1) + 4 * mpcWindow);
solver.data()->setNumberOfConstraints(2 * 12 * (mpcWindow + 1) + 4 * mpcWindow);
if(!solver.data()->setHessianMatrix(hessian)) return 1;
if(!solver.data()->setGradient(gradient)) return 1;
if(!solver.data()->setLinearConstraintsMatrix(linearMatrix)) return 1;
if(!solver.data()->setLowerBound(lowerBound)) return 1;
if(!solver.data()->setUpperBound(upperBound)) return 1;

// instantiate the solver
if(!solver.initSolver()) return 1;
Expand Down

0 comments on commit dcbefc7

Please sign in to comment.