Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design the ROS2 implementation for Clock class #575

Merged
merged 7 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ jobs:
cd C:/robotology/vcpkg
./bootstrap-vcpkg.bat

# Install Catch2
cd C:/robotology/vcpkg
./vcpkg.exe --overlay-ports=C:/robotology/robotology-vcpkg-ports install catch2:x64-windows

# Install tomlplusplus
./vcpkg.exe --overlay-ports=C:/robotology/robotology-vcpkg-ports install tomlplusplus:x64-windows

Expand Down Expand Up @@ -453,6 +449,23 @@ jobs:

cmake --build . --config ${{ matrix.build_type }} --target install

- name: Catch2 Dependency [Windows]
if: matrix.os == 'windows-2019'
shell: bash
run: |
# Catch2
git clone -b ${Catch2_TAG} https://github.com/catchorg/Catch2.git
cd Catch2
mkdir -p build
cd build
cmake -A x64 -DCMAKE_TOOLCHAIN_FILE=${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake \
-DCMAKE_PREFIX_PATH=${GITHUB_WORKSPACE}/install/deps \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/install/deps \
-DBUILD_TESTING=OFF ..

cmake --build . --config ${{ matrix.build_type }} --target install

- name: Source-based Dependencies [Ubuntu]
if: steps.cache-source-deps.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu')
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/conda-forge-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- uses: conda-incubator/setup-miniconda@v2
with:
mamba-version: "*"
channels: conda-forge,robotology
channels: conda-forge,robotology,robostack-humble
channel-priority: true

- name: Dependencies
Expand All @@ -38,7 +38,7 @@ jobs:
mamba install cmake compilers make ninja pkg-config
# Actual dependencies
# We ask for numpy 1.22.4 because of https://github.com/ami-iit/bipedal-locomotion-framework/issues/545
mamba install idyntree "yarp>=3.5.0" libmatio matio-cpp lie-group-controllers eigen qhull "casadi>=3.5.5" cppad spdlog "catch2=2" nlohmann_json manif manifpy pybind11 "numpy=1.22.4" pytest scipy opencv pcl tomlplusplus unicycle-footstep-planner "icub-models>=1.23.4"
mamba install idyntree "yarp>=3.5.0" libmatio matio-cpp lie-group-controllers eigen qhull "casadi>=3.5.5" cppad spdlog "catch2=2" nlohmann_json manif manifpy pybind11 "numpy=1.22.4" pytest scipy opencv pcl tomlplusplus unicycle-footstep-planner "icub-models>=1.23.4" ros-humble-desktop
- name: Linux-only Dependencies [Linux]
if: contains(matrix.os, 'ubuntu')
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project are documented in this file.
## [unreleased]
### Added
- Log the status of the system in `YarpRobotLoggerDevice` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/571)
- Add the `ROS2` implementation for Clock class (https://github.com/ami-iit/bipedal-locomotion-framework/pull/575)

### Changed

Expand Down
7 changes: 7 additions & 0 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ else ()
endif()
mark_as_advanced(FRAMEWORK_COMPILE_BINDINGS_YarpSystem)

if (FRAMEWORK_COMPILE_System AND FRAMEWORK_COMPILE_RosImplementation)
set(FRAMEWORK_COMPILE_BINDINGS_RosSystem ON)
else ()
set(FRAMEWORK_COMPILE_BINDINGS_RosSystem OFF)
endif()
mark_as_advanced(FRAMEWORK_COMPILE_BINDINGS_RosSystem)

configure_file_with_cmakeif(${CMAKE_CURRENT_SOURCE_DIR}/bipedal_locomotion_framework.cpp.in
${CMAKE_CURRENT_BINARY_DIR}/bipedal_locomotion_framework.cpp
@ONLY)
Expand Down
12 changes: 12 additions & 0 deletions bindings/python/System/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ if(FRAMEWORK_COMPILE_System)

endif()

if(FRAMEWORK_COMPILE_RosImplementation)

add_bipedal_locomotion_python_module(
NAME SystemRosImplementationBindings
SOURCES src/RosClock.cpp src/RosModule.cpp
HEADERS ${H_PREFIX}/RosClock.h ${H_PREFIX}/RosModule.h
LINK_LIBRARIES BipedalLocomotion::SystemRosImplementation
)

endif()


endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @file RosClock.h
* @authors Giulio Romualdi
* @copyright 2022 Istituto Italiano di Tecnologia (IIT). This software may be modified and
* distributed under the terms of the BSD-3-Clause license.
*/

#ifndef BIPEDAL_LOCOMOTION_BINDINGS_SYSTEM_ROS_CLOCK_H
#define BIPEDAL_LOCOMOTION_BINDINGS_SYSTEM_ROS_CLOCK_H

#include <pybind11/pybind11.h>

namespace BipedalLocomotion
{
namespace bindings
{
namespace System
{

void CreateRosClock(pybind11::module& module);
void CreateRosClockFactory(pybind11::module& module);

} // namespace System
} // namespace bindings
} // namespace BipedalLocomotion

#endif // BIPEDAL_LOCOMOTION_BINDINGS_SYSTEM_ROS_CLOCK_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @file RosModule.h
* @authors Giulio Romualdi
* @copyright 2022 Istituto Italiano di Tecnologia (IIT). This software may be modified and
* distributed under the terms of the BSD-3-Clause license.
*/

#ifndef BIPEDAL_LOCOMOTION_BINDINGS_SYSTEM_ROS_MODULE_H
#define BIPEDAL_LOCOMOTION_BINDINGS_SYSTEM_ROS_MODULE_H

#include <pybind11/pybind11.h>

namespace BipedalLocomotion
{
namespace bindings
{
namespace System
{

void CreateRosModule(pybind11::module& module);

} // namespace System
} // namespace bindings
} // namespace BipedalLocomotion

#endif // BIPEDAL_LOCOMOTION_BINDINGS_SYSTEM_ROS_MODULE_H
45 changes: 45 additions & 0 deletions bindings/python/System/src/RosClock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @file RosClock.cpp
* @authors Giulio Romualdi
* @copyright 2022 Istituto Italiano di Tecnologia (IIT). This software may be modified and
* distributed under the terms of the BSD-3-Clause license.
*/

#include <pybind11/cast.h>
#include <pybind11/chrono.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <BipedalLocomotion/System/RosClock.h>
#include <BipedalLocomotion/bindings/System/RosClock.h>

namespace BipedalLocomotion
{
namespace bindings
{
namespace System
{

void CreateRosClock(pybind11::module& module)
{
namespace py = ::pybind11;

py::class_<::BipedalLocomotion::System::RosClock,
::BipedalLocomotion::System::IClock>(module, "RosClock");
}

void CreateRosClockFactory(pybind11::module& module)
{
namespace py = ::pybind11;

py::class_<::BipedalLocomotion::System::RosClockFactory,
::BipedalLocomotion::System::ClockFactory,
std::shared_ptr<::BipedalLocomotion::System::RosClockFactory>>(module,
"RosClockFactory")
.def(py::init<const std::vector<std::string>&>(), py::arg("args"));
;
}

} // namespace System
} // namespace bindings
} // namespace BipedalLocomotion
26 changes: 26 additions & 0 deletions bindings/python/System/src/RosModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @file RosModule.cpp
* @authors Giulio Romualdi
* @copyright 2022 Istituto Italiano di Tecnologia (IIT). This software may be modified and
* distributed under the terms of the BSD-3-Clause license.
*/

#include <pybind11/pybind11.h>

#include <BipedalLocomotion/bindings/System/RosClock.h>
#include <BipedalLocomotion/bindings/System/RosModule.h>

namespace BipedalLocomotion
{
namespace bindings
{
namespace System
{
void CreateRosModule(pybind11::module& module)
{
CreateRosClock(module);
CreateRosClockFactory(module);
}
} // namespace System
} // namespace bindings
} // namespace BipedalLocomotion
8 changes: 8 additions & 0 deletions bindings/python/bipedal_locomotion_framework.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include <BipedalLocomotion/bindings/System/YarpModule.h>
@endcmakeif FRAMEWORK_COMPILE_BINDINGS_YarpSystem

@cmakeif FRAMEWORK_COMPILE_BINDINGS_RosSystem
#include <BipedalLocomotion/bindings/System/RosModule.h>
@endcmakeif FRAMEWORK_COMPILE_BINDINGS_RosSystem

@cmakeif FRAMEWORK_COMPILE_Contact
#include <BipedalLocomotion/bindings/Contacts/Module.h>
@endcmakeif FRAMEWORK_COMPILE_Contact
Expand Down Expand Up @@ -104,6 +108,10 @@ PYBIND11_MODULE(bindings, m)
bindings::System::CreateYarpModule(systemModule);
@endcmakeif FRAMEWORK_COMPILE_BINDINGS_YarpSystem

@cmakeif FRAMEWORK_COMPILE_BINDINGS_RosSystem
bindings::System::CreateRosModule(systemModule);
@endcmakeif FRAMEWORK_COMPILE_BINDINGS_RosSystem

@cmakeif FRAMEWORK_COMPILE_Contact
py::module contactsModule = m.def_submodule("contacts");
bindings::Contacts::CreateModule(contactsModule);
Expand Down
122 changes: 72 additions & 50 deletions cmake/AddUninstallTarget.cmake
Original file line number Diff line number Diff line change
@@ -1,70 +1,92 @@
#.rst:
# AddUninstallTarget
# ------------------
#
# Add the "uninstall" target for your project::
#
# include(AddUninstallTarget)
#
#
# will create a file cmake_uninstall.cmake in the build directory and add a
# custom target uninstall that will remove the files installed by your package
# (using install_manifest.txt)

#=============================================================================
# Copyright 2008-2013 Kitware, Inc.
# Copyright 2013 iCub Facility, Istituto Italiano di Tecnologia
# Authors: Daniele E. Domenichelli <daniele.domenichelli@iit.it>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)


if(DEFINED __ADD_UNINSTALL_TARGET_INCLUDED)
# SPDX-FileCopyrightText: 2012-2021 Istituto Italiano di Tecnologia (IIT)
# SPDX-FileCopyrightText: 2008-2013 Kitware Inc.
# SPDX-License-Identifier: BSD-3-Clause

#[=======================================================================[.rst:
AddUninstallTarget
------------------
Add the "uninstall" target for your project::
include(AddUninstallTarget)
will create a file ``cmake_uninstall.cmake`` in the build directory and add a
custom target ``uninstall`` (or ``UNINSTALL`` on Visual Studio and Xcode) that
will remove the files installed by your package (using
``install_manifest.txt``).
See also
https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake
The :module:`AddUninstallTarget` module must be included in your main
``CMakeLists.txt``. If included in a subdirectory it does nothing.
This allows you to use it safely in your main ``CMakeLists.txt`` and include
your project using ``add_subdirectory`` (for example when using it with
:cmake:module:`FetchContent`).
If the ``uninstall`` target already exists, the module does nothing.
#]=======================================================================]


# AddUninstallTarget works only when included in the main CMakeLists.txt
if(NOT "${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
return()
endif()

# The name of the target is uppercase in MSVC and Xcode (for coherence with the
# other standard targets)
if("${CMAKE_GENERATOR}" MATCHES "^(Visual Studio|Xcode)")
set(_uninstall "UNINSTALL")
else()
set(_uninstall "uninstall")
endif()

# If target is already defined don't do anything
if(TARGET ${_uninstall})
return()
endif()
set(__ADD_UNINSTALL_TARGET_INCLUDED TRUE)


set(_filename ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
set(_filename cmake_uninstall.cmake)

file(WRITE ${_filename}
"if(NOT EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\")
message(WARNING \"Cannot find install manifest: \\\"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\\\"\")
return()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_filename}"
"if(NOT EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\")
message(WARNING \"Cannot find install manifest: \\\"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\\\"\")
return()
endif()
file(READ \"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\" files)
string(STRIP \"\${files}\" files)
string(REGEX REPLACE \"\\n\" \";\" files \"\${files}\")
list(REVERSE files)
foreach(file \${files})
if(IS_SYMLINK \"\$ENV{DESTDIR}\${file}\" OR EXISTS \"\$ENV{DESTDIR}\${file}\")
message(STATUS \"Uninstalling: \$ENV{DESTDIR}\${file}\")
if(EXISTS \"\$ENV{DESTDIR}\${file}\")
execute_process(
COMMAND \${CMAKE_COMMAND} -E remove \"\$ENV{DESTDIR}\${file}\"
OUTPUT_VARIABLE rm_out
RESULT_VARIABLE rm_retval)
if(NOT \"\${rm_retval}\" EQUAL 0)
message(FATAL_ERROR \"Problem when removing \\\"\$ENV{DESTDIR}\${file}\\\"\")
endif()
else()
message(STATUS \"File \\\"\$ENV{DESTDIR}\${file}\\\" does not exist.\")
execute_process(
COMMAND \${CMAKE_COMMAND} -E remove \"\$ENV{DESTDIR}\${file}\"
OUTPUT_VARIABLE rm_out
RESULT_VARIABLE rm_retval)
if(NOT \"\${rm_retval}\" EQUAL 0)
message(FATAL_ERROR \"Problem when removing \\\"\$ENV{DESTDIR}\${file}\\\"\")
endif()
else()
message(STATUS \"Not-found: \$ENV{DESTDIR}\${file}\")
endif()
endforeach(file)
")

if("${CMAKE_GENERATOR}" MATCHES "^(Visual Studio|Xcode)")
set(_uninstall "UNINSTALL")
set(_desc "Uninstall the project...")
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(_comment COMMAND \$\(CMAKE_COMMAND\) -E cmake_echo_color --switch=$\(COLOR\) --cyan "${_desc}")
else()
set(_uninstall "uninstall")
set(_comment COMMENT "${_desc}")
endif()
add_custom_target(${_uninstall} COMMAND "${CMAKE_COMMAND}" -P "${_filename}")
add_custom_target(${_uninstall}
${_comment}
COMMAND ${CMAKE_COMMAND} -P ${_filename}
USES_TERMINAL
BYPRODUCTS uninstall_byproduct
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
set_property(SOURCE uninstall_byproduct PROPERTY SYMBOLIC 1)

set_property(TARGET ${_uninstall} PROPERTY FOLDER "CMakePredefinedTargets")
Loading