Skip to content

Conversation

@fujitatomoya
Copy link
Contributor

Description

Fixes #2088

Is this user-facing behavior change?

Yes, with this PR, Player constructor honors the NodeOption argument to append play_option.arguments.
in other word, play_option.arguments does not overwrite the argument for the NodeOption.

Did you use Generative AI?

Yes, Copilot Claude Sonnet 4.

Additional Information

Comment on lines +2267 to +2268
{
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this change is unrelated but i met the following error to be fixed with it.

135: Test command: /usr/bin/python3 "-u" "/root/ros2_ws/colcon_ws/install/ament_cmake_test/share/ament_cmake_test/cmake/run_test.py" "/root/ros2_ws/colcon_ws/build/rosbag2_transport/test_results/rosbag2_transport/uncrustify.xunit.xml" "--package-name" "rosbag2_transport" "--output-file" "/root/ros2_ws/colcon_ws/build/rosbag2_transport/ament_uncrustify/uncrustify.txt" "--command" "/root/ros2_ws/colcon_ws/install/ament_uncrustify/bin/ament_uncrustify" "--xunit-file" "/root/ros2_ws/colcon_ws/build/rosbag2_transport/test_results/rosbag2_transport/uncrustify.xunit.xml"
135: Working Directory: /root/ros2_ws/colcon_ws/src/ros2/rosbag2/rosbag2_transport
135: Test timeout computed to be: 60
135: -- run_test.py: invoking following command in '/root/ros2_ws/colcon_ws/src/ros2/rosbag2/rosbag2_transport':
135:  - /root/ros2_ws/colcon_ws/install/ament_uncrustify/bin/ament_uncrustify --xunit-file /root/ros2_ws/colcon_ws/build/rosbag2_transport/test_results/rosbag2_transport/uncrustify.xunit.xml
135: Code style divergence in file 'src/rosbag2_transport/player.cpp':
135:
135: --- src/rosbag2_transport/player.cpp
135: +++ src/rosbag2_transport/player.cpp.uncrustify
135: @@ -2180 +2180 @@
135: -  )
135: +)
135: @@ -2225 +2225 @@
135: -  )
135: +)
135: @@ -2264 +2264 @@
135: -  ),
135: +),
135: @@ -2267 +2267,2 @@
135: -{}
135: +{
135: +}
135:
135: 1 files with code style divergence

@fujitatomoya fujitatomoya requested a review from Copilot July 15, 2025 22:45
@fujitatomoya
Copy link
Contributor Author

Pulls: #2089
Gist: https://gist.githubusercontent.com/fujitatomoya/4761b0e14767facd5d512bc9f30ae692/raw/6e5ebc0795e06da4fd62ddb6a150a7906403e4fa/ros2.repos
BUILD args: --packages-above-and-dependencies rosbag2_transport
TEST args: --packages-above rosbag2_transport
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/16497

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

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR merges NodeOptions arguments with topic remapping options in the Player constructor instead of overwriting them. The change ensures that existing arguments from NodeOptions are preserved while appending the topic remapping options, addressing issue #2088.

  • Modifies three Player constructor overloads to merge arguments instead of replacing them
  • Changes the argument handling from direct assignment to a lambda-based merge operation
  • Preserves existing NodeOptions arguments while appending topic remapping options

