Skip to content

Commit a006896

Browse files
committed
Merge branch 'master' into feature/win-and-macos-build
Signed-off-by: Nordmann Arne (CR/ADT3) <arne.nordmann@de.bosch.com>
2 parents 5540c5e + 5359d23 commit a006896

23 files changed

+499
-98
lines changed

.github/workflows/ci.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: "Build action: Foxy + Rolling"
2+
3+
on:
4+
push:
5+
branches: [ master, dev ]
6+
pull_request:
7+
branches: [ master, dev ]
8+
schedule:
9+
# Run once per day to detect broken dependencies.
10+
- cron: '17 6 * * *'
11+
12+
jobs:
13+
build:
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [ ubuntu-20.04, macos-latest, windows-latest ]
19+
ros_distribution: [ foxy, rolling ]
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: ros-tooling/setup-ros@0.0.26
23+
with:
24+
required-ros-distributions: ${{ matrix.ros_distribution }}
25+
- uses : ros-tooling/action-ros-ci@0.1.0
26+
with:
27+
package-name: "system_modes system_modes_examples"
28+
target-ros2-distro: ${{ matrix.ros_distribution }}
29+
colcon-mixin-name: coverage-gcc
30+
colcon-mixin-repository: https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml
31+
- uses: codecov/codecov-action@v1
32+
with:
33+
file: ros_ws/lcov/total_coverage.info

.github/workflows/lint.yaml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/workflows/test.yaml

Lines changed: 0 additions & 22 deletions
This file was deleted.

NOTICE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,13 @@
2020
#
2121
# Please keep the list sorted.
2222

23+
Open Robotics
24+
Jacob Perron <jacob@openrobotics.org>
25+
Scott Logan <logans@cottsay.net>
26+
2327
Robert Bosch GmbH
2428
Arne Nordmann <arne.nordmann@de.bosch.com>
29+
Ralph Lange <ralph.lange@de.bosch.com>
30+
31+
BSH Hausgeräte GmbH
32+
Thilak Raj <chikmagalore.thilak@bshg.com>

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# ROS 2 System Modes
22

