From 734f685d0c369ef2f47353aeda43037b6e37f6f3 Mon Sep 17 00:00:00 2001 From: "Nordmann Arne (CR/ADT3)" Date: Mon, 12 Apr 2021 14:31:25 +0200 Subject: [PATCH 01/11] Separate ROS 2 package for system modes interface Separated msg and srv types into seperate package . This seems to be the ROS 2 way anyway, was requiring a hack beforehand, and seems necessary to get windows build working. Signed-off-by: Nordmann Arne (CR/ADT3) --- system_modes_msgs/CMakeLists.txt | 32 +++++++++++++++++++ .../msg/Mode.msg | 0 .../msg/ModeEvent.msg | 0 system_modes_msgs/package.xml | 28 ++++++++++++++++ .../srv/ChangeMode.srv | 0 .../srv/GetAvailableModes.srv | 0 .../srv/GetMode.srv | 0 7 files changed, 60 insertions(+) create mode 100644 system_modes_msgs/CMakeLists.txt rename {system_modes => system_modes_msgs}/msg/Mode.msg (100%) rename {system_modes => system_modes_msgs}/msg/ModeEvent.msg (100%) create mode 100644 system_modes_msgs/package.xml rename {system_modes => system_modes_msgs}/srv/ChangeMode.srv (100%) rename {system_modes => system_modes_msgs}/srv/GetAvailableModes.srv (100%) rename {system_modes => system_modes_msgs}/srv/GetMode.srv (100%) diff --git a/system_modes_msgs/CMakeLists.txt b/system_modes_msgs/CMakeLists.txt new file mode 100644 index 0000000..54b8ed6 --- /dev/null +++ b/system_modes_msgs/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.5) +project(system_modes_msgs) + +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +endif() +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +find_package(ament_cmake REQUIRED) +find_package(rosidl_default_generators REQUIRED) + +# generate service +rosidl_generate_interfaces(${PROJECT_NAME} + "msg/Mode.msg" + "msg/ModeEvent.msg" + "srv/ChangeMode.srv" + "srv/GetMode.srv" + "srv/GetAvailableModes.srv" + ADD_LINTER_TESTS +) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() +endif() + +ament_export_dependencies(rosidl_default_runtime) + +ament_package() diff --git a/system_modes/msg/Mode.msg b/system_modes_msgs/msg/Mode.msg similarity index 100% rename from system_modes/msg/Mode.msg rename to system_modes_msgs/msg/Mode.msg diff --git a/system_modes/msg/ModeEvent.msg b/system_modes_msgs/msg/ModeEvent.msg similarity index 100% rename from system_modes/msg/ModeEvent.msg rename to system_modes_msgs/msg/ModeEvent.msg diff --git a/system_modes_msgs/package.xml b/system_modes_msgs/package.xml new file mode 100644 index 0000000..a14f189 --- /dev/null +++ b/system_modes_msgs/package.xml @@ -0,0 +1,28 @@ + + + + system_modes_msgs + 0.6.0 + + 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. + + Arne Nordmann + Apache License 2.0 + + ament_cmake + + builtin_interfaces + rosidl_default_generators + + ament_lint_auto + + rosidl_interface_packages + + + ament_cmake + + diff --git a/system_modes/srv/ChangeMode.srv b/system_modes_msgs/srv/ChangeMode.srv similarity index 100% rename from system_modes/srv/ChangeMode.srv rename to system_modes_msgs/srv/ChangeMode.srv diff --git a/system_modes/srv/GetAvailableModes.srv b/system_modes_msgs/srv/GetAvailableModes.srv similarity index 100% rename from system_modes/srv/GetAvailableModes.srv rename to system_modes_msgs/srv/GetAvailableModes.srv diff --git a/system_modes/srv/GetMode.srv b/system_modes_msgs/srv/GetMode.srv similarity index 100% rename from system_modes/srv/GetMode.srv rename to system_modes_msgs/srv/GetMode.srv From 95090b40a11249eb72a87d7ae72adc3770e684ce Mon Sep 17 00:00:00 2001 From: "Nordmann Arne (CR/ADT3)" Date: Mon, 12 Apr 2021 14:33:08 +0200 Subject: [PATCH 02/11] Cleanup of system modes package Signed-off-by: Nordmann Arne (CR/ADT3) --- system_modes/CMakeLists.txt | 29 ++++------------------------- system_modes/package.xml | 4 +--- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/system_modes/CMakeLists.txt b/system_modes/CMakeLists.txt index e36da27..2c0bf30 100644 --- a/system_modes/CMakeLists.txt +++ b/system_modes/CMakeLists.txt @@ -18,24 +18,12 @@ endif() # find dependencies find_package(ament_cmake REQUIRED) find_package(builtin_interfaces REQUIRED) -find_package(std_msgs REQUIRED) find_package(rclcpp REQUIRED) find_package(rcl_lifecycle REQUIRED) find_package(rclcpp_lifecycle REQUIRED) find_package(rosidl_typesupport_cpp REQUIRED) -find_package(rosidl_default_generators REQUIRED) find_package(lifecycle_msgs REQUIRED) - -# generate service -rosidl_generate_interfaces(${PROJECT_NAME} - "msg/Mode.msg" - "msg/ModeEvent.msg" - "srv/ChangeMode.srv" - "srv/GetMode.srv" - "srv/GetAvailableModes.srv" - ADD_LINTER_TESTS - DEPENDENCIES builtin_interfaces -) +find_package(system_modes_msgs REQUIRED) add_library(mode SHARED src/system_modes/mode.cpp @@ -50,17 +38,10 @@ ament_target_dependencies(mode "rclcpp" "rcl_lifecycle" "rclcpp_lifecycle" - "lifecycle_msgs" "rosidl_typesupport_cpp" - "std_msgs" - "builtin_interfaces" + "lifecycle_msgs" + "system_modes_msgs" ) -#rosidl_target_interfaces(mode -# ${PROJECT_NAME} "rosidl_typesupport_cpp") -# TODO Should work with the two lines above, but doesn't -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, # which is appropriate when building the dll but not consuming it. @@ -227,11 +208,9 @@ if(BUILD_TESTING) endif() ament_export_include_directories(include) -#ament_export_interfaces(export_${PROJECT_NAME}) ament_export_libraries(mode) -ament_export_libraries(${PROJECT_NAME}__rosidl_typesupport_introspection_cpp) ament_export_dependencies(rclcpp) ament_export_dependencies(rclcpp_lifecycle) ament_export_dependencies(lifecycle_msgs) -ament_export_dependencies(std_msgs) +ament_export_dependencies(system_modes_msgs) ament_package() diff --git a/system_modes/package.xml b/system_modes/package.xml index 99825f0..9196e46 100644 --- a/system_modes/package.xml +++ b/system_modes/package.xml @@ -18,8 +18,8 @@ builtin_interfaces rclcpp rclcpp_lifecycle - rosidl_default_generators std_msgs + system_modes_msgs launch_ros @@ -36,8 +36,6 @@ launch_testing_ros ros2run - rosidl_interface_packages - ament_cmake From 749a8f4c8857dab246242c671ed2f36abd3b17fe Mon Sep 17 00:00:00 2001 From: "Nordmann Arne (CR/ADT3)" Date: Mon, 12 Apr 2021 14:33:37 +0200 Subject: [PATCH 03/11] Adapt packages to separated interface package Adapts system_modes and system_modes_example packages to separated system_modes_msgs interface package. Signed-off-by: Nordmann Arne (CR/ADT3) --- .../include/system_modes/mode_manager.hpp | 28 +++++++++---------- .../include/system_modes/mode_monitor.hpp | 8 +++--- .../include/system_modes/mode_observer.hpp | 8 +++--- system_modes/src/mode_manager_node.cpp | 2 +- system_modes/src/mode_monitor_node.cpp | 2 +- .../src/system_modes/mode_manager.cpp | 20 ++++++------- .../src/system_modes/mode_monitor.cpp | 2 +- .../src/system_modes/mode_observer.cpp | 6 ++-- .../test/launchtest/manager_and_monitor.py | 2 +- .../test/launchtest/modes_observer.py | 4 +-- .../launchtest/modes_observer_test_node.cpp | 2 +- .../test/launchtest/redundant_mode_changes.py | 2 +- .../launchtest/two_independent_hierarchies.py | 2 +- .../test/launchtest/two_lifecycle_nodes.py | 2 +- .../test/launchtest/two_mixed_nodes.py | 2 +- system_modes_examples/CMakeLists.txt | 3 ++ system_modes_examples/package.xml | 1 + 17 files changed, 50 insertions(+), 46 deletions(-) diff --git a/system_modes/include/system_modes/mode_manager.hpp b/system_modes/include/system_modes/mode_manager.hpp index 2c09019..4ee34f1 100644 --- a/system_modes/include/system_modes/mode_manager.hpp +++ b/system_modes/include/system_modes/mode_manager.hpp @@ -30,10 +30,10 @@ #include "system_modes/mode_handling.hpp" #include "system_modes/mode_inference.hpp" -#include "system_modes/srv/change_mode.hpp" -#include "system_modes/srv/get_mode.hpp" -#include "system_modes/srv/get_available_modes.hpp" -#include "system_modes/msg/mode_event.hpp" +#include "system_modes_msgs/srv/change_mode.hpp" +#include "system_modes_msgs/srv/get_mode.hpp" +#include "system_modes_msgs/srv/get_available_modes.hpp" +#include "system_modes_msgs/msg/mode_event.hpp" namespace system_modes { @@ -68,14 +68,14 @@ class ModeManager : public rclcpp::Node // Mode service callbacks virtual void on_change_mode( const std::string &, - const std::shared_ptr, - std::shared_ptr); + const std::shared_ptr, + std::shared_ptr); virtual void on_get_mode( const std::string &, - std::shared_ptr); + std::shared_ptr); virtual void on_get_available_modes( const std::string &, - std::shared_ptr); + std::shared_ptr); virtual bool change_state( const std::string &, @@ -109,17 +109,17 @@ class ModeManager : public rclcpp::Node states_srv_; // Mode change services - std::map::SharedPtr> + std::map::SharedPtr> mode_change_srv_; - std::map::SharedPtr> + std::map::SharedPtr> get_mode_srv_; - std::map::SharedPtr> + std::map::SharedPtr> modes_srv_; // Lifecycle / Mode / Parameter service clients std::map::SharedPtr> state_change_clients_; - std::map::SharedPtr> + std::map::SharedPtr> mode_change_clients_; std::map param_change_clients_; @@ -131,9 +131,9 @@ class ModeManager : public rclcpp::Node state_request_pub_; // Mode transition publisher - std::map::SharedPtr> + std::map::SharedPtr> mode_transition_pub_; - std::map::SharedPtr> + std::map::SharedPtr> mode_request_pub_; // Remember states and modes of the systems diff --git a/system_modes/include/system_modes/mode_monitor.hpp b/system_modes/include/system_modes/mode_monitor.hpp index 4c06c59..e23ab30 100644 --- a/system_modes/include/system_modes/mode_monitor.hpp +++ b/system_modes/include/system_modes/mode_monitor.hpp @@ -26,10 +26,10 @@ #include "system_modes/mode.hpp" #include "system_modes/mode_inference.hpp" -#include "system_modes/srv/change_mode.hpp" -#include "system_modes/srv/get_mode.hpp" -#include "system_modes/srv/get_available_modes.hpp" -#include "system_modes/msg/mode_event.hpp" +#include "system_modes_msgs/srv/change_mode.hpp" +#include "system_modes_msgs/srv/get_mode.hpp" +#include "system_modes_msgs/srv/get_available_modes.hpp" +#include "system_modes_msgs/msg/mode_event.hpp" namespace system_modes { diff --git a/system_modes/include/system_modes/mode_observer.hpp b/system_modes/include/system_modes/mode_observer.hpp index 082dde3..dfd569d 100644 --- a/system_modes/include/system_modes/mode_observer.hpp +++ b/system_modes/include/system_modes/mode_observer.hpp @@ -26,8 +26,8 @@ #include #include "system_modes/mode.hpp" -#include "system_modes/msg/mode_event.hpp" -#include "system_modes/srv/get_mode.hpp" +#include "system_modes_msgs/msg/mode_event.hpp" +#include "system_modes_msgs/srv/get_mode.hpp" namespace system_modes { @@ -39,8 +39,8 @@ using std::string; using lifecycle_msgs::msg::TransitionEvent; using lifecycle_msgs::srv::GetState; using rclcpp::node_interfaces::NodeBaseInterface; -using system_modes::msg::ModeEvent; -using system_modes::srv::GetMode; +using system_modes_msgs::msg::ModeEvent; +using system_modes_msgs::srv::GetMode; /** * Mode observer provides a local system modes cache. diff --git a/system_modes/src/mode_manager_node.cpp b/system_modes/src/mode_manager_node.cpp index a86d43a..8eca50d 100644 --- a/system_modes/src/mode_manager_node.cpp +++ b/system_modes/src/mode_manager_node.cpp @@ -39,7 +39,7 @@ using std::shared_ptr; using system_modes::ModeManager; using system_modes::DEFAULT_MODE; using system_modes::StateAndMode; -using system_modes::msg::ModeEvent; +using system_modes_msgs::msg::ModeEvent; using lifecycle_msgs::msg::State; using lifecycle_msgs::msg::TransitionEvent; diff --git a/system_modes/src/mode_monitor_node.cpp b/system_modes/src/mode_monitor_node.cpp index 514bbe4..7029de7 100644 --- a/system_modes/src/mode_monitor_node.cpp +++ b/system_modes/src/mode_monitor_node.cpp @@ -43,7 +43,7 @@ using std::invalid_argument; using system_modes::ModeMonitor; using system_modes::DEFAULT_MODE; using system_modes::StateAndMode; -using system_modes::msg::ModeEvent; +using system_modes_msgs::msg::ModeEvent; using lifecycle_msgs::msg::State; using lifecycle_msgs::msg::TransitionEvent; diff --git a/system_modes/src/system_modes/mode_manager.cpp b/system_modes/src/system_modes/mode_manager.cpp index cf5d76b..cb7b2d3 100644 --- a/system_modes/src/system_modes/mode_manager.cpp +++ b/system_modes/src/system_modes/mode_manager.cpp @@ -29,7 +29,7 @@ #include #include -#include "system_modes/msg/mode_event.hpp" +#include "system_modes_msgs/msg/mode_event.hpp" using std::string; using std::out_of_range; @@ -46,10 +46,10 @@ using lifecycle_msgs::srv::GetState; using lifecycle_msgs::srv::ChangeState; using lifecycle_msgs::srv::GetAvailableStates; -using system_modes::msg::ModeEvent; -using system_modes::srv::GetMode; -using system_modes::srv::ChangeMode; -using system_modes::srv::GetAvailableModes; +using system_modes_msgs::msg::ModeEvent; +using system_modes_msgs::srv::GetMode; +using system_modes_msgs::srv::ChangeMode; +using system_modes_msgs::srv::GetAvailableModes; using namespace std::chrono_literals; @@ -156,7 +156,7 @@ ModeManager::add_system(const std::string & system) std::shared_ptr)> mode_get_callback = std::bind(&ModeManager::on_get_mode, this, system, _3); this->get_mode_srv_[system] = - this->create_service( + this->create_service( topic_name, mode_get_callback); @@ -211,7 +211,7 @@ ModeManager::add_node(const std::string & node) std::shared_ptr)> mode_get_callback = std::bind(&ModeManager::on_get_mode, this, node, _3); this->get_mode_srv_[node] = - this->create_service( + this->create_service( topic_name, mode_get_callback); @@ -333,7 +333,7 @@ ModeManager::on_change_mode( void ModeManager::on_get_mode( const std::string & node_name, - std::shared_ptr response) + std::shared_ptr response) { // TODO(anordman): to be on the safe side, don't use the node name from // the request, but bind it to the callback instead @@ -532,9 +532,9 @@ ModeManager::change_part_state(const string & node, unsigned int transition) void ModeManager::change_part_mode(const string & node, const string & mode) { - RCLCPP_INFO( + RCLCPP_DEBUG( this->get_logger(), - " changing mode of %s to %s", + " changing mode of part %s to %s", node.c_str(), mode.c_str()); diff --git a/system_modes/src/system_modes/mode_monitor.cpp b/system_modes/src/system_modes/mode_monitor.cpp index 483ee18..eb47724 100644 --- a/system_modes/src/system_modes/mode_monitor.cpp +++ b/system_modes/src/system_modes/mode_monitor.cpp @@ -43,7 +43,7 @@ using rclcpp::ParameterMap; using lifecycle_msgs::msg::State; using lifecycle_msgs::msg::Transition; using lifecycle_msgs::msg::TransitionEvent; -using system_modes::msg::ModeEvent; +using system_modes_msgs::msg::ModeEvent; using namespace std::chrono_literals; using namespace std::literals::string_literals; diff --git a/system_modes/src/system_modes/mode_observer.cpp b/system_modes/src/system_modes/mode_observer.cpp index b4dc324..ebd9878 100644 --- a/system_modes/src/system_modes/mode_observer.cpp +++ b/system_modes/src/system_modes/mode_observer.cpp @@ -23,7 +23,7 @@ #include #include -#include "system_modes/msg/mode_event.hpp" +#include "system_modes_msgs/msg/mode_event.hpp" using std::function; using std::map; @@ -37,8 +37,8 @@ using lifecycle_msgs::msg::Transition; using lifecycle_msgs::msg::TransitionEvent; using lifecycle_msgs::srv::GetState; -using system_modes::msg::ModeEvent; -using system_modes::srv::GetMode; +using system_modes_msgs::msg::ModeEvent; +using system_modes_msgs::srv::GetMode; using namespace std::chrono_literals; using shared_mutex = std::shared_timed_mutex; diff --git a/system_modes/test/launchtest/manager_and_monitor.py b/system_modes/test/launchtest/manager_and_monitor.py index 99eb8cd..3ff9808 100644 --- a/system_modes/test/launchtest/manager_and_monitor.py +++ b/system_modes/test/launchtest/manager_and_monitor.py @@ -8,7 +8,7 @@ from rclpy.node import Node from rclpy.parameter import Parameter -from system_modes.srv import ChangeMode +from system_modes_msgs.srv import ChangeMode class FakeLifecycleNode(Node): diff --git a/system_modes/test/launchtest/modes_observer.py b/system_modes/test/launchtest/modes_observer.py index a2171c9..f1994c3 100644 --- a/system_modes/test/launchtest/modes_observer.py +++ b/system_modes/test/launchtest/modes_observer.py @@ -7,8 +7,8 @@ from rclpy.node import Node from rclpy.parameter import Parameter -from system_modes.msg import ModeEvent -from system_modes.srv import ChangeMode +from system_modes_msgs.msg import ModeEvent +from system_modes_msgs.srv import ChangeMode class FakeLifecycleNode(Node): diff --git a/system_modes/test/launchtest/modes_observer_test_node.cpp b/system_modes/test/launchtest/modes_observer_test_node.cpp index b1ba67d..3874a6c 100644 --- a/system_modes/test/launchtest/modes_observer_test_node.cpp +++ b/system_modes/test/launchtest/modes_observer_test_node.cpp @@ -40,7 +40,7 @@ using std::shared_ptr; using system_modes::ModeObserver; using system_modes::DEFAULT_MODE; using system_modes::StateAndMode; -using system_modes::msg::ModeEvent; +using system_modes_msgs::msg::ModeEvent; using lifecycle_msgs::msg::State; using lifecycle_msgs::msg::TransitionEvent; diff --git a/system_modes/test/launchtest/redundant_mode_changes.py b/system_modes/test/launchtest/redundant_mode_changes.py index 95dfa80..75e1296 100644 --- a/system_modes/test/launchtest/redundant_mode_changes.py +++ b/system_modes/test/launchtest/redundant_mode_changes.py @@ -9,7 +9,7 @@ from rclpy.node import Node from rclpy.parameter import Parameter -from system_modes.srv import ChangeMode +from system_modes_msgs.srv import ChangeMode class FakeLifecycleNode(Node): diff --git a/system_modes/test/launchtest/two_independent_hierarchies.py b/system_modes/test/launchtest/two_independent_hierarchies.py index f293929..025e4f1 100644 --- a/system_modes/test/launchtest/two_independent_hierarchies.py +++ b/system_modes/test/launchtest/two_independent_hierarchies.py @@ -8,7 +8,7 @@ from rclpy.node import Node from rclpy.parameter import Parameter -from system_modes.srv import ChangeMode +from system_modes_msgs.srv import ChangeMode class FakeLifecycleNode(Node): diff --git a/system_modes/test/launchtest/two_lifecycle_nodes.py b/system_modes/test/launchtest/two_lifecycle_nodes.py index 99eb8cd..3ff9808 100644 --- a/system_modes/test/launchtest/two_lifecycle_nodes.py +++ b/system_modes/test/launchtest/two_lifecycle_nodes.py @@ -8,7 +8,7 @@ from rclpy.node import Node from rclpy.parameter import Parameter -from system_modes.srv import ChangeMode +from system_modes_msgs.srv import ChangeMode class FakeLifecycleNode(Node): diff --git a/system_modes/test/launchtest/two_mixed_nodes.py b/system_modes/test/launchtest/two_mixed_nodes.py index 6f83674..6007dd9 100644 --- a/system_modes/test/launchtest/two_mixed_nodes.py +++ b/system_modes/test/launchtest/two_mixed_nodes.py @@ -8,7 +8,7 @@ from rclpy.node import Node from rclpy.parameter import Parameter -from system_modes.srv import ChangeMode +from system_modes_msgs.srv import ChangeMode class FakeLifecycleNode(Node): diff --git a/system_modes_examples/CMakeLists.txt b/system_modes_examples/CMakeLists.txt index c6168e6..e40afe2 100644 --- a/system_modes_examples/CMakeLists.txt +++ b/system_modes_examples/CMakeLists.txt @@ -25,6 +25,7 @@ find_package(rosidl_typesupport_cpp REQUIRED) find_package(rosidl_default_generators REQUIRED) find_package(lifecycle_msgs REQUIRED) find_package(system_modes REQUIRED) +find_package(system_modes_msgs REQUIRED) # drive_base add_executable(drive_base src/drive_base.cpp) @@ -39,6 +40,7 @@ ament_target_dependencies(drive_base "rosidl_typesupport_cpp" "std_msgs" "system_modes" + "system_modes_msgs" ) install(TARGETS drive_base EXPORT export_${PROJECT_NAME} @@ -57,6 +59,7 @@ ament_target_dependencies(manipulator "rosidl_typesupport_cpp" "std_msgs" "system_modes" + "system_modes_msgs" ) install(TARGETS manipulator EXPORT export_${PROJECT_NAME} diff --git a/system_modes_examples/package.xml b/system_modes_examples/package.xml index 4d0b3a5..b308c1f 100644 --- a/system_modes_examples/package.xml +++ b/system_modes_examples/package.xml @@ -14,6 +14,7 @@ rclcpp rclcpp_lifecycle + system_modes_msgs system_modes ros2launch From 187912d5e0350b2ab446535aa4ba37d31fb6588b Mon Sep 17 00:00:00 2001 From: "Nordmann Arne (CR/ADT3)" Date: Mon, 12 Apr 2021 14:48:55 +0200 Subject: [PATCH 04/11] Documentation for system_modes_msgs Signed-off-by: Nordmann Arne (CR/ADT3) --- README.md | 3 ++- system_modes_msgs/README.md | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 system_modes_msgs/README.md diff --git a/README.md b/README.md index c350782..d7df80c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,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) [![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: +This repository explores a system modes concept that is implemented for ROS 2 in three packages: +* [system_modes_msgs](./system_modes_msgs/) provides the message types and services for system modes * [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 diff --git a/system_modes_msgs/README.md b/system_modes_msgs/README.md new file mode 100644 index 0000000..70923dc --- /dev/null +++ b/system_modes_msgs/README.md @@ -0,0 +1,14 @@ +# ROS 2 System Modes Messages + +This package provides the message types and services for the System Modes Library. + +## Message Types + +* [msg/Mode.msg](./msg/Mode.msg) - Mode definition, along the lines of lifecycle_msgs [State](https://github.com/ros2/rcl_interfaces/blob/master/lifecycle_msgs/msg/State.msg), identifying a mode by a string. +* [msg/ModeEvent.msg](./msg/Mode.msg) - Notifies about the transition of a system mode, along the lines of lifecycle_msgs [TransitionEvent](https://github.com/ros2/rcl_interfaces/blob/master/lifecycle_msgs/msg/TransitionEvent.msg). + +## Services + +1. [src/GetMode.srv](./src/GetMode.srv) - Requests the current mode of a (sub-)system or node, along the lines of lifecycle_msgs [GetState](https://github.com/ros2/rcl_interfaces/blob/master/lifecycle_msgs/srv/GetState.srv) +2. [src/GetAvailableModes.srv](./src/GetMode.srv) - Requests all available modes of a (sub-)system or node, along the lines of lifecycle_msgs [GetAvailableStates](https://github.com/ros2/rcl_interfaces/blob/master/lifecycle_msgs/srv/GetAvailableStates.srv) +3. [src/ChangeMode.srv](./src/GetMode.srv) - Requests a change to a certain mode, along the lines of lifecycle_msgs [ChangeState](https://github.com/ros2/rcl_interfaces/blob/master/lifecycle_msgs/srv/ChangeState.srv) From 8c7c65241e16ace159b6fc58b5bc09af8d97dde9 Mon Sep 17 00:00:00 2001 From: "Nordmann Arne (CR/ADT3)" Date: Mon, 12 Apr 2021 14:49:58 +0200 Subject: [PATCH 05/11] Documentation typos Signed-off-by: Nordmann Arne (CR/ADT3) --- system_modes_msgs/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system_modes_msgs/README.md b/system_modes_msgs/README.md index 70923dc..2b6e412 100644 --- a/system_modes_msgs/README.md +++ b/system_modes_msgs/README.md @@ -9,6 +9,6 @@ This package provides the message types and services for the System Modes Librar ## Services -1. [src/GetMode.srv](./src/GetMode.srv) - Requests the current mode of a (sub-)system or node, along the lines of lifecycle_msgs [GetState](https://github.com/ros2/rcl_interfaces/blob/master/lifecycle_msgs/srv/GetState.srv) -2. [src/GetAvailableModes.srv](./src/GetMode.srv) - Requests all available modes of a (sub-)system or node, along the lines of lifecycle_msgs [GetAvailableStates](https://github.com/ros2/rcl_interfaces/blob/master/lifecycle_msgs/srv/GetAvailableStates.srv) -3. [src/ChangeMode.srv](./src/GetMode.srv) - Requests a change to a certain mode, along the lines of lifecycle_msgs [ChangeState](https://github.com/ros2/rcl_interfaces/blob/master/lifecycle_msgs/srv/ChangeState.srv) +1. [srv/GetMode.srv](./srv/GetMode.srv) - Requests the current mode of a (sub-)system or node, along the lines of lifecycle_msgs [GetState](https://github.com/ros2/rcl_interfaces/blob/master/lifecycle_msgs/srv/GetState.srv) +2. [srv/GetAvailableModes.srv](./srv/GetAvailableModes.srv) - Requests all available modes of a (sub-)system or node, along the lines of lifecycle_msgs [GetAvailableStates](https://github.com/ros2/rcl_interfaces/blob/master/lifecycle_msgs/srv/GetAvailableStates.srv) +3. [srv/ChangeMode.srv](./srv/ChangeMode.srv) - Requests a change to a certain mode, along the lines of lifecycle_msgs [ChangeState](https://github.com/ros2/rcl_interfaces/blob/master/lifecycle_msgs/srv/ChangeState.srv) From 74426a334d7d78663d5e6ca0adf95faab085ca14 Mon Sep 17 00:00:00 2001 From: "Nordmann Arne (CR/ADT3)" Date: Mon, 12 Apr 2021 15:01:41 +0200 Subject: [PATCH 06/11] Adapt CI action Signed-off-by: Nordmann Arne (CR/ADT3) --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f6d67a1..abea073 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,7 +24,7 @@ jobs: required-ros-distributions: ${{ matrix.ros_distribution }} - uses : ros-tooling/action-ros-ci@0.1.0 with: - package-name: "system_modes system_modes_examples" + package-name: "system_modes_msgs system_modes system_modes_examples" target-ros2-distro: ${{ matrix.ros_distribution }} vcs-repo-file-url: "" colcon-mixin-name: coverage-gcc From 62eadbb2655b79c632afea71fbeaa7ccf4f5d43c Mon Sep 17 00:00:00 2001 From: "Arne Nordmann (CR/AEA2)" Date: Wed, 5 May 2021 15:41:58 +0200 Subject: [PATCH 07/11] Adds visibility control Signed-off-by: Arne Nordmann (CR/AEA2) --- system_modes/CMakeLists.txt | 11 +- system_modes/include/system_modes/mode.hpp | 107 ++++++++++++---- .../include/system_modes/mode_handling.hpp | 7 + .../include/system_modes/mode_impl.hpp | 119 +++++++++++++---- .../include/system_modes/mode_inference.hpp | 120 ++++++++++++++---- .../include/system_modes/mode_manager.hpp | 77 ++++++++--- .../include/system_modes/mode_monitor.hpp | 34 +++-- .../include/system_modes/mode_observer.hpp | 11 +- .../system_modes/visibility_control.hpp | 54 ++++++++ system_modes/package.xml | 1 - system_modes/src/mode_manager_node.cpp | 15 ++- system_modes/src/system_modes/mode_impl.cpp | 5 + .../src/system_modes/mode_manager.cpp | 10 +- .../src/system_modes/mode_monitor.cpp | 4 + .../src/system_modes/mode_observer.cpp | 4 + 15 files changed, 460 insertions(+), 119 deletions(-) create mode 100644 system_modes/include/system_modes/visibility_control.hpp diff --git a/system_modes/CMakeLists.txt b/system_modes/CMakeLists.txt index 2c0bf30..c882430 100644 --- a/system_modes/CMakeLists.txt +++ b/system_modes/CMakeLists.txt @@ -18,11 +18,12 @@ endif() # find dependencies find_package(ament_cmake REQUIRED) find_package(builtin_interfaces REQUIRED) -find_package(rclcpp REQUIRED) +find_package(lifecycle_msgs REQUIRED) find_package(rcl_lifecycle REQUIRED) +find_package(rclcpp REQUIRED) find_package(rclcpp_lifecycle REQUIRED) find_package(rosidl_typesupport_cpp REQUIRED) -find_package(lifecycle_msgs REQUIRED) +find_package(std_msgs REQUIRED) find_package(system_modes_msgs REQUIRED) add_library(mode SHARED @@ -40,12 +41,12 @@ ament_target_dependencies(mode "rclcpp_lifecycle" "rosidl_typesupport_cpp" "lifecycle_msgs" + "std_msgs" "system_modes_msgs" -) - + "builtin_interfaces") # 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") +target_compile_definitions(mode PRIVATE "SYSTEM_MODES_BUILDING_LIBRARY") install( DIRECTORY include/ diff --git a/system_modes/include/system_modes/mode.hpp b/system_modes/include/system_modes/mode.hpp index 34f5e11..573a3c8 100644 --- a/system_modes/include/system_modes/mode.hpp +++ b/system_modes/include/system_modes/mode.hpp @@ -20,6 +20,8 @@ #include #include +#include "system_modes/visibility_control.hpp" + #include #include #include @@ -45,27 +47,57 @@ using ModeMap = std::map; class ModeBase { public: + SYSTEM_MODES_PUBLIC explicit ModeBase(const std::string & mode_name); + + SYSTEM_MODES_PUBLIC virtual ~ModeBase() = default; // cppcheck-suppress unknownMacro + + SYSTEM_MODES_PUBLIC RCLCPP_DISABLE_COPY(ModeBase) - std::string get_name() const; - - virtual void set_parameter(const rclcpp::Parameter & parameter) = 0; - virtual void set_parameters(const std::vector & parameters) = 0; - virtual void set_part_mode( + SYSTEM_MODES_PUBLIC + std::string + get_name() const; + + SYSTEM_MODES_PUBLIC + virtual void + set_parameter(const rclcpp::Parameter & parameter) = 0; + + SYSTEM_MODES_PUBLIC + virtual void + set_parameters(const std::vector & parameters) = 0; + + SYSTEM_MODES_PUBLIC + virtual void + set_part_mode( const std::string & part, const StateAndMode stateAndMode) = 0; - virtual rclcpp::Parameter get_parameter(const std::string & param_name) const; - virtual std::vector get_parameter_names() const; - virtual const std::vector get_parameters() const; - - virtual const std::vector get_parts() const; - virtual const StateAndMode get_part_mode(const std::string & part) const; - - virtual std::string print() const; + SYSTEM_MODES_PUBLIC + virtual rclcpp::Parameter + get_parameter(const std::string & param_name) const; + + SYSTEM_MODES_PUBLIC + virtual std::vector + get_parameter_names() const; + + SYSTEM_MODES_PUBLIC + virtual const std::vector + get_parameters() const; + + SYSTEM_MODES_PUBLIC + virtual const std::vector + get_parts() const; + + SYSTEM_MODES_PUBLIC + virtual const StateAndMode + get_part_mode(const std::string & part) const; + + SYSTEM_MODES_PUBLIC + virtual std::string + print() const; protected: ModeImpl mode_impl_; @@ -74,15 +106,25 @@ class ModeBase class DefaultMode : public ModeBase { public: + SYSTEM_MODES_PUBLIC DefaultMode(); + + SYSTEM_MODES_PUBLIC explicit DefaultMode(const std::string & mode_name) = delete; // cppcheck-suppress unknownMacro RCLCPP_DISABLE_COPY(DefaultMode) - virtual void set_parameter(const rclcpp::Parameter & parameter); - virtual void set_parameters(const std::vector & parameters); - - virtual void set_part_mode( + SYSTEM_MODES_PUBLIC + virtual void + set_parameter(const rclcpp::Parameter & parameter); + + SYSTEM_MODES_PUBLIC + virtual void + set_parameters(const std::vector & parameters); + + SYSTEM_MODES_PUBLIC + virtual void + set_part_mode( const std::string & part, const StateAndMode stateAndMode); }; @@ -90,22 +132,37 @@ class DefaultMode : public ModeBase class Mode : public ModeBase { public: - explicit Mode(const std::string & mode_name) = delete; + SYSTEM_MODES_PUBLIC + explicit + Mode(const std::string & mode_name) = delete; + + SYSTEM_MODES_PUBLIC Mode(const std::string & mode_name, const DefaultModePtr default_mode); // cppcheck-suppress unknownMacro RCLCPP_DISABLE_COPY(Mode) - virtual ~Mode() = default; - - virtual void set_parameter(const rclcpp::Parameter & parameter); - virtual void set_parameters(const std::vector & parameters); - - virtual void set_part_mode( + SYSTEM_MODES_PUBLIC + virtual + ~Mode() = default; + + SYSTEM_MODES_PUBLIC + virtual void + set_parameter(const rclcpp::Parameter & parameter); + + SYSTEM_MODES_PUBLIC + virtual void + set_parameters(const std::vector & parameters); + + SYSTEM_MODES_PUBLIC + virtual void + set_part_mode( const std::string & part, const StateAndMode stateAndMode); }; -inline std::ostream & operator<<(std::ostream & os, const Mode & mode) +SYSTEM_MODES_PUBLIC +inline std::ostream & +operator<<(std::ostream & os, const Mode & mode) { os.precision(3); os << mode.print(); diff --git a/system_modes/include/system_modes/mode_handling.hpp b/system_modes/include/system_modes/mode_handling.hpp index 1b662f8..c285558 100644 --- a/system_modes/include/system_modes/mode_handling.hpp +++ b/system_modes/include/system_modes/mode_handling.hpp @@ -16,9 +16,11 @@ #include #include + #include #include + #include #include #include @@ -28,6 +30,7 @@ #include "system_modes/mode.hpp" #include "system_modes/mode_impl.hpp" +#include "system_modes/visibility_control.hpp" namespace system_modes { @@ -50,11 +53,15 @@ using RulesMap = std::map; class ModeHandling { public: + SYSTEM_MODES_PUBLIC explicit ModeHandling(const std::string & model_path); // cppcheck-suppress unknownMacro RCLCPP_DISABLE_COPY(ModeHandling) + SYSTEM_MODES_PUBLIC virtual ~ModeHandling() = default; + + SYSTEM_MODES_PUBLIC virtual const std::vector get_rules_for( const std::string & system, const StateAndMode & target); diff --git a/system_modes/include/system_modes/mode_impl.hpp b/system_modes/include/system_modes/mode_impl.hpp index 39863f4..e94c975 100644 --- a/system_modes/include/system_modes/mode_impl.hpp +++ b/system_modes/include/system_modes/mode_impl.hpp @@ -19,6 +19,8 @@ #include +#include "system_modes/visibility_control.hpp" + #include #include #include @@ -34,26 +36,42 @@ namespace system_modes static const char DEFAULT_MODE[] = "__DEFAULT__"; -unsigned int state_id_(const std::string & state_label); -const std::string state_label_(unsigned int state_id); +SYSTEM_MODES_PUBLIC +unsigned int +state_id_(const std::string & state_label); + +SYSTEM_MODES_PUBLIC +const std::string +state_label_(unsigned int state_id); + +SYSTEM_MODES_PUBLIC +unsigned int +transition_id_(const std::string & transition_label); -unsigned int transition_id_(const std::string & transition_label); -const std::string transition_label_(unsigned int transition_id); +SYSTEM_MODES_PUBLIC +const std::string +transition_label_(unsigned int transition_id); -unsigned int goal_state_(unsigned int transition_id); +SYSTEM_MODES_PUBLIC +unsigned int +goal_state_(unsigned int transition_id); struct StateAndMode { unsigned int state; std::string mode; - explicit StateAndMode(unsigned int newstate = 0, const std::string & newmode = "") + SYSTEM_MODES_PUBLIC + explicit + StateAndMode(unsigned int newstate = 0, const std::string & newmode = "") { state = newstate; mode = newmode; } - bool operator==(const StateAndMode & cmp) const + SYSTEM_MODES_PUBLIC + bool + operator==(const StateAndMode & cmp) const { if (cmp.state != state) { return false; @@ -66,12 +84,16 @@ struct StateAndMode (mode.compare(DEFAULT_MODE) == 0 && cmp.mode.empty()); // DEFAULT_MODE the same } - bool operator!=(const StateAndMode & cmp) const + SYSTEM_MODES_PUBLIC + bool + operator!=(const StateAndMode & cmp) const { return !(*this == cmp); } - void from_string(const std::string & sam) + SYSTEM_MODES_PUBLIC + void + from_string(const std::string & sam) { auto dot = sam.find("."); if (dot != std::string::npos) { @@ -83,7 +105,9 @@ struct StateAndMode } } - std::string as_string() const + SYSTEM_MODES_PUBLIC + std::string + as_string() const { if (state != State::PRIMARY_STATE_ACTIVE || mode.empty()) { return state_label_(state); @@ -100,31 +124,72 @@ struct StateAndMode class ModeImpl { public: - explicit ModeImpl(const std::string & mode_name); - virtual ~ModeImpl() = default; + SYSTEM_MODES_PUBLIC + explicit + ModeImpl(const std::string & mode_name); + + SYSTEM_MODES_PUBLIC + virtual + ~ModeImpl() = default; + + SYSTEM_MODES_PUBLIC ModeImpl(const ModeImpl & copy) = delete; - virtual std::string get_name() const; - - virtual void add_parameter(const rclcpp::Parameter & parameter); - virtual void add_parameters(const std::vector & parameters); - virtual void add_part_mode( + SYSTEM_MODES_PUBLIC + virtual std::string + get_name() const; + + SYSTEM_MODES_PUBLIC + virtual void + add_parameter(const rclcpp::Parameter & parameter); + + SYSTEM_MODES_PUBLIC + virtual void + add_parameters(const std::vector & parameters); + + SYSTEM_MODES_PUBLIC + virtual void + add_part_mode( const std::string & part, const StateAndMode stateAndMode); - virtual void set_parameter(const rclcpp::Parameter & parameter); - virtual void set_parameters(const std::vector & parameters); - virtual void set_part_mode( + SYSTEM_MODES_PUBLIC + virtual void + set_parameter(const rclcpp::Parameter & parameter); + + SYSTEM_MODES_PUBLIC + virtual void + set_parameters(const std::vector & parameters); + + SYSTEM_MODES_PUBLIC + virtual void + set_part_mode( const std::string & part, const StateAndMode stateAndMode); - virtual std::vector get_parameter_names() const; - virtual rclcpp::Parameter get_parameter(const std::string & param_name) const; - virtual bool get_parameter(const std::string & param_name, rclcpp::Parameter & parameter) const; - virtual const std::vector get_parameters() const; - - virtual const std::vector get_parts() const; - virtual const StateAndMode get_part_mode(const std::string & part) const; + SYSTEM_MODES_PUBLIC + virtual std::vector + get_parameter_names() const; + + SYSTEM_MODES_PUBLIC + virtual rclcpp::Parameter + get_parameter(const std::string & param_name) const; + + SYSTEM_MODES_PUBLIC + virtual bool + get_parameter(const std::string & param_name, rclcpp::Parameter & parameter) const; + + SYSTEM_MODES_PUBLIC + virtual const std::vector + get_parameters() const; + + SYSTEM_MODES_PUBLIC + virtual const std::vector + get_parts() const; + + SYSTEM_MODES_PUBLIC + virtual const StateAndMode + get_part_mode(const std::string & part) const; protected: std::string name_; diff --git a/system_modes/include/system_modes/mode_inference.hpp b/system_modes/include/system_modes/mode_inference.hpp index b02eed1..89a3de7 100644 --- a/system_modes/include/system_modes/mode_inference.hpp +++ b/system_modes/include/system_modes/mode_inference.hpp @@ -28,6 +28,7 @@ #include "system_modes/mode.hpp" #include "system_modes/mode_handling.hpp" +#include "system_modes/visibility_control.hpp" namespace system_modes { @@ -39,28 +40,68 @@ typedef std::map> Deviation; class ModeInference { public: - explicit ModeInference(const std::string & model_path); + SYSTEM_MODES_PUBLIC + explicit + ModeInference(const std::string & model_path); // cppcheck-suppress unknownMacro RCLCPP_DISABLE_COPY(ModeInference) - virtual const std::vector get_all_parts() const; - virtual const std::vector get_nodes() const; - virtual const std::vector get_systems() const; - virtual const std::vector get_all_parts_of( + SYSTEM_MODES_PUBLIC + virtual const std::vector + get_all_parts() const; + + SYSTEM_MODES_PUBLIC + virtual const std::vector + get_nodes() const; + + SYSTEM_MODES_PUBLIC + virtual const std::vector + get_systems() const; + + SYSTEM_MODES_PUBLIC + virtual const std::vector + get_all_parts_of( const std::string & system) const; - virtual void update(const std::string &, const StateAndMode &); - virtual void update_state(const std::string &, unsigned int); - virtual void update_mode(const std::string &, const std::string &); - virtual void update_param(const std::string &, rclcpp::Parameter &); - virtual void update_target(const std::string &, StateAndMode); - - virtual StateAndMode get(const std::string & part) const; - virtual StateAndMode get_or_infer(const std::string & part); - - virtual StateAndMode infer(const std::string & part); - virtual StateAndMode infer_node(const std::string & part); - virtual StateAndMode infer_system(const std::string & part); + SYSTEM_MODES_PUBLIC + virtual void + update(const std::string &, const StateAndMode &); + + SYSTEM_MODES_PUBLIC + virtual void + update_state(const std::string &, unsigned int); + + SYSTEM_MODES_PUBLIC + virtual void + update_mode(const std::string &, const std::string &); + + SYSTEM_MODES_PUBLIC + virtual void + update_param(const std::string &, rclcpp::Parameter &); + + SYSTEM_MODES_PUBLIC + virtual void + update_target(const std::string &, StateAndMode); + + SYSTEM_MODES_PUBLIC + virtual StateAndMode + get(const std::string & part) const; + + SYSTEM_MODES_PUBLIC + virtual StateAndMode + get_or_infer(const std::string & part); + + SYSTEM_MODES_PUBLIC + virtual StateAndMode + infer(const std::string & part); + + SYSTEM_MODES_PUBLIC + virtual StateAndMode + infer_node(const std::string & part); + + SYSTEM_MODES_PUBLIC + virtual StateAndMode + infer_system(const std::string & part); /** * Infers latest transitions of systems @@ -70,19 +111,42 @@ class ModeInference * nodes publish their state transitions. For nodes, we only need to infer * mode transitions. */ - virtual Deviation infer_transitions(); - virtual Deviation get_deviation(); - - virtual StateAndMode get_target(const std::string & part) const; - virtual ModeConstPtr get_mode(const std::string & part, const std::string & mode) const; - virtual std::vector get_available_modes(const std::string & part) const; - - virtual ~ModeInference() = default; + SYSTEM_MODES_PUBLIC + virtual Deviation + infer_transitions(); + + SYSTEM_MODES_PUBLIC + virtual Deviation + get_deviation(); + + SYSTEM_MODES_PUBLIC + virtual StateAndMode + get_target(const std::string & part) const; + + SYSTEM_MODES_PUBLIC + virtual ModeConstPtr + get_mode(const std::string & part, const std::string & mode) const; + + SYSTEM_MODES_PUBLIC + virtual std::vector + get_available_modes(const std::string & part) const; + + SYSTEM_MODES_PUBLIC + virtual + ~ModeInference() = default; protected: - virtual bool matching_parameters(const rclcpp::Parameter &, const rclcpp::Parameter &) const; - virtual void read_modes_from_model(const std::string & model_path); - virtual void add_param_to_mode(ModeBasePtr, const rclcpp::Parameter &); + SYSTEM_MODES_PUBLIC + virtual bool + matching_parameters(const rclcpp::Parameter &, const rclcpp::Parameter &) const; + + SYSTEM_MODES_PUBLIC + virtual void + read_modes_from_model(const std::string & model_path); + + SYSTEM_MODES_PUBLIC + virtual void + add_param_to_mode(ModeBasePtr, const rclcpp::Parameter &); private: ModeHandling * mode_handling_; diff --git a/system_modes/include/system_modes/mode_manager.hpp b/system_modes/include/system_modes/mode_manager.hpp index 4ee34f1..0ba96c5 100644 --- a/system_modes/include/system_modes/mode_manager.hpp +++ b/system_modes/include/system_modes/mode_manager.hpp @@ -30,6 +30,7 @@ #include "system_modes/mode_handling.hpp" #include "system_modes/mode_inference.hpp" +#include "system_modes/visibility_control.hpp" #include "system_modes_msgs/srv/change_mode.hpp" #include "system_modes_msgs/srv/get_mode.hpp" #include "system_modes_msgs/srv/get_available_modes.hpp" @@ -41,63 +42,107 @@ namespace system_modes class ModeManager : public rclcpp::Node { public: + SYSTEM_MODES_PUBLIC ModeManager(); + + SYSTEM_MODES_PUBLIC ModeManager(const ModeManager &) = delete; - std::shared_ptr inference(); - virtual void handle_system_deviation(const std::string & reason); + SYSTEM_MODES_PUBLIC + virtual + ~ModeManager(); - virtual ~ModeManager() = default; + SYSTEM_MODES_PUBLIC + std::shared_ptr + inference(); + + SYSTEM_MODES_PUBLIC + virtual void + handle_system_deviation(const std::string & reason); protected: - virtual void add_system(const std::string &); - virtual void add_node(const std::string &); + SYSTEM_MODES_PUBLIC + virtual void + add_system(const std::string &); + + SYSTEM_MODES_PUBLIC + virtual void + add_node(const std::string &); // Lifecycle service callbacks - virtual void on_change_state( + SYSTEM_MODES_PUBLIC + virtual void + on_change_state( const std::string &, const std::shared_ptr, std::shared_ptr); - virtual void on_get_state( + + SYSTEM_MODES_PUBLIC + virtual void + on_get_state( const std::string &, std::shared_ptr); - virtual void on_get_available_states( + + SYSTEM_MODES_PUBLIC + virtual void + on_get_available_states( const std::string &, std::shared_ptr); // Mode service callbacks - virtual void on_change_mode( + SYSTEM_MODES_PUBLIC + virtual void + on_change_mode( const std::string &, const std::shared_ptr, std::shared_ptr); - virtual void on_get_mode( + + SYSTEM_MODES_PUBLIC + virtual void + on_get_mode( const std::string &, std::shared_ptr); - virtual void on_get_available_modes( + + SYSTEM_MODES_PUBLIC + virtual void + on_get_available_modes( const std::string &, std::shared_ptr); - virtual bool change_state( + SYSTEM_MODES_PUBLIC + virtual bool + change_state( const std::string &, unsigned int, bool transitive = true); - virtual bool change_mode( + + SYSTEM_MODES_PUBLIC + virtual bool + change_mode( const std::string &, const std::string &); - virtual void change_part_state( + SYSTEM_MODES_PUBLIC + virtual void + change_part_state( const std::string &, unsigned int); - virtual void change_part_mode( + + SYSTEM_MODES_PUBLIC + virtual void + change_part_mode( const std::string &, const std::string &); - virtual void publish_transitions(); + SYSTEM_MODES_PUBLIC + virtual void + publish_transitions(); private: std::shared_ptr mode_inference_; std::shared_ptr mode_handling_; rclcpp::TimerBase::SharedPtr periodic_timer_; + std::string model_path_; // Lifecycle change services diff --git a/system_modes/include/system_modes/mode_monitor.hpp b/system_modes/include/system_modes/mode_monitor.hpp index e23ab30..2f159b8 100644 --- a/system_modes/include/system_modes/mode_monitor.hpp +++ b/system_modes/include/system_modes/mode_monitor.hpp @@ -14,8 +14,8 @@ // limitations under the License. #pragma once -#include #include +#include #include #include @@ -25,6 +25,7 @@ #include "system_modes/mode.hpp" #include "system_modes/mode_inference.hpp" +#include "system_modes/visibility_control.hpp" #include "system_modes_msgs/srv/change_mode.hpp" #include "system_modes_msgs/srv/get_mode.hpp" @@ -37,22 +38,39 @@ namespace system_modes class ModeMonitor : public rclcpp::Node { public: + SYSTEM_MODES_PUBLIC ModeMonitor(); + + SYSTEM_MODES_PUBLIC ModeMonitor(const ModeMonitor &) = delete; - std::shared_ptr inference(); + SYSTEM_MODES_PUBLIC + virtual + ~ModeMonitor(); - virtual ~ModeMonitor() = default; + SYSTEM_MODES_PUBLIC + std::shared_ptr + inference(); protected: - virtual void refresh() const; - virtual std::string header() const; - virtual std::string format_line( + SYSTEM_MODES_PUBLIC + virtual void + refresh() const; + + SYSTEM_MODES_PUBLIC + virtual std::string + header() const; + + SYSTEM_MODES_PUBLIC + virtual std::string + format_line( const std::string &, unsigned int, unsigned int, unsigned int, const std::string &, const std::string &) const; - inline const std::string MONITOR_HLINE(const std::string & label) const; + SYSTEM_MODES_LOCAL + inline const + std::string MONITOR_HLINE(const std::string & label) const; std::shared_ptr mode_inference_; std::string model_path_; @@ -60,7 +78,7 @@ class ModeMonitor : public rclcpp::Node private: rclcpp::TimerBase::SharedPtr timer_; - unsigned int rate_; + int64_t rate_; bool clear_screen_, verbose_; }; diff --git a/system_modes/include/system_modes/mode_observer.hpp b/system_modes/include/system_modes/mode_observer.hpp index dfd569d..04aa8f3 100644 --- a/system_modes/include/system_modes/mode_observer.hpp +++ b/system_modes/include/system_modes/mode_observer.hpp @@ -52,35 +52,44 @@ using system_modes_msgs::srv::GetMode; class ModeObserver { public: + SYSTEM_MODES_PUBLIC explicit ModeObserver(std::weak_ptr); - virtual ~ModeObserver() = default; + + SYSTEM_MODES_PUBLIC + virtual + ~ModeObserver(); /** * Getter for observed state and mode. * * Returns cached observed state and mode for requested system entity (system or node). */ + SYSTEM_MODES_PUBLIC virtual StateAndMode get(const string & part_name); /** * Add part to list of observed parts. */ + SYSTEM_MODES_PUBLIC virtual void observe(const string & part_name); /** * Remove part from list of observed parts. */ + SYSTEM_MODES_PUBLIC virtual void stop_observing(const string & part_name); protected: + SYSTEM_MODES_PUBLIC virtual void transition_callback( const TransitionEvent::SharedPtr msg, const string & part_name); + SYSTEM_MODES_PUBLIC virtual void mode_event_callback( const ModeEvent::SharedPtr msg, diff --git a/system_modes/include/system_modes/visibility_control.hpp b/system_modes/include/system_modes/visibility_control.hpp new file mode 100644 index 0000000..391e8e3 --- /dev/null +++ b/system_modes/include/system_modes/visibility_control.hpp @@ -0,0 +1,54 @@ +// Copyright 2015 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +// This logic was borrowed (then namespaced) from the examples on the gcc wiki: +// https://gcc.gnu.org/wiki/Visibility + +#if defined _WIN32 || defined __CYGWIN__ + #ifdef __GNUC__ + #define SYSTEM_MODES_EXPORT __attribute__ ((dllexport)) + #define SYSTEM_MODES_IMPORT __attribute__ ((dllimport)) + #else + #define SYSTEM_MODES_EXPORT __declspec(dllexport) + #define SYSTEM_MODES_IMPORT __declspec(dllimport) + #endif + #ifdef SYSTEM_MODES_BUILDING_LIBRARY + #define SYSTEM_MODES_PUBLIC SYSTEM_MODES_EXPORT + #else + #define SYSTEM_MODES_PUBLIC SYSTEM_MODES_IMPORT + #endif + #define SYSTEM_MODES_PUBLIC_TYPE SYSTEM_MODES_PUBLIC + #define SYSTEM_MODES_LOCAL +#else + #define SYSTEM_MODES_EXPORT __attribute__ ((visibility("default"))) + #define SYSTEM_MODES_IMPORT + #if __GNUC__ >= 4 + #define SYSTEM_MODES_PUBLIC __attribute__ ((visibility("default"))) + #define SYSTEM_MODES_LOCAL __attribute__ ((visibility("hidden"))) + #else + #define SYSTEM_MODES_PUBLIC + #define SYSTEM_MODES_LOCAL + #endif + #define SYSTEM_MODES_PUBLIC_TYPE +#endif + +#ifdef __cplusplus +} +#endif diff --git a/system_modes/package.xml b/system_modes/package.xml index c60cced..409d7bd 100644 --- a/system_modes/package.xml +++ b/system_modes/package.xml @@ -15,7 +15,6 @@ ament_cmake - builtin_interfaces rclcpp rclcpp_lifecycle system_modes_msgs diff --git a/system_modes/src/mode_manager_node.cpp b/system_modes/src/mode_manager_node.cpp index 8eca50d..af355ac 100644 --- a/system_modes/src/mode_manager_node.cpp +++ b/system_modes/src/mode_manager_node.cpp @@ -49,7 +49,8 @@ using rcl_interfaces::msg::ParameterEvent; shared_ptr manager; -void transition_callback( +void +transition_callback( const TransitionEvent::SharedPtr msg, const string & node_name) { @@ -57,7 +58,8 @@ void transition_callback( manager->handle_system_deviation("transition"); } -void mode_change_callback( +void +mode_change_callback( const ModeEvent::SharedPtr msg, const string & node_name) { @@ -66,7 +68,8 @@ void mode_change_callback( manager->handle_system_deviation("mode change"); } -void transition_request_callback( +void +transition_request_callback( const TransitionEvent::SharedPtr msg, const string & node_name) { @@ -81,7 +84,8 @@ void transition_request_callback( } } -void mode_request_callback( +void +mode_request_callback( const ModeEvent::SharedPtr msg, const string & node_name) { @@ -108,7 +112,8 @@ parameter_event_callback(const ParameterEvent::SharedPtr event) manager->handle_system_deviation("parameter event"); } -int main(int argc, char * argv[]) +int +main(int argc, char * argv[]) { using namespace std::placeholders; diff --git a/system_modes/src/system_modes/mode_impl.cpp b/system_modes/src/system_modes/mode_impl.cpp index 2815118..6443003 100644 --- a/system_modes/src/system_modes/mode_impl.cpp +++ b/system_modes/src/system_modes/mode_impl.cpp @@ -222,6 +222,7 @@ static const map GOAL_STATES_ = { {Transition::TRANSITION_ACTIVE_SHUTDOWN, State::PRIMARY_STATE_FINALIZED} }; +SYSTEM_MODES_LOCAL const string state_label_(unsigned int state_id) { @@ -232,6 +233,7 @@ state_label_(unsigned int state_id) } } +SYSTEM_MODES_LOCAL unsigned int state_id_(const string & state_label) { @@ -243,6 +245,7 @@ state_id_(const string & state_label) return 0; } +SYSTEM_MODES_LOCAL const string transition_label_(unsigned int transition_id) { @@ -253,6 +256,7 @@ transition_label_(unsigned int transition_id) } } +SYSTEM_MODES_LOCAL unsigned int transition_id_(const string & transition_label) { @@ -264,6 +268,7 @@ transition_id_(const string & transition_label) throw out_of_range("Unknown transition " + transition_label); } +SYSTEM_MODES_LOCAL unsigned int goal_state_(unsigned int transition_id) { diff --git a/system_modes/src/system_modes/mode_manager.cpp b/system_modes/src/system_modes/mode_manager.cpp index cb7b2d3..43fec8b 100644 --- a/system_modes/src/system_modes/mode_manager.cpp +++ b/system_modes/src/system_modes/mode_manager.cpp @@ -101,6 +101,10 @@ ModeManager::ModeManager() }); } +ModeManager::~ModeManager() +{ +}; + std::shared_ptr ModeManager::inference() { @@ -280,7 +284,7 @@ ModeManager::on_get_state( response->current_state.id = stateAndMode.state; response->current_state.label = state_label_(stateAndMode.state); } - } catch (std::exception & ex) { + } catch (std::exception &) { response->current_state.id = State::PRIMARY_STATE_UNKNOWN; response->current_state.label = "unknown"; } @@ -341,7 +345,7 @@ ModeManager::on_get_mode( try { auto stateAndMode = this->mode_inference_->infer(node_name); response->current_mode = stateAndMode.mode; - } catch (std::exception & ex) { + } catch (std::exception &) { response->current_mode = "unknown"; } RCLCPP_INFO(this->get_logger(), " mode %s", response->current_mode.c_str()); @@ -360,7 +364,7 @@ ModeManager::on_get_available_modes( node_name.c_str()); try { response->available_modes = mode_inference_->get_available_modes(node_name); - } catch (std::exception & ex) { + } catch (std::exception &) { RCLCPP_INFO(this->get_logger(), " unknown"); } } diff --git a/system_modes/src/system_modes/mode_monitor.cpp b/system_modes/src/system_modes/mode_monitor.cpp index eb47724..cc92721 100644 --- a/system_modes/src/system_modes/mode_monitor.cpp +++ b/system_modes/src/system_modes/mode_monitor.cpp @@ -104,6 +104,10 @@ ModeMonitor::ModeMonitor() timer_ = this->create_wall_timer(std::chrono::milliseconds(rate_), [this]() {this->refresh();}); } +ModeMonitor::~ModeMonitor() +{ +} + std::shared_ptr ModeMonitor::inference() { diff --git a/system_modes/src/system_modes/mode_observer.cpp b/system_modes/src/system_modes/mode_observer.cpp index ebd9878..abf288d 100644 --- a/system_modes/src/system_modes/mode_observer.cpp +++ b/system_modes/src/system_modes/mode_observer.cpp @@ -51,6 +51,10 @@ ModeObserver::ModeObserver(std::weak_ptr handle) { } +ModeObserver::~ModeObserver() +{ +}; + StateAndMode ModeObserver::get(const std::string & part_name) { From f45b18f0ee3c8af449095e962f45538397b4ea99 Mon Sep 17 00:00:00 2001 From: "Arne Nordmann (CR/AEA2)" Date: Mon, 31 May 2021 15:56:46 +0200 Subject: [PATCH 08/11] adds pytest.ini, see https://github.com/ros2/ros2/issues/951 Signed-off-by: Arne Nordmann (CR/AEA2) --- pytest.ini | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..fe55d2e --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +junit_family=xunit2 From 41ae1ac22b02567be1f610a0c888ba8856e99065 Mon Sep 17 00:00:00 2001 From: "Nordmann Arne (CR/ADT3)" Date: Mon, 31 May 2021 16:35:31 +0200 Subject: [PATCH 09/11] Fixing compiler warnings Signed-off-by: Nordmann Arne (CR/ADT3) --- .../include/system_modes/mode_impl.hpp | 20 +++++++++---------- system_modes/src/system_modes/mode_impl.cpp | 10 +++++----- .../src/system_modes/mode_manager.cpp | 2 +- .../src/system_modes/mode_observer.cpp | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/system_modes/include/system_modes/mode_impl.hpp b/system_modes/include/system_modes/mode_impl.hpp index e94c975..9171cfd 100644 --- a/system_modes/include/system_modes/mode_impl.hpp +++ b/system_modes/include/system_modes/mode_impl.hpp @@ -127,11 +127,11 @@ class ModeImpl SYSTEM_MODES_PUBLIC explicit ModeImpl(const std::string & mode_name); - + SYSTEM_MODES_PUBLIC virtual ~ModeImpl() = default; - + SYSTEM_MODES_PUBLIC ModeImpl(const ModeImpl & copy) = delete; @@ -142,11 +142,11 @@ class ModeImpl SYSTEM_MODES_PUBLIC virtual void add_parameter(const rclcpp::Parameter & parameter); - + SYSTEM_MODES_PUBLIC virtual void add_parameters(const std::vector & parameters); - + SYSTEM_MODES_PUBLIC virtual void add_part_mode( @@ -156,11 +156,11 @@ class ModeImpl SYSTEM_MODES_PUBLIC virtual void set_parameter(const rclcpp::Parameter & parameter); - + SYSTEM_MODES_PUBLIC virtual void set_parameters(const std::vector & parameters); - + SYSTEM_MODES_PUBLIC virtual void set_part_mode( @@ -170,15 +170,15 @@ class ModeImpl SYSTEM_MODES_PUBLIC virtual std::vector get_parameter_names() const; - + SYSTEM_MODES_PUBLIC virtual rclcpp::Parameter get_parameter(const std::string & param_name) const; - + SYSTEM_MODES_PUBLIC virtual bool get_parameter(const std::string & param_name, rclcpp::Parameter & parameter) const; - + SYSTEM_MODES_PUBLIC virtual const std::vector get_parameters() const; @@ -186,7 +186,7 @@ class ModeImpl SYSTEM_MODES_PUBLIC virtual const std::vector get_parts() const; - + SYSTEM_MODES_PUBLIC virtual const StateAndMode get_part_mode(const std::string & part) const; diff --git a/system_modes/src/system_modes/mode_impl.cpp b/system_modes/src/system_modes/mode_impl.cpp index 6443003..dcc87fb 100644 --- a/system_modes/src/system_modes/mode_impl.cpp +++ b/system_modes/src/system_modes/mode_impl.cpp @@ -222,7 +222,7 @@ static const map GOAL_STATES_ = { {Transition::TRANSITION_ACTIVE_SHUTDOWN, State::PRIMARY_STATE_FINALIZED} }; -SYSTEM_MODES_LOCAL +SYSTEM_MODES_PUBLIC const string state_label_(unsigned int state_id) { @@ -233,7 +233,7 @@ state_label_(unsigned int state_id) } } -SYSTEM_MODES_LOCAL +SYSTEM_MODES_PUBLIC unsigned int state_id_(const string & state_label) { @@ -245,7 +245,7 @@ state_id_(const string & state_label) return 0; } -SYSTEM_MODES_LOCAL +SYSTEM_MODES_PUBLIC const string transition_label_(unsigned int transition_id) { @@ -256,7 +256,7 @@ transition_label_(unsigned int transition_id) } } -SYSTEM_MODES_LOCAL +SYSTEM_MODES_PUBLIC unsigned int transition_id_(const string & transition_label) { @@ -268,7 +268,7 @@ transition_id_(const string & transition_label) throw out_of_range("Unknown transition " + transition_label); } -SYSTEM_MODES_LOCAL +SYSTEM_MODES_PUBLIC unsigned int goal_state_(unsigned int transition_id) { diff --git a/system_modes/src/system_modes/mode_manager.cpp b/system_modes/src/system_modes/mode_manager.cpp index 43fec8b..b1b1b89 100644 --- a/system_modes/src/system_modes/mode_manager.cpp +++ b/system_modes/src/system_modes/mode_manager.cpp @@ -103,7 +103,7 @@ ModeManager::ModeManager() ModeManager::~ModeManager() { -}; +} std::shared_ptr ModeManager::inference() diff --git a/system_modes/src/system_modes/mode_observer.cpp b/system_modes/src/system_modes/mode_observer.cpp index abf288d..faece98 100644 --- a/system_modes/src/system_modes/mode_observer.cpp +++ b/system_modes/src/system_modes/mode_observer.cpp @@ -53,7 +53,7 @@ ModeObserver::ModeObserver(std::weak_ptr handle) ModeObserver::~ModeObserver() { -}; +} StateAndMode ModeObserver::get(const std::string & part_name) From 956c43ad4acd19f3956d674f385afc2164df6958 Mon Sep 17 00:00:00 2001 From: "Nordmann Arne (CR/ADT3)" Date: Mon, 31 May 2021 16:35:48 +0200 Subject: [PATCH 10/11] Updates github actions Signed-off-by: Nordmann Arne (CR/ADT3) --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a6c6075..93cd0fd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,7 +19,7 @@ jobs: ros_distribution: [ foxy, rolling ] steps: - uses: actions/checkout@v2.3.1 - - uses: ros-tooling/setup-ros@0.1.4 + - uses: ros-tooling/setup-ros@v0.2 with: required-ros-distributions: ${{ matrix.ros_distribution }} - uses : ros-tooling/action-ros-ci@v0.2 From 65bf94514554c0530b7db1ac1c4351948ba8017b Mon Sep 17 00:00:00 2001 From: "Nordmann Arne (CR/ADT3)" Date: Tue, 1 Jun 2021 13:21:51 +0200 Subject: [PATCH 11/11] Linting, uncrustify Signed-off-by: Nordmann Arne (CR/ADT3) --- system_modes/include/system_modes/mode.hpp | 31 ++++++++------- .../include/system_modes/mode_handling.hpp | 2 +- .../include/system_modes/mode_impl.hpp | 10 ++--- .../include/system_modes/mode_inference.hpp | 38 +++++++++---------- .../include/system_modes/mode_manager.hpp | 14 +++---- .../include/system_modes/mode_monitor.hpp | 6 +-- .../include/system_modes/mode_observer.hpp | 2 +- 7 files changed, 50 insertions(+), 53 deletions(-) diff --git a/system_modes/include/system_modes/mode.hpp b/system_modes/include/system_modes/mode.hpp index 573a3c8..12b7270 100644 --- a/system_modes/include/system_modes/mode.hpp +++ b/system_modes/include/system_modes/mode.hpp @@ -20,8 +20,6 @@ #include #include -#include "system_modes/visibility_control.hpp" - #include #include #include @@ -30,6 +28,8 @@ #include #include +#include "system_modes/visibility_control.hpp" + namespace system_modes { @@ -49,13 +49,13 @@ class ModeBase public: SYSTEM_MODES_PUBLIC explicit ModeBase(const std::string & mode_name); - + SYSTEM_MODES_PUBLIC virtual ~ModeBase() = default; + // cppcheck-suppress unknownMacro - SYSTEM_MODES_PUBLIC - RCLCPP_DISABLE_COPY(ModeBase) + RCLCPP_DISABLE_COPY(ModeBase) SYSTEM_MODES_PUBLIC std::string @@ -64,11 +64,11 @@ class ModeBase SYSTEM_MODES_PUBLIC virtual void set_parameter(const rclcpp::Parameter & parameter) = 0; - + SYSTEM_MODES_PUBLIC virtual void set_parameters(const std::vector & parameters) = 0; - + SYSTEM_MODES_PUBLIC virtual void set_part_mode( @@ -78,11 +78,11 @@ class ModeBase SYSTEM_MODES_PUBLIC virtual rclcpp::Parameter get_parameter(const std::string & param_name) const; - + SYSTEM_MODES_PUBLIC virtual std::vector get_parameter_names() const; - + SYSTEM_MODES_PUBLIC virtual const std::vector get_parameters() const; @@ -90,7 +90,7 @@ class ModeBase SYSTEM_MODES_PUBLIC virtual const std::vector get_parts() const; - + SYSTEM_MODES_PUBLIC virtual const StateAndMode get_part_mode(const std::string & part) const; @@ -108,7 +108,7 @@ class DefaultMode : public ModeBase public: SYSTEM_MODES_PUBLIC DefaultMode(); - + SYSTEM_MODES_PUBLIC explicit DefaultMode(const std::string & mode_name) = delete; // cppcheck-suppress unknownMacro @@ -117,7 +117,7 @@ class DefaultMode : public ModeBase SYSTEM_MODES_PUBLIC virtual void set_parameter(const rclcpp::Parameter & parameter); - + SYSTEM_MODES_PUBLIC virtual void set_parameters(const std::vector & parameters); @@ -133,9 +133,8 @@ class Mode : public ModeBase { public: SYSTEM_MODES_PUBLIC - explicit - Mode(const std::string & mode_name) = delete; - + explicit Mode(const std::string & mode_name) = delete; + SYSTEM_MODES_PUBLIC Mode(const std::string & mode_name, const DefaultModePtr default_mode); // cppcheck-suppress unknownMacro @@ -148,7 +147,7 @@ class Mode : public ModeBase SYSTEM_MODES_PUBLIC virtual void set_parameter(const rclcpp::Parameter & parameter); - + SYSTEM_MODES_PUBLIC virtual void set_parameters(const std::vector & parameters); diff --git a/system_modes/include/system_modes/mode_handling.hpp b/system_modes/include/system_modes/mode_handling.hpp index c285558..864c5b4 100644 --- a/system_modes/include/system_modes/mode_handling.hpp +++ b/system_modes/include/system_modes/mode_handling.hpp @@ -60,7 +60,7 @@ class ModeHandling SYSTEM_MODES_PUBLIC virtual ~ModeHandling() = default; - + SYSTEM_MODES_PUBLIC virtual const std::vector get_rules_for( const std::string & system, diff --git a/system_modes/include/system_modes/mode_impl.hpp b/system_modes/include/system_modes/mode_impl.hpp index 9171cfd..6f3aac6 100644 --- a/system_modes/include/system_modes/mode_impl.hpp +++ b/system_modes/include/system_modes/mode_impl.hpp @@ -19,8 +19,6 @@ #include -#include "system_modes/visibility_control.hpp" - #include #include #include @@ -28,6 +26,8 @@ #include #include +#include "system_modes/visibility_control.hpp" + using lifecycle_msgs::msg::State; namespace system_modes @@ -62,8 +62,7 @@ struct StateAndMode std::string mode; SYSTEM_MODES_PUBLIC - explicit - StateAndMode(unsigned int newstate = 0, const std::string & newmode = "") + explicit StateAndMode(unsigned int newstate = 0, const std::string & newmode = "") { state = newstate; mode = newmode; @@ -125,8 +124,7 @@ class ModeImpl { public: SYSTEM_MODES_PUBLIC - explicit - ModeImpl(const std::string & mode_name); + explicit ModeImpl(const std::string & mode_name); SYSTEM_MODES_PUBLIC virtual diff --git a/system_modes/include/system_modes/mode_inference.hpp b/system_modes/include/system_modes/mode_inference.hpp index 89a3de7..965f121 100644 --- a/system_modes/include/system_modes/mode_inference.hpp +++ b/system_modes/include/system_modes/mode_inference.hpp @@ -41,23 +41,23 @@ class ModeInference { public: SYSTEM_MODES_PUBLIC - explicit - ModeInference(const std::string & model_path); + explicit ModeInference(const std::string & model_path); + // cppcheck-suppress unknownMacro RCLCPP_DISABLE_COPY(ModeInference) SYSTEM_MODES_PUBLIC virtual const std::vector get_all_parts() const; - + SYSTEM_MODES_PUBLIC virtual const std::vector get_nodes() const; - + SYSTEM_MODES_PUBLIC virtual const std::vector get_systems() const; - + SYSTEM_MODES_PUBLIC virtual const std::vector get_all_parts_of( @@ -66,27 +66,27 @@ class ModeInference SYSTEM_MODES_PUBLIC virtual void update(const std::string &, const StateAndMode &); - + SYSTEM_MODES_PUBLIC virtual void update_state(const std::string &, unsigned int); - + SYSTEM_MODES_PUBLIC virtual void update_mode(const std::string &, const std::string &); - + SYSTEM_MODES_PUBLIC virtual void update_param(const std::string &, rclcpp::Parameter &); - + SYSTEM_MODES_PUBLIC virtual void - update_target(const std::string &, StateAndMode); + update_target(const std::string &, StateAndMode); SYSTEM_MODES_PUBLIC virtual StateAndMode get(const std::string & part) const; - + SYSTEM_MODES_PUBLIC virtual StateAndMode get_or_infer(const std::string & part); @@ -94,11 +94,11 @@ class ModeInference SYSTEM_MODES_PUBLIC virtual StateAndMode infer(const std::string & part); - + SYSTEM_MODES_PUBLIC virtual StateAndMode infer_node(const std::string & part); - + SYSTEM_MODES_PUBLIC virtual StateAndMode infer_system(const std::string & part); @@ -114,7 +114,7 @@ class ModeInference SYSTEM_MODES_PUBLIC virtual Deviation infer_transitions(); - + SYSTEM_MODES_PUBLIC virtual Deviation get_deviation(); @@ -122,11 +122,11 @@ class ModeInference SYSTEM_MODES_PUBLIC virtual StateAndMode get_target(const std::string & part) const; - + SYSTEM_MODES_PUBLIC virtual ModeConstPtr get_mode(const std::string & part, const std::string & mode) const; - + SYSTEM_MODES_PUBLIC virtual std::vector get_available_modes(const std::string & part) const; @@ -139,14 +139,14 @@ class ModeInference SYSTEM_MODES_PUBLIC virtual bool matching_parameters(const rclcpp::Parameter &, const rclcpp::Parameter &) const; - + SYSTEM_MODES_PUBLIC virtual void read_modes_from_model(const std::string & model_path); - + SYSTEM_MODES_PUBLIC virtual void - add_param_to_mode(ModeBasePtr, const rclcpp::Parameter &); + add_param_to_mode(ModeBasePtr, const rclcpp::Parameter &); private: ModeHandling * mode_handling_; diff --git a/system_modes/include/system_modes/mode_manager.hpp b/system_modes/include/system_modes/mode_manager.hpp index 0ba96c5..975439a 100644 --- a/system_modes/include/system_modes/mode_manager.hpp +++ b/system_modes/include/system_modes/mode_manager.hpp @@ -44,7 +44,7 @@ class ModeManager : public rclcpp::Node public: SYSTEM_MODES_PUBLIC ModeManager(); - + SYSTEM_MODES_PUBLIC ModeManager(const ModeManager &) = delete; @@ -55,7 +55,7 @@ class ModeManager : public rclcpp::Node SYSTEM_MODES_PUBLIC std::shared_ptr inference(); - + SYSTEM_MODES_PUBLIC virtual void handle_system_deviation(const std::string & reason); @@ -64,7 +64,7 @@ class ModeManager : public rclcpp::Node SYSTEM_MODES_PUBLIC virtual void add_system(const std::string &); - + SYSTEM_MODES_PUBLIC virtual void add_node(const std::string &); @@ -96,13 +96,13 @@ class ModeManager : public rclcpp::Node const std::string &, const std::shared_ptr, std::shared_ptr); - + SYSTEM_MODES_PUBLIC virtual void on_get_mode( const std::string &, std::shared_ptr); - + SYSTEM_MODES_PUBLIC virtual void on_get_available_modes( @@ -115,7 +115,7 @@ class ModeManager : public rclcpp::Node const std::string &, unsigned int, bool transitive = true); - + SYSTEM_MODES_PUBLIC virtual bool change_mode( @@ -127,7 +127,7 @@ class ModeManager : public rclcpp::Node change_part_state( const std::string &, unsigned int); - + SYSTEM_MODES_PUBLIC virtual void change_part_mode( diff --git a/system_modes/include/system_modes/mode_monitor.hpp b/system_modes/include/system_modes/mode_monitor.hpp index 2f159b8..09dd727 100644 --- a/system_modes/include/system_modes/mode_monitor.hpp +++ b/system_modes/include/system_modes/mode_monitor.hpp @@ -40,7 +40,7 @@ class ModeMonitor : public rclcpp::Node public: SYSTEM_MODES_PUBLIC ModeMonitor(); - + SYSTEM_MODES_PUBLIC ModeMonitor(const ModeMonitor &) = delete; @@ -56,11 +56,11 @@ class ModeMonitor : public rclcpp::Node SYSTEM_MODES_PUBLIC virtual void refresh() const; - + SYSTEM_MODES_PUBLIC virtual std::string header() const; - + SYSTEM_MODES_PUBLIC virtual std::string format_line( diff --git a/system_modes/include/system_modes/mode_observer.hpp b/system_modes/include/system_modes/mode_observer.hpp index 04aa8f3..6ec4ca1 100644 --- a/system_modes/include/system_modes/mode_observer.hpp +++ b/system_modes/include/system_modes/mode_observer.hpp @@ -54,7 +54,7 @@ class ModeObserver public: SYSTEM_MODES_PUBLIC explicit ModeObserver(std::weak_ptr); - + SYSTEM_MODES_PUBLIC virtual ~ModeObserver();