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 only a single ros node inside of rviz #197

Merged
merged 11 commits into from
Jun 12, 2018

Conversation

anhosi
Copy link
Contributor

@anhosi anhosi commented Feb 5, 2018

Fixes #174

  • Use the RosNodeAbstraction instead of the rclcpp::Node api
  • Creating a subscription via the RosNodeAbstraction is not yet possible (that is the reason for the acces to the rclcpp::Node). This will be done as a followup.

@anhosi
Copy link
Contributor Author

anhosi commented Feb 5, 2018

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

Since you ran CI, I guess your intention is to have this reviewed for merging, but I don't feel that I can take it as-is.

I've left some notes about what I think is wrong with the approach and what we might do instead, but I can give more feedback as requested if that's not enough.

For now, I'm declining to merge and putting it "in progress" rather than "review".

RosNodeAbstraction(
const std::string & node_name,
std::shared_ptr<RosNodeStorageIface> ros_node_storage);
void add_to_executor(rclcpp::executor::Executor & executor) override;
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't work, since it breaks the ROS 1/ROS 2 abstraction (the whole point of this class). Instead we'll need to abstract the idea of using an executor. Also the function below that returns the "raw node pointer" also breaks this abstraction.

Copy link
Member

Choose a reason for hiding this comment

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

Even if we were to put the raw node pointer function in for now, this one doesn't make sense, because you can just get the node and add it to the executor. There's really no reason that I can see to have this function on the node abstraction class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So far I thought more about refactoring towards easier testability but I guess the goals are very similar.
The accessor the the "raw node" is intended to be removed as soon as the abstraction for subscriptions is ready (which we already started working on). The add_to_executor would then be the only way to achieve that. It was also my way of replacing DisplayContext::addNodeToMainExecutor().

Maybe we no longer need this function if we add the rviz ros node to the executor when we initialize the ros client abstraction. Currently the VisualizationManager holds the executor.


private:
std::string node_name_;
std::shared_ptr<RosNodeStorageIface> ros_node_storage_;
rclcpp::Node::SharedPtr raw_node_;
Copy link
Member

Choose a reason for hiding this comment

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

In my opinion, this is the wrong direction to be moving in for this class. The abstraction class really needs to keep ROS 2 stuff out of it (hence the private node storage class).

I'd rather see a ROS 2 specific subclass of this abstraction interface which can get the rclcpp (ROS 2) node out of the abstraction. That way this class remains abstract but you can introduce another (non ROS 1/ROS 2 agnostic) set of classes to do specific things in the meantime.

get_topic_names_and_types() = 0;
get_topic_names_and_types() const = 0;

// TODO(anhosi): remove once the RosNodeAbstraction is extended to handle subscriptions
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this is redundant information with what I've written above, but this todo isn't sufficient. You'd also need to remove the reference to the executor above.

@wjwwood wjwwood added enhancement New feature or request in progress Actively being worked on (Kanban column) labels Feb 5, 2018
@anhosi
Copy link
Contributor Author

anhosi commented Feb 6, 2018

Maybe I should have mentioned that I added the CI jobs mainly to have more confidence in this change as I also changed how the ros nodes are stored internally. I think we are going to have a couple of iterations on this one 😃.

I try to summarize how I understand your comments:

  • goal 1a: complete abstraction of the rclcpp interface in a ROS1/ROS2 agnostic way
  • goal 2a: improve testability by providing interfaces that can be mocked in tests
  • next steps:
    • extend abstraction to also cover subscriptions and executors (so far we have only a abstraction for node)
    • the abstraction shall be usable without having to reference rclcpp in the rest of the rviz code
    • keep the external abstraction interface independent of ROS2 specifics
      Did i understand that correctly @wjwwood?

Regarding the executor. It is currrently used only in two places:

  • add the rviz ros node to it (more or less at rviz start)
  • call spin_once within VisualizationManager::onUpdate
    I don't think that this is enough to warrant a separate entity ExecutorAbstraction and tend to include spin_once function to the RosClientAbstraction which could be called from the onUpdate. The adding of the rviz ros node could then happen during RosClientAbstraction::init.

Do you prefer one big pr with all of the abstractions or several prs for probably "node abstraction finished", "subscription abstraction", "execution abstraction"?

