diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..3c815b7 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,33 @@ +name: "Build action: Foxy + Rolling" + +on: + push: + branches: [ master, dev ] + pull_request: + branches: [ master, dev ] + schedule: + # Run once per day to detect broken dependencies. + - cron: '17 6 * * *' + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-20.04 ] + ros_distribution: [ foxy, rolling ] + steps: + - uses: actions/checkout@v2 + - uses: ros-tooling/setup-ros@0.0.26 + with: + required-ros-distributions: ${{ matrix.ros_distribution }} + - uses : ros-tooling/action-ros-ci@0.1.0 + with: + package-name: "system_modes system_modes_examples" + target-ros2-distro: ${{ matrix.ros_distribution }} + colcon-mixin-name: coverage-gcc + colcon-mixin-repository: https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml + - uses: codecov/codecov-action@v1 + with: + file: ros_ws/lcov/total_coverage.info diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index 422c83a..0000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,45 +0,0 @@ -name: Lint system modes -on: - pull_request: - -jobs: - ament_xmllint: - name: ament_xmllint - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - - uses: ros-tooling/setup-ros@0.0.26 - - uses: ros-tooling/action-ros2-lint@0.0.6 - with: - linter: xmllint - package-name: system_modes system_modes_examples - - ament_lint_cpp: - name: ament_${{ matrix.linter }} - runs-on: ubuntu-18.04 - strategy: - fail-fast: false - matrix: - linter: [cppcheck, cpplint, uncrustify] - steps: - - uses: actions/checkout@v2 - - uses: ros-tooling/setup-ros@0.0.26 - - uses: ros-tooling/action-ros2-lint@0.0.6 - with: - linter: ${{ matrix.linter }} - package-name: system_modes system_modes_examples - - ament_lint_py: - name: ament_${{ matrix.linter }} - runs-on: ubuntu-18.04 - strategy: - fail-fast: false - matrix: - linter: [flake8, pep257] - steps: - - uses: actions/checkout@v2 - - uses: ros-tooling/setup-ros@0.0.26 - - uses: ros-tooling/action-ros2-lint@0.0.6 - with: - linter: ${{ matrix.linter }} - package-name: system_modes system_modes_examples diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index 960527a..0000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,22 +0,0 @@ -name: Test system modes -on: - pull_request: - push: - branches: - - master - -jobs: - build_and_test: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-18.04] - steps: - - uses: ros-tooling/setup-ros@0.0.26 - - uses: ros-tooling/action-ros-ci@0.0.19 - with: - package-name: system_modes system_modes_examples - target-ros2-distro: foxy - colcon-mixin-name: coverage-gcc - colcon-mixin-repository: https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml diff --git a/README.md b/README.md index 0c6b850..d229bbc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # ROS 2 System Modes +[![License](https://img.shields.io/badge/License-Apache%202-blue.svg)](https://github.com/micro-ROS/system_modes/blob/master/LICENSE) +[![Build status](https://build.ros2.org/job/Ddev__system_modes__ubuntu_bionic_amd64/badge/icon?subject=Build%20farm%3A%20Dashing)](https://build.ros2.org/job/Ddev__system_modes__ubuntu_bionic_amd64/) +[![Build status](http://build.ros2.org/job/Edev__system_modes__ubuntu_bionic_amd64/badge/icon?subject=Build%20farm%3A%20Eloquent)](http://build.ros2.org/job/Edev__system_modes__ubuntu_bionic_amd64/) +[![Build status](http://build.ros2.org/job/Fdev__system_modes__ubuntu_focal_amd64/badge/icon?subject=Build%20farm%3A%20Foxy)](http://build.ros2.org/job/Fdev__system_modes__ubuntu_focal_amd64/) +[![Build status](http://build.ros2.org/job/Rdev__system_modes__ubuntu_focal_amd64/badge/icon?subject=Build%20farm%3A%20Rolling)](http://build.ros2.org/job/Rdev__system_modes__ubuntu_focal_amd64/) +[![Build status](https://github.com/micro-ROS/system_modes/workflows/Build%20action%3A%20Foxy%20%2B%20Rolling/badge.svg)](https://github.com/micro-ROS/system_modes/actions) +[![Code coverage](https://codecov.io/gh/micro-ROS/system_modes/branch/master/graph/badge.svg)](https://codecov.io/gh/micro-ROS/system_modes) + This repository explores a system modes concept that is implemented for ROS 2 in two packages: * [system_modes](./system_modes/) provides a library for system mode inference, a mode manager, and a mode monitor * [system_modes_examples](./system_modes_examples/) implements a simple example @@ -32,6 +40,12 @@ ROS 2 System Modes are open-sourced under the Apache-2.0 license. See the For a list of other open-source components included in ROS 2 system_modes, see the file [3rd-party-licenses.txt](3rd-party-licenses.txt). +## Quality assurance + +The colcon_test tool is used for quality assurances, which includes cpplint, uncrustify, flake8, xmllint and various other tools. + +Unit tests based on [gtest](https://github.com/google/googletest) are located in the [./system_modes/test](system_modes/test) folder. + ## Known Issues/Limitations Please notice the following issues/limitations: diff --git a/system_modes/CMakeLists.txt b/system_modes/CMakeLists.txt index 18dc3d9..4f23dad 100644 --- a/system_modes/CMakeLists.txt +++ b/system_modes/CMakeLists.txt @@ -61,7 +61,7 @@ include_directories(../../build/system_modes/rosidl_generator_cpp/) link_directories(../../build/system_modes/) target_link_libraries(mode system_modes__rosidl_typesupport_cpp) - # Causes the visibility macros to use dllexport rather than dllimport, +# Causes the visibility macros to use dllexport rather than dllimport, # which is appropriate when building the dll but not consuming it. target_compile_definitions(mode PRIVATE "SYSTEMMODES_BUILDING_LIBRARY") @@ -106,9 +106,6 @@ if(BUILD_TESTING) # the following line skips the linter which checks for copyrights # remove the line when a copyright and license is present in all source files set(ament_cmake_copyright_FOUND TRUE) - # the following line skips cpplint (only works in a git repo) - # remove the line when this package is a git repo - set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() set(MODE_FILE_CORRECT ${CMAKE_CURRENT_SOURCE_DIR}/test/test_modes.yaml) diff --git a/system_modes/changelog.rst b/system_modes/changelog.rst index 6666b93..3c6443a 100644 --- a/system_modes/changelog.rst +++ b/system_modes/changelog.rst @@ -2,6 +2,11 @@ Changelog for package system_modes_examples ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.4.2 (2020-12-17) +----------- +* Error handling and rules feature no longer experimental +* Fixed bugs in monitor and tests + 0.4.1 (2020-10-29) ----------- * Include experimental error handling and rules feature diff --git a/system_modes/include/system_modes/mode.hpp b/system_modes/include/system_modes/mode.hpp index e6df72a..34f5e11 100644 --- a/system_modes/include/system_modes/mode.hpp +++ b/system_modes/include/system_modes/mode.hpp @@ -16,6 +16,7 @@ #include "system_modes/mode_impl.hpp" +#include #include #include @@ -46,6 +47,7 @@ class ModeBase public: explicit ModeBase(const std::string & mode_name); virtual ~ModeBase() = default; + // cppcheck-suppress unknownMacro RCLCPP_DISABLE_COPY(ModeBase) std::string get_name() const; @@ -74,6 +76,7 @@ class DefaultMode : public ModeBase public: DefaultMode(); explicit DefaultMode(const std::string & mode_name) = delete; + // cppcheck-suppress unknownMacro RCLCPP_DISABLE_COPY(DefaultMode) virtual void set_parameter(const rclcpp::Parameter & parameter); @@ -89,6 +92,7 @@ class Mode : public ModeBase public: explicit Mode(const std::string & mode_name) = delete; Mode(const std::string & mode_name, const DefaultModePtr default_mode); + // cppcheck-suppress unknownMacro RCLCPP_DISABLE_COPY(Mode) virtual ~Mode() = default; diff --git a/system_modes/include/system_modes/mode_handling.hpp b/system_modes/include/system_modes/mode_handling.hpp index 1816d3a..1b662f8 100644 --- a/system_modes/include/system_modes/mode_handling.hpp +++ b/system_modes/include/system_modes/mode_handling.hpp @@ -51,6 +51,7 @@ class ModeHandling { public: explicit ModeHandling(const std::string & model_path); + // cppcheck-suppress unknownMacro RCLCPP_DISABLE_COPY(ModeHandling) virtual ~ModeHandling() = default; diff --git a/system_modes/include/system_modes/mode_inference.hpp b/system_modes/include/system_modes/mode_inference.hpp index eaf454a..b02eed1 100644 --- a/system_modes/include/system_modes/mode_inference.hpp +++ b/system_modes/include/system_modes/mode_inference.hpp @@ -40,6 +40,7 @@ class ModeInference { public: explicit ModeInference(const std::string & model_path); + // cppcheck-suppress unknownMacro RCLCPP_DISABLE_COPY(ModeInference) virtual const std::vector get_all_parts() const; diff --git a/system_modes/package.xml b/system_modes/package.xml index 9e4753d..ed3ba0c 100644 --- a/system_modes/package.xml +++ b/system_modes/package.xml @@ -2,7 +2,7 @@ system_modes - 0.4.1 + 0.4.2 The system modes concept assumes that a robotics system is built from components with a lifecycle. It adds a notion of (sub-)systems, diff --git a/system_modes/src/system_modes/mode_inference.cpp b/system_modes/src/system_modes/mode_inference.cpp index cd53aa5..c197f8a 100644 --- a/system_modes/src/system_modes/mode_inference.cpp +++ b/system_modes/src/system_modes/mode_inference.cpp @@ -56,7 +56,11 @@ void ModeInference::update(const string & node, const StateAndMode & sm) { this->update_state(node, sm.state); - this->update_mode(node, sm.mode); + if (sm.state == State::PRIMARY_STATE_ACTIVE) { + this->update_mode(node, sm.mode); + } else { + this->update_mode(node, ""); + } } void @@ -162,7 +166,14 @@ ModeInference::get(const string & part) const throw std::runtime_error("No solid information about state and mode of '" + part + "'."); } - return this->nodes_.at(part); + auto sam = this->nodes_.at(part); + if (sam.state != State::PRIMARY_STATE_ACTIVE && + sam.state != State::TRANSITION_STATE_ACTIVATING) + { + sam.mode = ""; + } + + return sam; } StateAndMode @@ -422,7 +433,7 @@ ModeInference::get_or_infer(const string & part) return stateAndMode; } } catch (...) { - // not a node, so try inference + // so try inference } try { @@ -441,6 +452,9 @@ ModeInference::get_or_infer(const string & part) if (stateAndMode.state == 0 && stateAndMode.mode.empty()) { throw std::runtime_error("Not able to infer anything for part " + part); } + if (stateAndMode.state != State::PRIMARY_STATE_ACTIVE) { + stateAndMode.mode = ""; + } return stateAndMode; } @@ -555,9 +569,13 @@ ModeInference::read_modes_from_model(const string & model_path) } else { if (param.value_to_string().compare("node") != 0) { - this->systems_.emplace(part_name, StateAndMode(0, "")); + this->systems_.emplace( + part_name, + StateAndMode(State::PRIMARY_STATE_UNKNOWN, "")); } else { - this->nodes_.emplace(part_name, StateAndMode(0, "")); + this->nodes_.emplace( + part_name, + StateAndMode(State::PRIMARY_STATE_UNKNOWN, "")); } } } diff --git a/system_modes/src/system_modes/mode_monitor.cpp b/system_modes/src/system_modes/mode_monitor.cpp index 521b926..aabb4d4 100644 --- a/system_modes/src/system_modes/mode_monitor.cpp +++ b/system_modes/src/system_modes/mode_monitor.cpp @@ -204,9 +204,11 @@ ModeMonitor::refresh() const // state/mode inference try { - auto stateAndMode = mode_inference_->infer(node); - state_infer = stateAndMode.state; - mode_infer = stateAndMode.mode; + if (state_actual == State::PRIMARY_STATE_ACTIVE) { + auto stateAndMode = mode_inference_->infer(node); + state_infer = stateAndMode.state; + mode_infer = stateAndMode.mode; + } } catch (std::out_of_range & ex) { RCLCPP_DEBUG( get_logger(), diff --git a/system_modes_examples/changelog.rst b/system_modes_examples/changelog.rst index 0f2d931..61db0f5 100644 --- a/system_modes_examples/changelog.rst +++ b/system_modes_examples/changelog.rst @@ -2,6 +2,11 @@ Changelog for package system_modes_examples ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.4.2 (2020-12-17) +----------- +* Error handling and rules feature no longer experimental +* Fixed bugs in monitor and tests + 0.4.1 (2020-10-29) ----------- * Include experimental error handling and rules feature diff --git a/system_modes_examples/package.xml b/system_modes_examples/package.xml index f7e7e52..f198618 100644 --- a/system_modes_examples/package.xml +++ b/system_modes_examples/package.xml @@ -2,7 +2,7 @@ system_modes_examples - 0.4.1 + 0.4.2 Simple example system and according launch files for the system_modes package.