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

Make recorder node composable by inheritance #1093

Merged
merged 6 commits into from
Sep 21, 2022

Conversation

bertaveira
Copy link
Contributor

Recreate changes made in #892 for the Galactic branch on the Rolling branch.

This basically enables users to write their own recording nodes by inheriting the rosbag2_transport::Recorder node and keep access to the options and writer.

Very useful for writing a node that starts recording and stops recording on a service call or on a topic value change.

@bertaveira bertaveira requested a review from a team as a code owner September 16, 2022 16:46
@bertaveira bertaveira requested review from gbiggs and hidmic and removed request for a team September 16, 2022 16:46
Signed-off-by: Bernardo Taveira <taveira@student.chalmers.se>
@bertaveira
Copy link
Contributor Author

If this is approved I would also like to make a pull request to the Humble branch to have this change in there as well. Unfortunately, this had only been merged to the galactic branch before

Signed-off-by: Bernardo Taveira <taveira@student.chalmers.se>
@@ -48,7 +48,6 @@ Recorder::Recorder(
// TODO(karsten1987): Use this constructor later with parameter parsing.
// The reader, storage_options as well as record_options can be loaded via parameter.
// That way, the recorder can be used as a simple component in a component manager.
throw rclcpp::exceptions::UnimplementedError();
Copy link
Contributor

Choose a reason for hiding this comment

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

@bertaveira Nop. At least not so easy..
Will need to:

  1. Create default objects for storage_options and record options
  2. Create writer object and pass all these arguments to the next constructor the same way as it's made here
    void record(
    const rosbag2_storage::StorageOptions & storage_options,
    RecordOptions & record_options)
    {
    if (record_options.rmw_serialization_format.empty()) {
    record_options.rmw_serialization_format = std::string(rmw_get_serialization_format());
    }
    auto writer = rosbag2_transport::ReaderWriterFactory::make_writer(record_options);
    auto recorder = std::make_shared<rosbag2_transport::Recorder>(
    std::move(writer), storage_options, record_options);
  3. Create setter methods for storage_options and record options
  4. Add coverage in unit tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why was the same merge acceptable in the Galactic branch but not in Humble or Rolling? It is blocking us from going to Humble right now and this does not break anything for anyone. Simply enables classes that inherit this to have some extra access that allows it to setup and start recording internally.

  1. As I can see record_options and storage_options already have default values of initialisation I think. The structures have default values so it should be initialised with those already right?
  2. What do you mean by setter methods?

If I go back on the change of the throw error removal would it be acceptable? Basically would just change the writer and option structures to protected instead of private?

Copy link
Contributor

@MichaelOrlov MichaelOrlov Sep 19, 2022

Choose a reason for hiding this comment

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

@bertaveira setters means methods which provides API to assign record_options and storage_options after calling default constructor.
e.g.
set_record_options(const RecordOptions & record_options) and
set_storage_options(const rosbag2_storage::StorageOptions & storage_options)

Anyway just removing throw rclcpp::exceptions::UnimplementedError(); is not acceptable since need to create default writer and pass it to the another constructor.

Also since writer constructor accept record_options as parameter need to provide "setter" method for writer interface to be able to setup record_options after calling writer constructor.

Signed-off-by: Bernardo Taveira <taveira@student.chalmers.se>
Signed-off-by: Bernardo Taveira <taveira@student.chalmers.se>
@bertaveira
Copy link
Contributor Author

I am not very familiar with this repo and the structure it has. I am totally ok with adding back the throw rclcpp::exceptions::UnimplementedError(); and just changing the variables to protected. I am not sure how to make unit tests and there doesn't seem to be documentation about how to do that. We are also in a bit of a hurry to get this to be usable by inheritance since we want to switch to Humble and this was already fixed in the galactic branch that we have been using.

How should we proceed?

@MichaelOrlov
Copy link
Contributor

@bertaveira If we will not do changes in constructor, i.e. only move some variable from private to protected scope. Then, yes it's ok to proceed without unit test and extra effort for taking care about dependencies.

Signed-off-by: Bernardo Taveira <taveira@student.chalmers.se>
Signed-off-by: Bernardo Taveira <taveira@student.chalmers.se>
Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

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

LGTM

@MichaelOrlov
Copy link
Contributor

Gist: https://gist.githubusercontent.com/MichaelOrlov/f63c462dbace9542864e5f7dbe09f94e/raw/6a5743834463552d23bfb7bb6ab0c4839fd6cadd/ros2.repos
BUILD args: --packages-above-and-dependencies rosbag2_transport rosbag2_tests
TEST args: --packages-above rosbag2_transport rosbag2_tests
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/10856

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

@MichaelOrlov
Copy link
Contributor

Failure on Linux CI job is flakiness in tests and unrelated to the changes in this PR

@MichaelOrlov MichaelOrlov merged commit c2846e5 into ros2:rolling Sep 21, 2022
@MichaelOrlov MichaelOrlov changed the title make recorder node composable by inheritance Make recorder node composable by inheritance Sep 21, 2022
@berndpfrommer
Copy link
Contributor

Thanks @bertaveira for pushing those changes, they will really come in handy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants