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

Refactor ComponentInterface to use node interfaces #33

Merged
merged 9 commits into from
Jul 11, 2023

Conversation

domire8
Copy link
Member

@domire8 domire8 commented May 31, 2023

Description

This is kind of a long shot and has low priority, but I wanted to write it down while it's fresh.

Even though the changes are big, they are not as complex in my opinion. What you need to do is get a pointer to all node interfaces rclcpp::node_interfaces::NodeInterfaces<ALL_RCLCPP_NODE_INTERFACES> to be able to replace all occurrences of NodeT::foo.

So basically, most of the changes are in the style of this->get_logger() that becomes this->node_logging_->get_logger() (same for parameters, clock). Services and subscriptions are slightly more complicated, you have to do

auto subscription = rclcpp::create_subscription<modulo_core::EncodedState>(
            this->node_parameters_, this->node_topics_, topic_name, this->qos_,
            subscription_handler->get_callback(user_callback));

i.e. you have to work with the node_parameters_ and node_topics_ interfaces.

Another nice consequence is that the PublisherType does not have to be a class attribute anymore, but can just be passed as an argument to create_output. Apart from that, I just updated the tests (that got much simpler without these if else blocks based on the TypeParam).

The CI will not build obviously though.

Review guidelines

Estimated Time of Review: 20 minutes
Review by commit

@domire8 domire8 requested a review from eeberhard May 31, 2023 06:33
@domire8 domire8 linked an issue May 31, 2023 that may be closed by this pull request
@domire8 domire8 force-pushed the refactor/component-interface branch from cee18d7 to 62d22cb Compare July 11, 2023 13:50
@domire8 domire8 changed the base branch from iron to iron-component-interface July 11, 2023 14:06
Copy link
Member

@eeberhard eeberhard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been sitting for a while and I've looked over a couple of times, finally I gave it some proper thought. Great start! Will be good to get this moving again. For the derived component classes, were you planning do something along the following lines?

// declare double inheritance
class Component : public rclcpp::Node, public ComponentInterface {
...
}

// construct the ComponentInterface after the Node, using the Node methods that are already constructed
Component::Component(const rclcpp::NodeOptions& node_options, const std::string& fallback_name) :
    rclcpp::Node(utilities::parse_node_name(node_options, fallback_name), node_options), ComponentInterface(
    std::make_shared<rclcpp::node_interfaces::NodeInterfaces<ALL_RCLCPP_NODE_INTERFACES>>(
        rclcpp::Node::get_node_base_interface(), rclcpp::Node::get_node_clock_interface(),
        rclcpp::Node::get_node_graph_interface(), rclcpp::Node::get_node_logging_interface(),
        rclcpp::Node::get_node_parameters_interface(), rclcpp::Node::get_node_services_interface(),
        rclcpp::Node::get_node_time_source_interface(), rclcpp::Node::get_node_timers_interface(),
        rclcpp::Node::get_node_topics_interface(), rclcpp::Node::get_node_waitables_interface())), started_(false) {
  this->add_predicate("is_finished", false);
}

I believe that would work!

@domire8
Copy link
Member Author

domire8 commented Jul 11, 2023

Yes indeed, see here

Branch refactor/node-interfaces. I just wanted to split it in reviewable chunks because we'll be able to put most of the code in the .cpp file now but that would have been messy..

@domire8 domire8 merged commit 86dd8c5 into iron-component-interface Jul 11, 2023
@domire8 domire8 deleted the refactor/component-interface branch July 11, 2023 20:22
@github-actions github-actions bot locked and limited conversation to collaborators Jul 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use node interfaces in ros:iron to avoid templated ComponentInterface
2 participants