3+
[![License](https://img.shields.io/badge/License-Apache%202-blue.svg)](https://github.com/micro-ROS/system_modes/blob/master/LICENSE)
4+
[![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/)
5+
[![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/)
6+
[![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/)
7+
[![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/)
8+
[![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)
9+
[![Code coverage](https://codecov.io/gh/micro-ROS/system_modes/branch/master/graph/badge.svg)](https://codecov.io/gh/micro-ROS/system_modes)
10+
311
This repository explores a system modes concept that is implemented for ROS 2 in two packages:
412
* [system_modes](./system_modes/) provides a library for system mode inference, a mode manager, and a mode monitor
513
* [system_modes_examples](./system_modes_examples/) implements a simple example
@@ -17,7 +25,7 @@ standards, e.g., ISO 26262.
1725

1826
## How to Build, Test, Install, and Use
1927

20-
After you cloned this repository into your ROS 2 workspace folder, you may build and install the [system_modes](./system_modes/) package and the [system_modes_examples](./system_modes_examples/) package using colcon:
28+
After you cloned this repository into your ROS 2 workspace folder, you may build and install the [system_modes](./system_modes/) package and the [system_modes_examples](./system_modes_examples/) package using colcon:
2129
$ `colcon build --packages-select-regex system_modes`
2230

2331
Have a look at the [system_modes_examples](./system_modes_examples/) documentation to try your installation.
@@ -32,11 +40,18 @@ ROS 2 System Modes are open-sourced under the Apache-2.0 license. See the
3240
For a list of other open-source components included in ROS 2 system_modes,
3341
see the file [3rd-party-licenses.txt](3rd-party-licenses.txt).
3442

43+
## Quality assurance
44+
45+
The colcon_test tool is used for quality assurances, which includes cpplint, uncrustify, flake8, xmllint and various other tools.
46+
47+
Unit tests based on [gtest](https://github.com/google/googletest) are located in the [./system_modes/test](system_modes/test) folder.
48+
3549
## Known Issues/Limitations
3650

3751
Please notice the following issues/limitations:
3852

3953
* Currently, (sub-)systems managed by the mode manager are not recognized by the `ros2 lifecycle` tool (*"Node not found"*). So to trigger lifecycle transitions in (sub-)systems, you have to go with the `ros2 service call` tool. Check the [system_modes_examples](./system_modes_examples/) documentation for example calls.
54+
* The [Error Handling and Rules](./system_modes/README.md#error-handling-and-rules-experimental) feature is still experimental and might be subject to major changes. However, if no rules are specified in the model file, this feature is not used.
4055

4156
## Acknowledgments
4257

system_modes/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ rosidl_generate_interfaces(${PROJECT_NAME}
4040
add_library(mode SHARED
4141
src/system_modes/mode.cpp
4242
src/system_modes/mode_impl.cpp
43+
src/system_modes/mode_handling.cpp
4344
src/system_modes/mode_inference.cpp)
4445
target_include_directories(mode PUBLIC
4546
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -60,7 +61,7 @@ include_directories(../../build/system_modes/rosidl_generator_cpp/)
6061
link_directories(../../build/system_modes/)
6162
target_link_libraries(mode system_modes__rosidl_typesupport_cpp)
6263

63-
# Causes the visibility macros to use dllexport rather than dllimport,
64+
# Causes the visibility macros to use dllexport rather than dllimport,
6465
# which is appropriate when building the dll but not consuming it.
6566
target_compile_definitions(mode PRIVATE "SYSTEMMODES_BUILDING_LIBRARY")
6667

@@ -105,9 +106,6 @@ if(BUILD_TESTING)
105106
# the following line skips the linter which checks for copyrights
106107
# remove the line when a copyright and license is present in all source files
107108
set(ament_cmake_copyright_FOUND TRUE)
108-
# the following line skips cpplint (only works in a git repo)
109-
# remove the line when this package is a git repo
110-
set(ament_cmake_cpplint_FOUND TRUE)
111109
ament_lint_auto_find_test_dependencies()
112110

113111
set(MODE_FILE_CORRECT ${CMAKE_CURRENT_SOURCE_DIR}/test/test_modes.yaml)

system_modes/README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
General information about this repository, including legal information, project context, build instructions and known issues/limitations, are given in [README.md](../README.md) in the repository root.
2-
31
# ROS 2 System Modes
42

53
The system modes concept assumes that a robotics system is built from components with a lifecycle. It adds a notion of (sub-)systems, hiararchically grouping these nodes, as well as a notion of *modes* that determine the configuration of these nodes and (sub-)systems in terms of their parameter values.
64

75
A list of (current and future) requirements for system modes can be found here: [requirements](./doc/requirements.md#system-runtime-configuration).
86

7+
General information about this repository, including legal information, project context, build instructions and known issues/limitations, are given in [README.md](../README.md) in the repository root.
8+
99
## System Modes Package
1010

1111
The system modes concept is implemented as a package for ROS 2. This package provides a library for system mode inference, a mode manager, and a mode monitor.
@@ -105,7 +105,7 @@ The mode manager is a ROS node that accepts an SHM file (see [above](#system-mod
105105
* `/{system_or_node}/transition_request_info` - lifecycle_msgs/TransitionEvent
106106
* `/{system_or_node}/mode_request_info` - [system_modes/ModeEvent](./msg/ModeEvent.msg)
107107

108-
Running the manager:
108+
Running the manager:
109109
$ `ros2 launch system_modes mode_manager.launch.py modelfile:=[path/to/modelfile.yaml]`
110110

111111
### Mode Monitor
@@ -118,9 +118,23 @@ The mode monitor is a ROS node that accepts an SHM file (see [above](#system-mod
118118

119119
![mode_monitor](../system_modes_examples/doc/screenshot-monitor.png "Screenshot of the mode monitor from system_modes_examples")
120120

121-
Running the monitor:
121+
Running the monitor:
122122
$ `ros2 launch system_modes mode_monitor.launch.py modelfile:=[path/to/modelfile.yaml]`
123123

124+
### Error Handling and Rules
125+
126+
If the _actual_ state/mode of the system or any of its parts diverges from the _target_ state/mode, we define rules that try to bring the system back to a valid _target_ state/mode, e.g., a degraded mode. Rules work in a bottom-up manner, i.e. starting from correcting nodes before sub-systems before systems. Rules are basically defined in the following way:
127+
128+
```pseudo
129+
if:
130+
system.target == {target state/mode} && system.actual != {target state/mode} && part.actual == {specific state/mode}
131+
then:
132+
system.target := {specific state/mode}
133+
```
134+
135+
if _actual_ state/mode and _target_ state/mode diverge, but there is no rule for this exact situation, the bottom-up rules will just try to return the system/part to its _target_ state/mode.
136+
*Potentiall dangereous, to be discussed:* what's happening, if the system is already on its way. E.g., a system or part was just commanded to transition to _ACTIVE.foo_, but is currently _activating_ (so doing everything right). In this case we have to avoid that the bottom-up rules will trigger.
137+
124138
## How to Apply
125139

126140
When designing the hierarchy of your system, try to group parts semantically, e.g., everything that belongs to *perception* or *navigation*. You want to group those parts of a system that are often jointly managed (initialized, shutdown, configured). Hierarchies don't necessarily need to be designed in one big tree, but can form several parallel trees.

system_modes/changelog.rst

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
1-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2-
Changelog for package system_modes
3-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2+
Changelog for package system_modes_examples
3+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
5+
0.4.2 (2020-12-17)
6+
-----------
7+
* Error handling and rules feature no longer experimental
8+
* Fixed bugs in monitor and tests
9+
10+
0.4.1 (2020-10-29)
11+
-----------
12+
* Include experimental error handling and rules feature
13+
* https://github.com/micro-ROS/system_modes/issues/13
14+
* CI for ubuntu 20.04 ROS 2 rolling
15+
16+
0.4.0 (2020-09-30)
17+
-----------
18+
* publish inferred state and mode transitions
19+
* https://github.com/micro-ROS/system_modes/issues/42
20+
21+
0.4.0 (2020-09-30)
22+
-----------
23+
* mode event now including start and goal mode
24+
* publish inferred state and mode transitions
25+
* https://github.com/micro-ROS/system_modes/issues/42
426

527
0.4.0 (2020-09-30)
628
-----------

system_modes/include/system_modes/mode.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "system_modes/mode_impl.hpp"
1818

19+
#include <rclcpp/macros.hpp>
1920
#include <rclcpp/node_interfaces/node_parameters.hpp>
2021
#include <rclcpp/parameter_map.hpp>
2122

@@ -46,6 +47,7 @@ class ModeBase
4647
public:
4748
explicit ModeBase(const std::string & mode_name);
4849
virtual ~ModeBase() = default;
50+
// cppcheck-suppress unknownMacro
4951
RCLCPP_DISABLE_COPY(ModeBase)
5052

5153
std::string get_name() const;
@@ -74,6 +76,7 @@ class DefaultMode : public ModeBase
7476
public:
7577
DefaultMode();
7678
explicit DefaultMode(const std::string & mode_name) = delete;
79+
// cppcheck-suppress unknownMacro
7780
RCLCPP_DISABLE_COPY(DefaultMode)
7881

7982
virtual void set_parameter(const rclcpp::Parameter & parameter);
@@ -89,6 +92,7 @@ class Mode : public ModeBase
8992
public:
9093
explicit Mode(const std::string & mode_name) = delete;
9194
Mode(const std::string & mode_name, const DefaultModePtr default_mode);
95+
// cppcheck-suppress unknownMacro
9296
RCLCPP_DISABLE_COPY(Mode)
9397

9498
virtual ~Mode() = default;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2018 - for information on the respective copyright owner
2+
// see the NOTICE file and/or the repository https://github.com/microros/system_modes
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
#pragma once
16+
17+
#include <stdint.h>
18+
#include <shared_mutex>
19+
#include <rclcpp/parameter.hpp>
20+
#include <rclcpp/parameter_map.hpp>
21+
22+
#include <map>
23+
#include <mutex>
24+
#include <string>
25+
#include <memory>
26+
#include <vector>
27+
#include <utility>
28+
29+
#include "system_modes/mode.hpp"
30+
#include "system_modes/mode_impl.hpp"
31+
32+
namespace system_modes
33+
{
34+
35+
struct ModeRule
36+
{
37+
std::string name;
38+
39+
std::string system;
40+
StateAndMode system_target;
41+
42+
std::string part;
43+
StateAndMode part_actual;
44+
45+
StateAndMode new_system_target;
46+
};
47+
48+
using RulesMap = std::map<std::string, ModeRule>;
49+
50+
class ModeHandling
51+
{
52+
public:
53+
explicit ModeHandling(const std::string & model_path);
54+
// cppcheck-suppress unknownMacro
55+
RCLCPP_DISABLE_COPY(ModeHandling)
56+
57+
virtual ~ModeHandling() = default;
58+
virtual const std::vector<ModeRule> get_rules_for(
59+
const std::string & system,
60+
const StateAndMode & target);
61+
62+
protected:
63+
mutable std::shared_timed_mutex rules_mutex_;
64+
65+
private:
66+
std::map<std::string, RulesMap> rules_;
67+
68+
virtual void read_rules_from_model(const std::string & model_path);
69+
virtual void add_rule(
70+
const std::string & part,
71+
const std::string & rule_name,
72+
const rclcpp::Parameter & rule_param);
73+
};
74+
75+
} // namespace system_modes

0 commit comments

Comments
 (0)