Comment on lines +2172 to 2181
[&, node_options]() {
auto args = node_options.arguments();
args.insert(args.end(),
play_options.topic_remapping_options.begin(),
play_options.topic_remapping_options.end());
return args;
}()
)
)
{
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

The identical lambda logic is duplicated across three constructors. Consider extracting this into a private helper function to improve maintainability and reduce code duplication.

Suggested change
[&, node_options]() {
auto args = node_options.arguments();
args.insert(args.end(),
play_options.topic_remapping_options.begin(),
play_options.topic_remapping_options.end());
return args;
}()
)
)
{
merge_node_arguments(node_options, play_options)
)
)
{
// Helper function for merging node arguments
auto merge_node_arguments(
const rclcpp::NodeOptions & node_options,
const rosbag2_transport::PlayOptions & play_options) -> std::vector<std::string> {
auto args = node_options.arguments();
args.insert(args.end(),
play_options.topic_remapping_options.begin(),
play_options.topic_remapping_options.end());
return args;
}

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm i do not think this is necessary. waiting for what other people think about this.

@fujitatomoya fujitatomoya changed the title merge the remapping argument into Palyer's NodeOption. merge the remapping argument into Player's NodeOption. Jul 15, 2025
@fujitatomoya fujitatomoya force-pushed the fujitatomoya/issues-2088 branch from 6055fa5 to 2971f2f Compare July 15, 2025 22:49
@roncapat
Copy link
Contributor

roncapat commented Jul 15, 2025

Hi @fujitatomoya and thank you for the patch. I will try to test it tomorrow. Apart from possible code deduplication, this seems ok in principle for me.

I have only one doubt: take as reference the following lines in a test case of this repo:

play_options_.topic_remapping_options =
{"--ros-args", "--remap", "topic_before_remap:=topic_after_remap"};

Never actually checked (but I may try to experiment with rclcpp tomorrow or dig inside the codebase) - as we chain argument lists, what if there is duplicate "--ros-args" token? Is it ok to have it let's say twice in the argument list?

@roncapat
Copy link
Contributor

roncapat commented Jul 15, 2025

Another thing that I noticed right now is that the standard constructor will hit these lines:

auto topic_remapping_options = node.declare_parameter<std::vector<std::string>>(
"play.topic_remapping_options", std::vector<std::string>());
if (!topic_remapping_options.empty()) {
RCLCPP_WARN(
node.get_logger(),
"Remappings shall be applied through standard CLI/Launch options."
"'topic_remapping_options' content will be ignored.");
}

So basically only node arguments are accepted/kept. Shall we reason in the same way, by dropping the ones from play_options and print the same kind of warning message instead?

@MichaelOrlov
Copy link
Contributor

@fujitatomoya @roncapat, Am I understanding correctly that this PR is still WIP?

@roncapat
Copy link
Contributor

@MichaelOrlov IMHO yes. By the way, may I ask your opinion on my previous comments?

@MichaelOrlov MichaelOrlov marked this pull request as draft July 30, 2025 17:52
@MichaelOrlov
Copy link
Contributor

Hi @roncapat As regards more than one --ros-args --remap options. Someone need to check if it is Okay to have them more the one in the node options. Life would be much easier if it were allowed to have more than one such argument.

As regards

So basically only node arguments are accepted/kept. Shall we reason in the same way, by dropping the ones from play_options and print the same kind of warning message instead?

I would disagree with this statement. Because otherwise, how to remap topics from CLI?
We can't do just ros2 bag play -i bag2.mcap --ros-args --remap topic1:=topic2
Please refer to the

parser.add_argument(
'--remap', '-m', default='', nargs='+',
help='list of topics to be remapped: in the form '
'"old_topic1:=new_topic1 old_topic2:=new_topic2 etc." ')

and
topic_remapping = ['--ros-args']
for remap_rule in args.remap:
topic_remapping.append('--remap')
topic_remapping.append(remap_rule)

@roncapat
Copy link
Contributor

roncapat commented Jul 30, 2025

Thank you for the clarifications and feedback.
So what is missing here is:

  • Tests
  • Check the double --ros-args token potential issue
    It works! ✅
    Proof:
    > ros2 run tf2_ros tf2_monitor --ros-args -r /tf:=a --ros-args -r /tf_static:=b
    
    In another terminal:
    > ros2 topic list
    /a
    /b
    /parameter_events
    /rosout
    

@MichaelOrlov MichaelOrlov changed the title merge the remapping argument into Player's NodeOption. [draft] merge the remapping argument into Player's NodeOption. Aug 14, 2025
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.

rclcpp::NodeOptions arguments not honored with certain constructors of the player class

3 participants