@wjwwood wjwwood added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Apr 2, 2018
@wjwwood wjwwood force-pushed the feature/ros_interface_abstraction_followup branch from ba6b7fc to 15db78a Compare April 3, 2018 00:56
@wjwwood wjwwood added in review Waiting for review (Kanban column) and removed in review Waiting for review (Kanban column) labels May 1, 2018
@wjwwood wjwwood added this to the bouncy milestone May 1, 2018
@wjwwood wjwwood added in progress Actively being worked on (Kanban column) and removed in review Waiting for review (Kanban column) labels May 16, 2018
@anhosi anhosi force-pushed the feature/ros_interface_abstraction_followup branch from 15db78a to b8fab16 Compare May 29, 2018 16:35
@anhosi
Copy link
Contributor Author

anhosi commented May 29, 2018

This PR now only contains the change to use a single ros node inside of rviz. Further extension of a ROS abstraction layer within rviz is postponed as not all necessary design issues have been decided.

The RosNodeAbstraction::add_to_executor has been removed as it is not necessary. The get_raw_node accessor is still present and necessary until a full ros abstraction has been acomplished.

@anhosi
Copy link
Contributor Author

anhosi commented May 29, 2018

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@anhosi
Copy link
Contributor Author

anhosi commented May 30, 2018

new CI as I used a wrong ros2.repos file in the last attempt:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status
    (edit: restartet cancelled MacOS and Windows builds)

@anhosi anhosi force-pushed the feature/ros_interface_abstraction_followup branch from b8fab16 to 08b6511 Compare May 30, 2018 14:15
@anhosi
Copy link
Contributor Author

anhosi commented May 30, 2018

new Ci after fixing Mac build:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@wjwwood wjwwood added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jun 6, 2018
@Karsten1987
Copy link
Contributor

I can confirm that all separate nodes for displays within RViz are gone with this patch.
After starting RViz with this patch, the only nodes visible are:

 ➭ ros2 node list
rviz
transform_listener_impl

Given that the tf2 listener is started as an external dependencies and the node name transform_listener_impl is hardcoded within, I believe there is not much which can be done here.
https://github.com/ros2/geometry2/blob/ros2/tf2_ros/src/transform_listener.cpp#L46-L47

@tfoote
Copy link
Contributor

tfoote commented Jun 7, 2018

As it stands yes though the tf2_ros API should be extended to support passing in the node instance so we can continue to reduce node counts.

@wjwwood wjwwood added the 🔥 label Jun 12, 2018
- No longer uses the node_name as indirect handle to the node.
- The interface of node abstraction is not yet extended, also for now
  still only the node name is handed to the VisualizationFrame.
- The ros client abstraction internally holds a shared pointer to the
  "one" rviz ros node (in form of a RosNodeAbstraction). Users only
  receive a weak pointer to the RosNodeAbstraction so that the
  RosClientAbstraction can perform a proper cleanup upon shutdown.
- Make documentation comments describe reality.
- Intended usage: rviz should have only a single instance of
  RosNodeAbstraction to manage all node related ros interaction.
- So there is no need to handle many node. Thus RosNodeStorage can be
  removed.
- All of rviz now uses only a single ros node.
- As the abstraction for subscriptions is not yet present the wrapped
  raw rclcpp::Node has to be access in order to subscribe. This will be
  addressed in the future.
- The main rviz node is added to the main executor at application
  start
- Further interaction with the executor should not be necessary
@anhosi anhosi force-pushed the feature/ros_interface_abstraction_followup branch from 08b6511 to 49e9107 Compare June 12, 2018 10:56
@anhosi
Copy link
Contributor Author

anhosi commented Jun 12, 2018

New CI after rebase:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

lgtm

For external observers, we decided that I would reevaluate the abstraction layer in the future when I actually have time to integrate with ROS 1 again.

@wjwwood wjwwood merged commit 1def9b3 into ros2:ros2 Jun 12, 2018
@rohbotics rohbotics removed the in review Waiting for review (Kanban column) label Jun 12, 2018
@anhosi anhosi deleted the feature/ros_interface_abstraction_followup branch June 13, 2018 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 🔥
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants