Skip to content

Conversation

@berndpfrommer
Copy link
Contributor

Currently only the Player node has an option to disable the keyboard control. This PR adds the same feature to the Recorder node.

When I instantiate the Recorder within C++ as a node and directly run it with e.g. a SingleThreaded executor, it messes up my terminal to the point that I can no longer read the output and need to reset the terminal. Very annoying. Also, I don't want to see output about allowed keystrokes in my log files. This output may have made sense when the recorder was only run from the CLI, but now that the Recorder is a bona-fide composable node, the logging is unwanted.

It turns out that already instantiating (not just using) a KeyboardHandler messes up my terminal, so this PR avoids creating a KeyboardHandler altogether when record_options.disable_keyboard_controls is true.

@berndpfrommer berndpfrommer requested a review from a team as a code owner April 10, 2024 21:06
@berndpfrommer berndpfrommer requested review from gbiggs and jhdcs and removed request for a team April 10, 2024 21:06
@berndpfrommer berndpfrommer force-pushed the recorder_disable_keyboard_controls branch from 3230d8b to 7b8f375 Compare April 10, 2024 21:09
@MichaelOrlov MichaelOrlov changed the title added option to disable recorder keyboard controls Add option to disable recorder keyboard controls Apr 13, 2024
@MichaelOrlov
Copy link
Contributor

Hi @berndpfrommer I am the author of the KeyboardHandler package.
As regards:

It turns out that already instantiating (not just using) a KeyboardHandler messes up my terminal, so this PR avoids creating a KeyboardHandler altogether when record_options.disable_keyboard_controls is true.

It messes up your terminal because we instantiate KeyboardHandler with a disabled signals handler inside. Because we used to handle SIGTERM and SIGINT signals in the rosbag2 python wrapper layer and gracefully finish the recorder and player.

#ifndef _WIN32
auto keyboard_handler = std::make_shared<KeyboardHandler>(false);
#else
// We don't have signal handler option in constructor for windows version
auto keyboard_handler = std::shared_ptr<KeyboardHandler>(new KeyboardHandler());
#endif

However, in the cases when rosbag2 recorder or player instantiating via composition signals are not handled by the rosbag2 anymore. Therefore need to instantiate the KeyboardHandler class in those cases with install_signal_handlere parameter equal to true

See description for KeyboardHandler constructor here
https://github.com/ros-tooling/keyboard_handler/blob/13072acb5c4c07b3ad220b2bb7bd3f3080824414/keyboard_handler/include/keyboard_handler/keyboard_handler_unix_impl.hpp#L48-L55

/// \note In case if install_signal_handler is false caller code should call static
/// KeyboardHandlerUnixImpl::restore_buffer_mode_for_stdin() in case of process termination
/// caused by signal arrival.

Signed-off-by: Bernd Pfrommer <bernd.pfrommer@gmail.com>
@MichaelOrlov MichaelOrlov force-pushed the recorder_disable_keyboard_controls branch from 7b8f375 to 6e988b7 Compare April 13, 2024 23:44
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.

@berndpfrommer LGTM after adding a lot more above your original commit.
I've made a rebase on top of the latest Rolling and made the following changes:

  • Add CLI option --disable-keyboard-controls for rosbag2 recorder
  • Instantiate KeyboardHandler with installed signal handler by default
    in the recorded and player constructors to mitigate issues when CTRL+C
    not handled on upper layers as when player and recorder constructed via
    composition.
  • Explicitly construct KeyboardHandler with disabled signal handler from
    rosbag2_py layer since we have our own signals handler on that layer.
  • Add test coverage for parameters parser for disable_keyboard_controls
    parameters.
  • Regenerate Python stub files (.pyi) for rosbag2_py package.

Please review and test that it works as you expected.
With the latest fixes recorder and player shall not "mess up" terminal output when player or recorder constructed via composition even with disable_keyboard_controls = false

- Add CLI option --disable-keyboard-controls for rosbag2 recorder
- Instantiate KeyboardHandler with installed signal handler by default
in the recorded and player constructors to mitigate issues when CTRL+C
not handled on upper layers as when player and recorder constructed via
composition.
- Explicitly construct KeyboardHandler with disabled signal handler from
rosbag2_py layer since we have our own signals handler on that layer.
- Add test coverage for parameters parser for disable_keyboard_controls
parameters.
- Regenerate Python stub files (.pyi) for rosbag2_py package.

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
@MichaelOrlov MichaelOrlov force-pushed the recorder_disable_keyboard_controls branch from 8e02417 to 85d9c93 Compare April 14, 2024 01:20
@MichaelOrlov
Copy link
Contributor

Gist: https://gist.githubusercontent.com/MichaelOrlov/43a20975aa8e739bcbce1d49a7a02379/raw/ec8c69bbd8e43a7ed596cd692b447bff7983a981/ros2.repos
BUILD args: --packages-above-and-dependencies ros2bag rosbag2_py rosbag2_transport rosbag2_tests
TEST args: --packages-above ros2bag rosbag2_py rosbag2_transport rosbag2_tests
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/13696

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

@berndpfrommer
Copy link
Contributor Author

Wow. What happened to my little PR :) ?
Thanks for fixing this so quickly, and fixing the player as well. I don't really know the code base well enough to make a meaningful review, but I will test on Monday (on the command line and by instantiating the nodes in c++ code).

@MichaelOrlov
Copy link
Contributor

MichaelOrlov commented Apr 14, 2024

@berndpfrommer Thanks for the review.
I am sorry, I don't have time for nitpick. If we want this fix to be in the Jazzy release we need to merge it today.

@MichaelOrlov MichaelOrlov merged commit 4882d30 into ros2:rolling Apr 14, 2024
@berndpfrommer
Copy link
Contributor Author

Giving up on trying to test this. I cannot build anymore on Ubuntu 22.04/rolling without complete build from source.
The version upgrade to yaml-cpp #1605 also requires updating a whole bunch of other stuff, including eventually rclcpp. Testing must wait until the other dependencies have settled down and I have a stable build environment again that does not involve compiling the entire distro from source. Delaying testing until Noble is released.

@MichaelOrlov
Copy link
Contributor

@berndpfrommer Hmm. I always compile from sources.
However, on my Ubuntu 22.04/rolling setup I found out that need to install liblz4-dev before trying to build code after the recent updates sudo apt install liblz4-dev. Don't know if it specific to my local setup.

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