Skip to content

Commit 86fe634

Browse files
authored
Separate interface package system_modes_msgs (#74)
* Separate ROS 2 package for system modes interface * Documentation for system_modes_msgs * Adapt CI action 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) <arne.nordmann@de.bosch.com>
1 parent 2917384 commit 86fe634

29 files changed

Lines changed: 132 additions & 80 deletions

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
required-ros-distributions: ${{ matrix.ros_distribution }}
2525
- uses : ros-tooling/action-ros-ci@0.1.0
2626
with:
27-
package-name: "system_modes system_modes_examples"
27+
package-name: "system_modes_msgs system_modes system_modes_examples"
2828
target-ros2-distro: ${{ matrix.ros_distribution }}
2929
vcs-repo-file-url: ""
3030
colcon-mixin-name: coverage-gcc

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
[![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)
88
[![Code coverage](https://codecov.io/gh/micro-ROS/system_modes/branch/master/graph/badge.svg)](https://codecov.io/gh/micro-ROS/system_modes)
99

10-
This repository explores a system modes concept that is implemented for ROS 2 in two packages:
10+
This repository explores a system modes concept that is implemented for ROS 2 in three packages:
11+
* [system_modes_msgs](./system_modes_msgs/) provides the message types and services for system modes
1112
* [system_modes](./system_modes/) provides a library for system mode inference, a mode manager, and a mode monitor
1213
* [system_modes_examples](./system_modes_examples/) implements a simple example
1314

system_modes/CMakeLists.txt

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,12 @@ endif()
1818
# find dependencies
1919
find_package(ament_cmake REQUIRED)
2020
find_package(builtin_interfaces REQUIRED)
21-
find_package(std_msgs REQUIRED)
2221
find_package(rclcpp REQUIRED)
2322
find_package(rcl_lifecycle REQUIRED)
2423
find_package(rclcpp_lifecycle REQUIRED)
2524
find_package(rosidl_typesupport_cpp REQUIRED)
26-
find_package(rosidl_default_generators REQUIRED)
2725
find_package(lifecycle_msgs REQUIRED)
28-
29-
# generate service
30-
rosidl_generate_interfaces(${PROJECT_NAME}
31-
"msg/Mode.msg"
32-
"msg/ModeEvent.msg"
33-
"srv/ChangeMode.srv"
34-
"srv/GetMode.srv"
35-
"srv/GetAvailableModes.srv"
36-
ADD_LINTER_TESTS
37-
DEPENDENCIES builtin_interfaces
38-
)
26+
find_package(system_modes_msgs REQUIRED)
3927

4028
add_library(mode SHARED
4129
src/system_modes/mode.cpp
@@ -50,17 +38,10 @@ ament_target_dependencies(mode
5038
"rclcpp"
5139
"rcl_lifecycle"
5240
"rclcpp_lifecycle"
53-
"lifecycle_msgs"
5441
"rosidl_typesupport_cpp"
55-
"std_msgs"
56-
"builtin_interfaces"
42+
"lifecycle_msgs"
43+
"system_modes_msgs"
5744
)
58-
#rosidl_target_interfaces(mode
59-
# ${PROJECT_NAME} "rosidl_typesupport_cpp")
60-
# TODO Should work with the two lines above, but doesn't
61-
include_directories(../../build/system_modes/rosidl_generator_cpp/)
62-
link_directories(../../build/system_modes/)
63-
target_link_libraries(mode system_modes__rosidl_typesupport_cpp)
6445

6546
# Causes the visibility macros to use dllexport rather than dllimport,
6647
# which is appropriate when building the dll but not consuming it.
@@ -227,11 +208,9 @@ if(BUILD_TESTING)
227208
endif()
228209

229210
ament_export_include_directories(include)
230-
#ament_export_interfaces(export_${PROJECT_NAME})
231211
ament_export_libraries(mode)
232-
ament_export_libraries(${PROJECT_NAME}__rosidl_typesupport_introspection_cpp)
233212
ament_export_dependencies(rclcpp)
234213
ament_export_dependencies(rclcpp_lifecycle)
235214
ament_export_dependencies(lifecycle_msgs)
236-
ament_export_dependencies(std_msgs)
215+
ament_export_dependencies(system_modes_msgs)
237216
ament_package()

system_modes/include/system_modes/mode_manager.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030

3131
#include "system_modes/mode_handling.hpp"
3232
#include "system_modes/mode_inference.hpp"
33-
#include "system_modes/srv/change_mode.hpp"
34-
#include "system_modes/srv/get_mode.hpp"
35-
#include "system_modes/srv/get_available_modes.hpp"
36-
#include "system_modes/msg/mode_event.hpp"
33+
#include "system_modes_msgs/srv/change_mode.hpp"
34+
#include "system_modes_msgs/srv/get_mode.hpp"
35+
#include "system_modes_msgs/srv/get_available_modes.hpp"
36+
#include "system_modes_msgs/msg/mode_event.hpp"
3737

3838
namespace system_modes
3939
{
@@ -68,14 +68,14 @@ class ModeManager : public rclcpp::Node
6868
// Mode service callbacks
6969
virtual void on_change_mode(
7070
const std::string &,
71-
const std::shared_ptr<system_modes::srv::ChangeMode::Request>,
72-
std::shared_ptr<system_modes::srv::ChangeMode::Response>);
71+
const std::shared_ptr<system_modes_msgs::srv::ChangeMode::Request>,
72+
std::shared_ptr<system_modes_msgs::srv::ChangeMode::Response>);
7373
virtual void on_get_mode(
7474
const std::string &,
75-
std::shared_ptr<system_modes::srv::GetMode::Response>);
75+
std::shared_ptr<system_modes_msgs::srv::GetMode::Response>);
7676
virtual void on_get_available_modes(
7777
const std::string &,
78-
std::shared_ptr<system_modes::srv::GetAvailableModes::Response>);
78+
std::shared_ptr<system_modes_msgs::srv::GetAvailableModes::Response>);
7979

8080
virtual bool change_state(
8181
const std::string &,
@@ -109,17 +109,17 @@ class ModeManager : public rclcpp::Node
109109
states_srv_;
110110

111111
// Mode change services
112-
std::map<std::string, rclcpp::Service<system_modes::srv::ChangeMode>::SharedPtr>
112+
std::map<std::string, rclcpp::Service<system_modes_msgs::srv::ChangeMode>::SharedPtr>
113113
mode_change_srv_;
114-
std::map<std::string, rclcpp::Service<system_modes::srv::GetMode>::SharedPtr>
114+
std::map<std::string, rclcpp::Service<system_modes_msgs::srv::GetMode>::SharedPtr>
115115
get_mode_srv_;
116-
std::map<std::string, rclcpp::Service<system_modes::srv::GetAvailableModes>::SharedPtr>
116+
std::map<std::string, rclcpp::Service<system_modes_msgs::srv::GetAvailableModes>::SharedPtr>
117117
modes_srv_;
118118

119119
// Lifecycle / Mode / Parameter service clients
120120
std::map<std::string, rclcpp::Client<lifecycle_msgs::srv::ChangeState>::SharedPtr>
121121
state_change_clients_;
122-
std::map<std::string, rclcpp::Client<system_modes::srv::ChangeMode>::SharedPtr>
122+
std::map<std::string, rclcpp::Client<system_modes_msgs::srv::ChangeMode>::SharedPtr>
123123
mode_change_clients_;
124124
std::map<std::string, rclcpp::AsyncParametersClient::SharedPtr>
125125
param_change_clients_;
@@ -131,9 +131,9 @@ class ModeManager : public rclcpp::Node
131131
state_request_pub_;
132132

133133
// Mode transition publisher
134-
std::map<std::string, rclcpp::Publisher<system_modes::msg::ModeEvent>::SharedPtr>
134+
std::map<std::string, rclcpp::Publisher<system_modes_msgs::msg::ModeEvent>::SharedPtr>
135135
mode_transition_pub_;
136-
std::map<std::string, rclcpp::Publisher<system_modes::msg::ModeEvent>::SharedPtr>
136+
std::map<std::string, rclcpp::Publisher<system_modes_msgs::msg::ModeEvent>::SharedPtr>
137137
mode_request_pub_;
138138

139139
// Remember states and modes of the systems

system_modes/include/system_modes/mode_monitor.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
#include "system_modes/mode.hpp"
2727
#include "system_modes/mode_inference.hpp"
2828

29-
#include "system_modes/srv/change_mode.hpp"
30-
#include "system_modes/srv/get_mode.hpp"
31-
#include "system_modes/srv/get_available_modes.hpp"
32-
#include "system_modes/msg/mode_event.hpp"
29+
#include "system_modes_msgs/srv/change_mode.hpp"
30+
#include "system_modes_msgs/srv/get_mode.hpp"
31+
#include "system_modes_msgs/srv/get_available_modes.hpp"
32+
#include "system_modes_msgs/msg/mode_event.hpp"
3333

3434
namespace system_modes
3535
{

system_modes/include/system_modes/mode_observer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include <utility>
2727

2828
#include "system_modes/mode.hpp"
29-
#include "system_modes/msg/mode_event.hpp"
30-
#include "system_modes/srv/get_mode.hpp"
29+
#include "system_modes_msgs/msg/mode_event.hpp"
30+
#include "system_modes_msgs/srv/get_mode.hpp"
3131

3232
namespace system_modes
3333
{
@@ -39,8 +39,8 @@ using std::string;
3939
using lifecycle_msgs::msg::TransitionEvent;
4040
using lifecycle_msgs::srv::GetState;
4141
using rclcpp::node_interfaces::NodeBaseInterface;
42-
using system_modes::msg::ModeEvent;
43-
using system_modes::srv::GetMode;
42+
using system_modes_msgs::msg::ModeEvent;
43+
using system_modes_msgs::srv::GetMode;
4444

4545
/**
4646
* Mode observer provides a local system modes cache.

system_modes/package.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
<depend>builtin_interfaces</depend>
1919
<depend>rclcpp</depend>
2020
<depend>rclcpp_lifecycle</depend>
21-
<depend>rosidl_default_generators</depend>
22-
<depend>std_msgs</depend>
21+
<depend>system_modes_msgs</depend>
2322

2423
<exec_depend>launch_ros</exec_depend>
2524

@@ -36,8 +35,6 @@
3635
<test_depend>launch_testing_ros</test_depend>
3736
<test_depend>ros2run</test_depend>
3837

39-
<member_of_group>rosidl_interface_packages</member_of_group>
40-
4138
<export>
4239
<build_type>ament_cmake</build_type>
4340
</export>

system_modes/src/mode_manager_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ using std::shared_ptr;
3939
using system_modes::ModeManager;
4040
using system_modes::DEFAULT_MODE;
4141
using system_modes::StateAndMode;
42-
using system_modes::msg::ModeEvent;
42+
using system_modes_msgs::msg::ModeEvent;
4343

4444
using lifecycle_msgs::msg::State;
4545
using lifecycle_msgs::msg::TransitionEvent;

system_modes/src/mode_monitor_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ using std::invalid_argument;
4343
using system_modes::ModeMonitor;
4444
using system_modes::DEFAULT_MODE;
4545
using system_modes::StateAndMode;
46-
using system_modes::msg::ModeEvent;
46+
using system_modes_msgs::msg::ModeEvent;
4747
using lifecycle_msgs::msg::State;
4848
using lifecycle_msgs::msg::TransitionEvent;
4949

system_modes/src/system_modes/mode_manager.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <algorithm>
3030
#include <functional>
3131

32-
#include "system_modes/msg/mode_event.hpp"
32+
#include "system_modes_msgs/msg/mode_event.hpp"
3333

3434
using std::string;
3535
using std::out_of_range;
@@ -46,10 +46,10 @@ using lifecycle_msgs::srv::GetState;
4646
using lifecycle_msgs::srv::ChangeState;
4747
using lifecycle_msgs::srv::GetAvailableStates;
4848

49-
using system_modes::msg::ModeEvent;
50-
using system_modes::srv::GetMode;
51-
using system_modes::srv::ChangeMode;
52-
using system_modes::srv::GetAvailableModes;
49+
using system_modes_msgs::msg::ModeEvent;
50+
using system_modes_msgs::srv::GetMode;
51+
using system_modes_msgs::srv::ChangeMode;
52+
using system_modes_msgs::srv::GetAvailableModes;
5353

5454
using namespace std::chrono_literals;
5555

@@ -156,7 +156,7 @@ ModeManager::add_system(const std::string & system)
156156
std::shared_ptr<GetMode::Response>)> mode_get_callback =
157157
std::bind(&ModeManager::on_get_mode, this, system, _3);
158158
this->get_mode_srv_[system] =
159-
this->create_service<system_modes::srv::GetMode>(
159+
this->create_service<system_modes_msgs::srv::GetMode>(
160160
topic_name,
161161
mode_get_callback);
162162

@@ -211,7 +211,7 @@ ModeManager::add_node(const std::string & node)
211211
std::shared_ptr<GetMode::Response>)> mode_get_callback =
212212
std::bind(&ModeManager::on_get_mode, this, node, _3);
213213
this->get_mode_srv_[node] =
214-
this->create_service<system_modes::srv::GetMode>(
214+
this->create_service<system_modes_msgs::srv::GetMode>(
215215
topic_name,
216216
mode_get_callback);
217217

@@ -333,7 +333,7 @@ ModeManager::on_change_mode(
333333
void
334334
ModeManager::on_get_mode(
335335
const std::string & node_name,
336-
std::shared_ptr<system_modes::srv::GetMode::Response> response)
336+
std::shared_ptr<system_modes_msgs::srv::GetMode::Response> response)
337337
{
338338
// TODO(anordman): to be on the safe side, don't use the node name from
339339
// the request, but bind it to the callback instead
@@ -532,9 +532,9 @@ ModeManager::change_part_state(const string & node, unsigned int transition)
532532
void
533533
ModeManager::change_part_mode(const string & node, const string & mode)
534534
{
535-
RCLCPP_INFO(
535+
RCLCPP_DEBUG(
536536
this->get_logger(),
537-
" changing mode of %s to %s",
537+
" changing mode of part %s to %s",
538538
node.c_str(),
539539
mode.c_str());
540540

0 commit comments

Comments
 (0)