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

Use node interfaces in iron to avoid templated ComponentInterface #41

Merged
merged 3 commits into from
Jul 18, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Release Versions:

## Upcoming changes (in development)

- Revise ComponentInterface by moving implementations to source file (#39)
- Update component classes to inherit from new ComponentInterface (#38)
- Refactor ComponentInterface to use node interfaces (#33)
- Refactor component predicates with a single Predicate publisher (#26)
- Add and install component descriptions (#31)
- Apply AICA C++ style guide (#30)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.10
2.2.13
2 changes: 1 addition & 1 deletion doxygen/doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Modulo"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.2.10
PROJECT_NUMBER = 2.2.13

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion source/modulo_component_interfaces/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>modulo_component_interfaces</name>
<version>2.2.10</version>
<version>2.2.13</version>
<description>Interface package for communicating with modulo components through the ROS framework</description>
<maintainer email="[email protected]">Enrico Eberhard</maintainer>
<license>GPLv3</license>
Expand Down
1 change: 1 addition & 0 deletions source/modulo_components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ament_auto_find_build_dependencies()
include_directories(include)

ament_auto_add_library(${PROJECT_NAME} SHARED
${PROJECT_SOURCE_DIR}/src/ComponentInterface.cpp
${PROJECT_SOURCE_DIR}/src/Component.cpp
${PROJECT_SOURCE_DIR}/src/LifecycleComponent.cpp)

Expand Down
35 changes: 17 additions & 18 deletions source/modulo_components/include/modulo_components/Component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include <rclcpp/node.hpp>

#include "modulo_components/ComponentInterface.hpp"
#include "modulo_components/utilities/utilities.hpp"
#include "modulo_core/EncodedState.hpp"
#include "modulo_core/exceptions/CoreException.hpp"

namespace modulo_components {

Expand All @@ -23,7 +20,7 @@ namespace modulo_components {
* constructor.
* @see LifecycleComponent for a state-based composition alternative
*/
class Component : public ComponentInterface<rclcpp::Node> {
class Component : public rclcpp::Node, public ComponentInterface {
public:
friend class ComponentPublicInterface;

Expand Down Expand Up @@ -79,13 +76,14 @@ class Component : public ComponentInterface<rclcpp::Node> {
void on_execute();

// TODO hide ROS methods
using ComponentInterface<rclcpp::Node>::create_output;
using ComponentInterface<rclcpp::Node>::inputs_;
using ComponentInterface<rclcpp::Node>::outputs_;
using ComponentInterface<rclcpp::Node>::qos_;
using ComponentInterface<rclcpp::Node>::publish_predicates;
using ComponentInterface<rclcpp::Node>::publish_outputs;
using ComponentInterface<rclcpp::Node>::evaluate_periodic_callbacks;
using ComponentInterface::create_output;
using ComponentInterface::inputs_;
using ComponentInterface::outputs_;
using ComponentInterface::periodic_outputs_;
using ComponentInterface::publish_predicate;
using ComponentInterface::publish_predicates;
using ComponentInterface::publish_outputs;
using ComponentInterface::evaluate_periodic_callbacks;

std::thread execute_thread_; ///< The execution thread of the component
bool started_; ///< Flag that indicates if execution has started or not
Expand All @@ -98,50 +96,51 @@ inline void Component::add_output(
) {
using namespace modulo_core::communication;
try {
auto parsed_signal_name = this->create_output(signal_name, data, default_topic, fixed_topic, publish_on_step);
auto parsed_signal_name =
this->create_output(PublisherType::PUBLISHER, signal_name, data, default_topic, fixed_topic, publish_on_step);
auto topic_name = this->get_parameter_value<std::string>(parsed_signal_name + "_topic");
RCLCPP_DEBUG_STREAM(this->get_logger(),
"Adding output '" << parsed_signal_name << "' with topic name '" << topic_name << "'.");
auto message_pair = this->outputs_.at(parsed_signal_name)->get_message_pair();
switch (message_pair->get_type()) {
case MessageType::BOOL: {
auto publisher = this->create_publisher<std_msgs::msg::Bool>(topic_name, this->qos_);
auto publisher = this->create_publisher<std_msgs::msg::Bool>(topic_name, this->get_qos());
this->outputs_.at(parsed_signal_name) =
std::make_shared<PublisherHandler<rclcpp::Publisher<std_msgs::msg::Bool>, std_msgs::msg::Bool>>(
PublisherType::PUBLISHER, publisher)->create_publisher_interface(message_pair);
break;
}
case MessageType::FLOAT64: {
auto publisher = this->create_publisher<std_msgs::msg::Float64>(topic_name, this->qos_);
auto publisher = this->create_publisher<std_msgs::msg::Float64>(topic_name, this->get_qos());
this->outputs_.at(parsed_signal_name) =
std::make_shared<PublisherHandler<rclcpp::Publisher<std_msgs::msg::Float64>, std_msgs::msg::Float64>>(
PublisherType::PUBLISHER, publisher)->create_publisher_interface(message_pair);
break;
}
case MessageType::FLOAT64_MULTI_ARRAY: {
auto publisher = this->create_publisher<std_msgs::msg::Float64MultiArray>(topic_name, this->qos_);
auto publisher = this->create_publisher<std_msgs::msg::Float64MultiArray>(topic_name, this->get_qos());
this->outputs_.at(parsed_signal_name) = std::make_shared<
PublisherHandler<
rclcpp::Publisher<std_msgs::msg::Float64MultiArray>, std_msgs::msg::Float64MultiArray>>(
PublisherType::PUBLISHER, publisher)->create_publisher_interface(message_pair);
break;
}
case MessageType::INT32: {
auto publisher = this->create_publisher<std_msgs::msg::Int32>(topic_name, this->qos_);
auto publisher = this->create_publisher<std_msgs::msg::Int32>(topic_name, this->get_qos());
this->outputs_.at(parsed_signal_name) =
std::make_shared<PublisherHandler<rclcpp::Publisher<std_msgs::msg::Int32>, std_msgs::msg::Int32>>(
PublisherType::PUBLISHER, publisher)->create_publisher_interface(message_pair);
break;
}
case MessageType::STRING: {
auto publisher = this->create_publisher<std_msgs::msg::String>(topic_name, this->qos_);
auto publisher = this->create_publisher<std_msgs::msg::String>(topic_name, this->get_qos());
this->outputs_.at(parsed_signal_name) =
std::make_shared<PublisherHandler<rclcpp::Publisher<std_msgs::msg::String>, std_msgs::msg::String>>(
PublisherType::PUBLISHER, publisher)->create_publisher_interface(message_pair);
break;
}
case MessageType::ENCODED_STATE: {
auto publisher = this->create_publisher<modulo_core::EncodedState>(topic_name, this->qos_);
auto publisher = this->create_publisher<modulo_core::EncodedState>(topic_name, this->get_qos());
this->outputs_.at(parsed_signal_name) =
std::make_shared<PublisherHandler<rclcpp::Publisher<modulo_core::EncodedState>, modulo_core::EncodedState>>(
PublisherType::PUBLISHER, publisher)->create_publisher_interface(message_pair);
Expand Down
Loading