Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Separate interface package system_modes_msgs #74

Merged
merged 7 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 4 additions & 25 deletions system_modes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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()
28 changes: 14 additions & 14 deletions system_modes/include/system_modes/mode_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -68,14 +68,14 @@ class ModeManager : public rclcpp::Node
// Mode service callbacks
virtual void on_change_mode(
const std::string &,
const std::shared_ptr<system_modes::srv::ChangeMode::Request>,
std::shared_ptr<system_modes::srv::ChangeMode::Response>);
const std::shared_ptr<system_modes_msgs::srv::ChangeMode::Request>,
std::shared_ptr<system_modes_msgs::srv::ChangeMode::Response>);
virtual void on_get_mode(
const std::string &,
std::shared_ptr<system_modes::srv::GetMode::Response>);
std::shared_ptr<system_modes_msgs::srv::GetMode::Response>);
virtual void on_get_available_modes(
const std::string &,
std::shared_ptr<system_modes::srv::GetAvailableModes::Response>);
std::shared_ptr<system_modes_msgs::srv::GetAvailableModes::Response>);

virtual bool change_state(
const std::string &,
Expand Down Expand Up @@ -109,17 +109,17 @@ class ModeManager : public rclcpp::Node
states_srv_;

// Mode change services
std::map<std::string, rclcpp::Service<system_modes::srv::ChangeMode>::SharedPtr>
std::map<std::string, rclcpp::Service<system_modes_msgs::srv::ChangeMode>::SharedPtr>
mode_change_srv_;
std::map<std::string, rclcpp::Service<system_modes::srv::GetMode>::SharedPtr>
std::map<std::string, rclcpp::Service<system_modes_msgs::srv::GetMode>::SharedPtr>
get_mode_srv_;
std::map<std::string, rclcpp::Service<system_modes::srv::GetAvailableModes>::SharedPtr>
std::map<std::string, rclcpp::Service<system_modes_msgs::srv::GetAvailableModes>::SharedPtr>
modes_srv_;

// Lifecycle / Mode / Parameter service clients
std::map<std::string, rclcpp::Client<lifecycle_msgs::srv::ChangeState>::SharedPtr>
state_change_clients_;
std::map<std::string, rclcpp::Client<system_modes::srv::ChangeMode>::SharedPtr>
std::map<std::string, rclcpp::Client<system_modes_msgs::srv::ChangeMode>::SharedPtr>
mode_change_clients_;
std::map<std::string, rclcpp::AsyncParametersClient::SharedPtr>
param_change_clients_;
Expand All @@ -131,9 +131,9 @@ class ModeManager : public rclcpp::Node
state_request_pub_;

// Mode transition publisher
std::map<std::string, rclcpp::Publisher<system_modes::msg::ModeEvent>::SharedPtr>
std::map<std::string, rclcpp::Publisher<system_modes_msgs::msg::ModeEvent>::SharedPtr>
mode_transition_pub_;
std::map<std::string, rclcpp::Publisher<system_modes::msg::ModeEvent>::SharedPtr>
std::map<std::string, rclcpp::Publisher<system_modes_msgs::msg::ModeEvent>::SharedPtr>
mode_request_pub_;

// Remember states and modes of the systems
Expand Down
8 changes: 4 additions & 4 deletions system_modes/include/system_modes/mode_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 4 additions & 4 deletions system_modes/include/system_modes/mode_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include <utility>

#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
{
Expand All @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions system_modes/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
<depend>builtin_interfaces</depend>
<depend>rclcpp</depend>
<depend>rclcpp_lifecycle</depend>
<depend>rosidl_default_generators</depend>
<depend>std_msgs</depend>
<depend>system_modes_msgs</depend>

<exec_depend>launch_ros</exec_depend>

Expand All @@ -36,8 +35,6 @@
<test_depend>launch_testing_ros</test_depend>
<test_depend>ros2run</test_depend>

<member_of_group>rosidl_interface_packages</member_of_group>

<export>
<build_type>ament_cmake</build_type>
</export>
Expand Down
2 changes: 1 addition & 1 deletion system_modes/src/mode_manager_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion system_modes/src/mode_monitor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 10 additions & 10 deletions system_modes/src/system_modes/mode_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <algorithm>
#include <functional>

#include "system_modes/msg/mode_event.hpp"
#include "system_modes_msgs/msg/mode_event.hpp"

using std::string;
using std::out_of_range;
Expand All @@ -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;

Expand Down Expand Up @@ -156,7 +156,7 @@ ModeManager::add_system(const std::string & system)
std::shared_ptr<GetMode::Response>)> mode_get_callback =
std::bind(&ModeManager::on_get_mode, this, system, _3);
this->get_mode_srv_[system] =
this->create_service<system_modes::srv::GetMode>(
this->create_service<system_modes_msgs::srv::GetMode>(
topic_name,
mode_get_callback);

Expand Down Expand Up @@ -211,7 +211,7 @@ ModeManager::add_node(const std::string & node)
std::shared_ptr<GetMode::Response>)> mode_get_callback =
std::bind(&ModeManager::on_get_mode, this, node, _3);
this->get_mode_srv_[node] =
this->create_service<system_modes::srv::GetMode>(
this->create_service<system_modes_msgs::srv::GetMode>(
topic_name,
mode_get_callback);

Expand Down Expand Up @@ -333,7 +333,7 @@ ModeManager::on_change_mode(
void
ModeManager::on_get_mode(
const std::string & node_name,
std::shared_ptr<system_modes::srv::GetMode::Response> response)
std::shared_ptr<system_modes_msgs::srv::GetMode::Response> 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
Expand Down Expand Up @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion system_modes/src/system_modes/mode_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions system_modes/src/system_modes/mode_observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <vector>
#include <memory>

#include "system_modes/msg/mode_event.hpp"
#include "system_modes_msgs/msg/mode_event.hpp"

using std::function;
using std::map;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion system_modes/test/launchtest/manager_and_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions system_modes/test/launchtest/modes_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion system_modes/test/launchtest/modes_observer_test_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion system_modes/test/launchtest/redundant_mode_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion system_modes/test/launchtest/two_lifecycle_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion system_modes/test/launchtest/two_mixed_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading