diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 00000000..ac4a67c9 --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,9 @@ +{ + "extends": [ + "config:base", + "schedule:yearly" + ], + "labels": [ + "dependencies" + ] +} diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6bfe07ed..3ec7f355 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,56 +3,62 @@ on: push: branches: - master - - windows-github-actions pull_request: jobs: build-linux: runs-on: ${{ matrix.os }} + continue-on-error: true strategy: + fail-fast: false matrix: - os: [ ubuntu-18.04, ubuntu-20.04 ] + os: [ ubuntu-20.04, ubuntu-22.04 ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: "Update dependencies" run: sudo apt-get update - name: "Install dependencies" - run: sudo apt-get install -y build-essential cmake pkg-config qt5-default libqt5opengl5-dev libgl1-mesa-dev libglu1-mesa-dev libprotobuf-dev protobuf-compiler libode-dev libboost-dev + run: sudo apt-get install -y build-essential cmake pkg-config qtbase5-dev libqt5opengl5-dev libgl1-mesa-dev libglu1-mesa-dev libprotobuf-dev protobuf-compiler libode-dev libboost-dev - name: "Build" - run: mkdir build && cd build && cmake .. && make + run: make build-macos: runs-on: ${{ matrix.os }} + continue-on-error: true strategy: + fail-fast: false matrix: - os: [ macos-10.15, macos-11 ] + os: [ macos-12, macos-13 ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: "Install dependencies" - run: brew tap robotology/formulae && brew install qt5 protobuf robotology/formulae/ode + run: brew tap robotology/formulae && brew install cmake pkg-config qt@5 - name: "Build" - run: mkdir build && cd build && cmake .. && make - env: - Qt5_DIR: /usr/local/opt/qt5/lib/cmake/Qt5 + # for some reason qt5 is not correctly in the path and this will break whenever the location of it changes + # 5.15.11 is for macos-12 and 5.15.12 is for macos-13 + run: PATH=/usr/local/Cellar/qt@5/5.15.11/lib/cmake/Qt5:/usr/local/Cellar/qt@5/5.15.12/lib/cmake/Qt5:$PATH && make - build-windows: - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - - name: make build directory - run: mkdir '${{ github.workspace }}/build/' - - - name: Install dependencies # saves / restores cache to avoid rebuilding dependencies - uses: lukka/run-vcpkg@v6 - with: - setupOnly: false - vcpkgGitCommitId: 94ce0dab56f4d8ba6bd631ba59ed682b02d45c46 - vcpkgDirectory: c:/vcpkg # folder must reside in c:\ otherwise qt wont install due to long path errors - vcpkgTriplet: x64-windows - vcpkgArguments: qt5 ode protobuf - - - name: Run CMake and build - working-directory: ${{ github.workspace }}/build/ - run: | - cmake -DCMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake .. - cmake --build . --config Release +# Windows build does not work currently, see https://github.com/RoboCup-SSL/grSim/issues/183 +# build-windows: +# runs-on: windows-latest +# steps: +# - uses: actions/checkout@v4 +# +# - name: Install dependencies # saves / restores cache to avoid rebuilding dependencies +# uses: lukka/run-vcpkg@v11 +# with: +# vcpkgGitCommitId: 8eb57355a4ffb410a2e94c07b4dca2dffbee8e50 +# vcpkgDirectory: c:/vcpkg # folder must reside in c:\ otherwise qt wont install due to long path errors +# +# - name: Run CMake and run vcpkg to build packages +# uses: lukka/run-cmake@v10 +# with: +# # this preset is needed to actually install the vcpkg dependencies +# configurePreset: "ninja-multi-vcpkg" +# configPresetAdditionalArgs: "[-DVCPKG_TARGET_TRIPLET=x64-windows]" +# buildPreset: "ninja-multi-vcpkg" +# buildPresetAdditionalArgs: "['--config Release']" +# env: +# # [OPTIONAL] Define the vcpkg's triplet you want to enforce, otherwise the default one +# # for the hosting system will be automatically choosen (x64 is the default on all +# # platforms, e.g. `x64-osx`). +# VCPKG_DEFAULT_TRIPLET: "x64-windows" diff --git a/.gitignore b/.gitignore index c57bddde..2f15451b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ bin*/* *.swp Thumbs.db .idea/* +*.iml cmake-build-debug cmake-build-release diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7c6d1534..00000000 --- a/.travis.yml +++ /dev/null @@ -1,51 +0,0 @@ -language: cpp - - -jobs: - include: - - os: linux - dist: bionic - compiler: clang - - os: linux - dist: bionic - compiler: gcc - - os: linux - dist: focal - compiler: clang - - os: linux - dist: focal - compiler: gcc - - os: osx - osx_image: xcode11.3 - compiler: clang - - os: osx - osx_image: xcode11.3 - compiler: gcc - - -addons: - apt: - packages: - - cmake - - qt5-default - - libqt5opengl5-dev - - libgl1-mesa-dev - - libglu1-mesa-dev - - libprotobuf-dev - - protobuf-compiler - - libode-dev - - libboost-dev - homebrew: - taps: robotology/formulae - packages: - - qt5 - - protobuf - - robotology/formulae/ode - -script: - # grsim - - cd $TRAVIS_BUILD_DIR - - mkdir build && cd build - - cmake .. - - make - - sudo make install diff --git a/CMakeLists.txt b/CMakeLists.txt index 833c5cce..f9ffc9e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,19 @@ include(${PROJECT_SOURCE_DIR}/cmake/Utils.cmake) standard_config() standard_paths(${PROJECT_SOURCE_DIR} bin lib) +# policy regarding how to handle generated stuff, OLD behavior would ignore generated files +# (which includes the generated protobuf cpp files) +if (POLICY CMP0071) + cmake_policy(SET CMP0071 NEW) +endif() + +# policy regarding when to rebuild stuff when external projects downloaded with URL changes +if (POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif() + +include(GNUInstallDirs) + set(app ${CMAKE_PROJECT_NAME}) # create the target before the sources list is known so that we can call # add_dependencies( external_proj) @@ -69,12 +82,25 @@ find_package(Qt5 COMPONENTS Core Widgets OpenGL Network REQUIRED) list(APPEND libs Qt5::Core Qt5::Widgets Qt5::OpenGL Qt5::Network) # ODE -if(WIN32) - find_package(ODE CONFIG REQUIRED) - list(APPEND libs ODE::ODE) +if(BUILD_ODE) + include(BuildODE) + add_dependencies(${app} ode_external) else() - find_package(ODE REQUIRED) - list(APPEND libs ode::ode) + if(WIN32) + find_package(ODE CONFIG) + set(ODE_LIB_NAME ODE::ODE) + else() + find_package(ODE) + set(ODE_LIB_NAME ode::ode) + endif() + + if(ODE_FOUND) + list(APPEND libs ${ODE_LIB_NAME}) + else() + # if ODE could not be found just build it + include(BuildODE) + add_dependencies(${app} ode_external) + endif() endif() # VarTypes @@ -82,7 +108,6 @@ find_package(VarTypes) if(NOT VARTYPES_FOUND) include(ExternalProject) - set(VARTYPES_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/vartypes_install") set(VARTYPES_CMAKE_ARGS "-DVARTYPES_BUILD_STATIC=ON;-DCMAKE_INSTALL_PREFIX=") if(NOT "${CMAKE_TOOLCHAIN_FILE}" STREQUAL "") @@ -92,23 +117,39 @@ if(NOT VARTYPES_FOUND) ExternalProject_Add(vartypes_external GIT_REPOSITORY https://github.com/jpfeltracco/vartypes GIT_TAG origin/jpfeltracco/build_static - INSTALL_DIR "${VARTYPES_INSTALL_DIR}" CMAKE_ARGS "${VARTYPES_CMAKE_ARGS}" + STEP_TARGETS install ) + set(VARTYPES_LIB_SUBPATH "${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}vartypes${CMAKE_STATIC_LIBRARY_SUFFIX}") + + # the byproducts are available after the install step + ExternalProject_Add_Step(vartypes_external out + DEPENDEES install + BYPRODUCTS + "/${VARTYPES_LIB_SUBPATH}" + ) + + add_dependencies(${app} vartypes_external) + + ExternalProject_Get_Property(vartypes_external install_dir) add_dependencies(${app} vartypes_external) - set(VARTYPES_INCLUDE_DIRS "${VARTYPES_INSTALL_DIR}/include") - set(VARTYPE_LIB_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}vartypes${CMAKE_STATIC_LIBRARY_SUFFIX}) - set(VARTYPES_LIBRARIES "${VARTYPES_INSTALL_DIR}/lib/${VARTYPE_LIB_NAME}") + set(VARTYPES_INCLUDE_DIRS "${install_dir}/include") + set(VARTYPES_LIBRARIES "${install_dir}/${VARTYPES_LIB_SUBPATH}") endif() target_include_directories(${app} PRIVATE ${VARTYPES_INCLUDE_DIRS}) list(APPEND libs ${VARTYPES_LIBRARIES}) # Protobuf -find_package(Protobuf REQUIRED) -include_directories(${PROTOBUF_INCLUDE_DIRS}) -list(APPEND libs ${PROTOBUF_LIBRARIES}) +include(FindOrBuildProtobuf) + +if(TARGET protobuf_external) + add_dependencies(${app} protobuf_external) +endif() + +include_directories(${Protobuf_INCLUDE_DIRS}) +list(APPEND libs ${Protobuf_LIBRARIES}) set (Protobuf_IMPORT_DIRS ${Protobuf_INCLUDE_DIR}) protobuf_generate_cpp(PROTO_CPP PROTO_H diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000..de8ed6dd --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,45 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "windows-default", + "displayName": "Windows x64 Release", + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}" + } + }, + { + "name": "ninja-multi-vcpkg", + "displayName": "Windows x64 Release vcpkg", + "generator": "Ninja Multi-Config", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": { + "type": "FILEPATH", + "value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + }, + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}" + } + } + ], + "buildPresets": [ + { + "name": "ninja-multi-vcpkg", + "configurePreset": "ninja-multi-vcpkg", + "displayName": "Build ninja-multi-vcpkg", + "description": "Build ninja-multi-vcpkg Configurations" + } + ] +} diff --git a/INSTALL.md b/INSTALL.md index 47957903..e7ee47f5 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -56,11 +56,11 @@ $ sudo pacman -S base-devel boost hicolor-icon-theme \ mesa ode protobuf qt5-base cmake git ``` -#### Debian +#### Ubuntu / Debian For Debian, or derivative ``` -$ sudo apt install git build-essential cmake pkg-config qt5-default \ +sudo apt install git build-essential cmake pkg-config qtbase5-dev \ libqt5opengl5-dev libgl1-mesa-dev libglu1-mesa-dev \ libprotobuf-dev protobuf-compiler libode-dev libboost-dev ``` @@ -79,8 +79,8 @@ brew install cmake brew install pkg-config brew tap robotology/formulae brew install robotology/formulae/ode -brew install qt -brew install protobuf +brew install qt@5 +brew install protobuf@21 ``` If you run into build issues, you may need to run this first: @@ -159,7 +159,11 @@ $ sudo make install grSim will be — by default — installed on the `/usr/local` directory. -if you face any problem regarding of updating the grsim version, you can try removing the `grsim.xml`. +## Troubleshooting + +If you face any problem regarding of updating the grsim version, you can try removing the `grsim.xml`. +If grSim crashes almost instantly with some ODE error the issue might by your ODE version. +Try adding -DBUILD_ODE=TRUE to build ODE from source instead of using the system dependency. ## Notes on the performance diff --git a/Makefile b/Makefile index 4486fb59..0b6ba2e0 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,8 @@ BUILDDIR=build BUILDTYPE=Release #BUILDTYPE=Debug +BUILD_ODE=OFF + .PHONY: all build mkbuilddir cmake dist package deb install clean clean-all all: build @@ -22,7 +24,7 @@ mkbuilddir: [ -d $(BUILDDIR) ] || mkdir $(BUILDDIR) cmake: CMakeLists.txt - cd $(BUILDDIR) && cmake -DCMAKE_BUILD_TYPE=$(BUILDTYPE) .. + cd $(BUILDDIR) && cmake -DCMAKE_BUILD_TYPE=$(BUILDTYPE) -DBUILD_ODE=$(BUILD_ODE) .. dist: package diff --git a/clients/qt/CMakeLists.txt b/clients/qt/CMakeLists.txt index 5ea9473f..a543a721 100644 --- a/clients/qt/CMakeLists.txt +++ b/clients/qt/CMakeLists.txt @@ -4,15 +4,30 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) +# policy regarding how to handle generated stuff, OLD behavior would ignore generated files +# (which includes the generated protobuf cpp files) +if (POLICY CMP0071) + cmake_policy(SET CMP0071 NEW) +endif() + +# policy regarding when to rebuild stuff when external projects downloaded with URL changes +if (POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif() + set(libs) find_package(Qt5 COMPONENTS Core Widgets Network REQUIRED) list(APPEND libs Qt5::Core Qt5::Widgets Qt5::Network) +# if find_package was already executed and we already included BuildProtobuf find_package fails, +# so we only want to do execute find_package if protobuf was not found yet +if(NOT Protobuf_FOUND) + include(FindOrBuildProtobuf) +endif() -find_package(Protobuf REQUIRED) -include_directories(${PROTOBUF_INCLUDE_DIRS}) -list(APPEND libs ${PROTOBUF_LIBRARIES}) +include_directories(${Protobuf_INCLUDE_DIRS}) +list(APPEND libs ${Protobuf_LIBRARIES}) protobuf_generate_cpp(PROTO_CPP PROTO_H ../../src/proto/grSim_Replacement.proto @@ -30,5 +45,9 @@ add_executable(${app} MACOSX_BUNDLE mainwindow.h ) +if(TARGET protobuf_external) + add_dependencies(${app} protobuf_external) +endif() + target_link_libraries(${app} ${libs}) diff --git a/cmake/modules/BuildODE.cmake b/cmake/modules/BuildODE.cmake new file mode 100644 index 00000000..41aa54f7 --- /dev/null +++ b/cmake/modules/BuildODE.cmake @@ -0,0 +1,34 @@ +# build ODE, because some versions of it cause grSim to segfault somewhere +# could be because in some packages the double precision is turned off +include(ExternalProject) + +ExternalProject_Add(ode_external + GIT_REPOSITORY https://bitbucket.org/odedevs/ode.git + GIT_TAG 0.16.4 + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX:PATH= + -DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE} + -DCMAKE_C_COMPILER:PATH=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER} + -DCMAKE_MAKE_PROGRAM:PATH=${CMAKE_MAKE_PROGRAM} + # necessary, because it does not build the static libs if this is ON + -DBUILD_SHARED_LIBS=OFF + # if this is OFF grSim just dies instantly and INSTALL.md says it should be ON + -DODE_DOUBLE_PRECISION=ON + -DCMAKE_INSTALL_PREFIX= + STEP_TARGETS install +) + +set(ODE_LIB_SUBPATH "${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ode${CMAKE_STATIC_LIBRARY_SUFFIX}") + +# the byproducts are available after the install step +ExternalProject_Add_Step(ode_external out + DEPENDEES install + BYPRODUCTS + "/${ODE_LIB_SUBPATH}" +) + +ExternalProject_Get_Property(ode_external install_dir) +set(ODE_LIBRARY "${install_dir}/${ODE_LIB_SUBPATH}") +list(APPEND libs ${ODE_LIBRARY}) +target_include_directories(${app} PRIVATE "${install_dir}/include") diff --git a/cmake/modules/BuildProtobuf.cmake b/cmake/modules/BuildProtobuf.cmake new file mode 100644 index 00000000..dcc584b3 --- /dev/null +++ b/cmake/modules/BuildProtobuf.cmake @@ -0,0 +1,87 @@ +# *************************************************************************** +# * Copyright 2017 Michael Eischer * +# * Robotics Erlangen e.V. * +# * http://www.robotics-erlangen.de/ * +# * info@robotics-erlangen.de * +# * * +# * This program is free software: you can redistribute it and/or modify * +# * it under the terms of the GNU General Public License as published by * +# * the Free Software Foundation, either version 3 of the License, or * +# * any later version. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU General Public License for more details. * +# * * +# * You should have received a copy of the GNU General Public License * +# * along with this program. If not, see . * +# *************************************************************************** + +include(ExternalProject) + +set(PROTOBUF_CMAKE_ARGS ) + +ExternalProject_Add(protobuf_external + # URL is the same as in the ER-Force framework, + # because ER-Force needs it and has an incentive to keep the link stable + URL http://www.robotics-erlangen.de/downloads/libraries/protobuf-cpp-3.6.1.tar.gz + URL_HASH SHA256=b3732e471a9bb7950f090fd0457ebd2536a9ba0891b7f3785919c654fe2a2529 + SOURCE_SUBDIR cmake + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX:PATH= + -DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE} + -DCMAKE_C_COMPILER:PATH=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER} + -DCMAKE_MAKE_PROGRAM:PATH=${CMAKE_MAKE_PROGRAM} + # the tests fail to build :-( + -Dprotobuf_BUILD_TESTS:BOOL=OFF + STEP_TARGETS install +) + +set(PROTOBUF_SUBPATH "${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}protobuf${CMAKE_STATIC_LIBRARY_SUFFIX}") +set(LIBPROTOC_SUBPATH "${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}protoc${CMAKE_STATIC_LIBRARY_SUFFIX}") +set(PROTOC_SUBPATH "bin/protoc${CMAKE_EXECUTABLE_SUFFIX}") + +# the byproducts are available after the install step +ExternalProject_Add_Step(protobuf_external out + DEPENDEES install + BYPRODUCTS + "/${PROTOBUF_SUBPATH}" + "/${LIBPROTOC_SUBPATH}" + "/${PROTOC_SUBPATH}" +) + +ExternalProject_Get_Property(protobuf_external install_dir) +set_target_properties(protobuf_external PROPERTIES EXCLUDE_FROM_ALL true) + +# override all necessary variables originally set by find_package +# if FORCE is not set cmake does not allow us to override the variables, for some unknown reason +set(Protobuf_FOUND true CACHE BOOL "" FORCE) +set(Protobuf_VERSION "3.6.1" CACHE STRING "" FORCE) +set(Protobuf_INCLUDE_DIR "${install_dir}/include" CACHE PATH "" FORCE) +set(Protobuf_INCLUDE_DIRS "${Protobuf_INCLUDE_DIR}" CACHE PATH "" FORCE) +set(Protobuf_LIBRARY "${install_dir}/${PROTOBUF_SUBPATH}" CACHE PATH "" FORCE) +set(Protobuf_LIBRARIES "${Protobuf_LIBRARY}" CACHE PATH "" FORCE) +set(Protobuf_LIBRARY_DEBUG "${install_dir}/${PROTOBUF_SUBPATH}" CACHE PATH "" FORCE) +set(Protobuf_LIBRARY_RELEASE "${install_dir}/${PROTOBUF_SUBPATH}" CACHE PATH "" FORCE) +set(Protobuf_LITE_LIBRARY_DEBUG "${install_dir}/${PROTOBUF_SUBPATH}" CACHE PATH "" FORCE) +set(Protobuf_LITE_LIBRARY_RELEASE "${install_dir}/${PROTOBUF_SUBPATH}" CACHE PATH "" FORCE) +set(Protobuf_PROTOC_EXECUTABLE "${install_dir}/${PROTOC_SUBPATH}" CACHE PATH "" FORCE) +set(Protobuf_PROTOC_LIBRARY_DEBUG "${install_dir}/${LIBPROTOC_SUBPATH}" CACHE PATH "" FORCE) +set(Protobuf_PROTOC_LIBRARY_RELEASE "${install_dir}/${LIBPROTOC_SUBPATH}" CACHE PATH "" FORCE) +# this is a dependency for the protobuf_generate_cpp custom command +# if this is not set the generate command sometimes get executed before protoc is compiled +set(protobuf_generate_DEPENDENCIES protobuf_external CACHE STRING "" FORCE) + +# compatibility with cmake 3.10 +if(NOT TARGET protobuf::protoc) + # avoid error if target was already created for an older version + add_executable(protobuf::protoc IMPORTED) +endif() +# override the protobuf::protoc path used by the protobuf_generate_cpp macro +set_target_properties(protobuf::protoc PROPERTIES + IMPORTED_LOCATION "${Protobuf_PROTOC_EXECUTABLE}" +) + +message(STATUS "Building protobuf ${Protobuf_VERSION}") diff --git a/cmake/modules/EnvHelper.cmake b/cmake/modules/EnvHelper.cmake new file mode 100644 index 00000000..f5339c5f --- /dev/null +++ b/cmake/modules/EnvHelper.cmake @@ -0,0 +1,31 @@ +# *************************************************************************** +# * Copyright 2017 Michael Eischer * +# * Robotics Erlangen e.V. * +# * http://www.robotics-erlangen.de/ * +# * info@robotics-erlangen.de * +# * * +# * This program is free software: you can redistribute it and/or modify * +# * it under the terms of the GNU General Public License as published by * +# * the Free Software Foundation, either version 3 of the License, or * +# * any later version. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU General Public License for more details. * +# * * +# * You should have received a copy of the GNU General Public License * +# * along with this program. If not, see . * +# *************************************************************************** + +macro(sanitize_env) + # remove "." from path to avoid searching the build_dir/bin folder + set(ORIG_PATH $ENV{PATH}) + set(MOD_PATH $ENV{PATH}) + list(REMOVE_ITEM MOD_PATH .) + set(ENV{PATH} ${MOD_PATH}) +endmacro() + +macro(restore_env) + set(ENV{PATH} ${ORIG_PATH}) +endmacro() diff --git a/cmake/modules/FindOrBuildProtobuf.cmake b/cmake/modules/FindOrBuildProtobuf.cmake new file mode 100644 index 00000000..4db92e07 --- /dev/null +++ b/cmake/modules/FindOrBuildProtobuf.cmake @@ -0,0 +1,11 @@ +# sanitize environment before find_package, because otherwise it also looks in the directory created for the ExternalProject +include(EnvHelper) +sanitize_env() +find_package(Protobuf 3.3.0) +restore_env() + +# protobuf versions >= 3.21 are incompatible with how the project is setup and cause weird errors +# so we build protobuf ourselves +if(NOT Protobuf_FOUND OR Protobuf_VERSION VERSION_GREATER_EQUAL 3.21) + include(BuildProtobuf) +endif() diff --git a/include/sslworld.h b/include/sslworld.h index ece6c55d..60915835 100644 --- a/include/sslworld.h +++ b/include/sslworld.h @@ -111,6 +111,10 @@ class SSLWorld : public QObject QUdpSocket *simControlSocket; QUdpSocket *blueControlSocket; QUdpSocket *yellowControlSocket; + + QElapsedTimer elapsedLastPackageBlue; + QElapsedTimer elapsedLastPackageYellow; + bool updatedCursor; Robot* robots[MAX_ROBOT_COUNT*2]{}; int sendGeomCount; diff --git a/renovate.json b/renovate.json deleted file mode 100644 index f45d8f11..00000000 --- a/renovate.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": [ - "config:base" - ] -} diff --git a/shippable.yml b/shippable.yml deleted file mode 100644 index 4aae1497..00000000 --- a/shippable.yml +++ /dev/null @@ -1,46 +0,0 @@ -language: none -compiler: - - gcc - -env: - global: - - GRSIM_WS=$HOME/grsim_ws - matrix: - - UBUNTU_DISTRO="trusty" - - UBUNTU_DISTRO="xenial" - -build: - pre_ci_boot: - image_name: ubuntu - image_tag: ${UBUNTU_DISTRO} - pull: true - - ci: - - env # debug - # OS level dependencies - - sudo apt-get update -qq - # libboost-dev is for vartypes - - sudo apt-get install -qq -y git build-essential cmake libqt4-dev libgl1-mesa-dev libglu1-mesa-dev libprotobuf-dev protobuf-compiler libode-dev libboost-dev - - mkdir -p $GRSIM_WS - - ln -s $SHIPPABLE_BUILD_DIR $GRSIM_WS/grSim - # Compile vartypes - - cd $GRSIM_WS - - git clone https://github.com/szi/vartypes.git - - cd vartypes - - mkdir build && cd build - - cmake .. - - make - - sudo make install - # compile grSim - - cd $GRSIM_WS/grSim - - mkdir build && cd build - - cmake .. - - make - - sudo make install - -integrations: - notifications: - - integrationName: email - type: email - on_success: change - on_failure: always diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 35c75a49..0460c905 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -93,7 +93,7 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(simControlSocket,SIGNAL(readyRead()),this,SLOT(simControlSocketReady())); QObject::connect(blueControlSocket,SIGNAL(readyRead()),this,SLOT(blueControlSocketReady())); QObject::connect(yellowControlSocket,SIGNAL(readyRead()),this,SLOT(yellowControlSocketReady())); - + glwidget->ssl->visionServer = visionServer; glwidget->ssl->commandSocket = commandSocket; glwidget->ssl->blueStatusSocket = blueStatusSocket; @@ -410,6 +410,36 @@ void MainWindow::update() noiselabel->setVisible(configwidget->noise()); cursorlabel->setText(QString("Cursor: [X=%1;Y=%2;Z=%3]").arg(dRealToStr(glwidget->ssl->cursor_x)).arg(dRealToStr(glwidget->ssl->cursor_y)).arg(dRealToStr(glwidget->ssl->cursor_z))); statusWidget->update(); + + if(glwidget != nullptr && glwidget->ssl != nullptr) + { + // Stops blue robots from moving if no package has been received for 1 second + if(glwidget->ssl->elapsedLastPackageBlue.nsecsElapsed()*1e-9 > 1) + { + for(int i=0; i < glwidget->cfg->Robots_Count(); ++i) + { + const int index = glwidget->ssl->robotIndex(i, BLUE-1); + + if(index == -1 || glwidget->ssl->robots[index] == nullptr) + continue; + + glwidget->ssl->robots[index]->resetSpeeds(); + } + } + // Stops yellow robots from moving if no package has been received for 1 second + if(glwidget->ssl->elapsedLastPackageYellow.nsecsElapsed()*1e-9 > 1) + { + for(int i=0; i < glwidget->cfg->Robots_Count(); ++i) + { + const int index = glwidget->ssl->robotIndex(i, YELLOW-1); + + if(index == -1 || glwidget->ssl->robots[index] == nullptr) + continue; + + glwidget->ssl->robots[index]->resetSpeeds(); + } + } + } } void MainWindow::updateRobotLabel() diff --git a/src/sslworld.cpp b/src/sslworld.cpp index 7b358c98..2cb626e8 100644 --- a/src/sslworld.cpp +++ b/src/sslworld.cpp @@ -313,6 +313,9 @@ SSLWorld::SSLWorld(QGLWidget* parent, ConfigWidget* _cfg, RobotsFormation *form1 } restartRequired = false; + + elapsedLastPackageBlue.start(); + elapsedLastPackageYellow.start(); } int SSLWorld::robotIndex(int robot,int team) { @@ -705,6 +708,8 @@ void SSLWorld::blueControlSocketReady() { robotControlResponse.SerializeToArray(buffer.data(), buffer.size()); blueControlSocket->writeDatagram(buffer.data(), buffer.size(), datagram.senderAddress(), datagram.senderPort()); } + + elapsedLastPackageBlue.start(); } void SSLWorld::yellowControlSocketReady() { @@ -723,6 +728,8 @@ void SSLWorld::yellowControlSocketReady() { robotControlResponse.SerializeToArray(buffer.data(), buffer.size()); yellowControlSocket->writeDatagram(buffer.data(), buffer.size(), datagram.senderAddress(), datagram.senderPort()); } + + elapsedLastPackageYellow.start(); } @@ -835,8 +842,9 @@ void SSLWorld::processTeleportRobot(const TeleportRobot &teleBot, Robot *robot) if (teleBot.has_present()) { robot->on = teleBot.present(); if(!teleBot.present()) { - // Move it out of the field - robot->setXY(1e6, 1e6); + // Move it out of the field. + // Set different x and y to avoid collisions of the robots. + robot->setXY(1e6 * teleBot.id().id(), 1e6 * teleBot.id().team()); } } } diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 00000000..89c2f3c8 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,9 @@ +{ + "name": "grsim", + "version-string": "0.0.1", + "dependencies": [ + "qt5-base", + "ode", + "protobuf" + ] +}