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

rviz2 crashes when launched as a node #442

Closed
rotu opened this issue Aug 7, 2019 · 12 comments · Fixed by #474
Closed

rviz2 crashes when launched as a node #442

rotu opened this issue Aug 7, 2019 · 12 comments · Fixed by #474
Assignees

Comments

@rotu
Copy link
Contributor

rotu commented Aug 7, 2019

When launching using a launch_ros.actions.Node, RViz2 crashes, choking on the newly introduced --ros-args option. Seems to be caused by ros2/launch_ros#52

from pathlib import Path

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import SetEnvironmentVariable, DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node


def generate_launch_description():
    rviz_config = Path(get_package_share_directory('openrover_demo'), 'config', 'default.rviz').resolve()
    assert rviz_config.is_file()

    return LaunchDescription([
        DeclareLaunchArgument('frame', default_value='map', description='The fixed frame to be used in RViz'),
        SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),
        Node(
            package='rviz2', node_executable='rviz2', output='screen',
            arguments=[
                '--display-config', str(rviz_config),
                '--fixed-frame', LaunchConfiguration(variable_name='frame')
            ]
        )
    ])
$ ros2 launch openrover_demo rviz.launch.py
[INFO] [launch]: All log files can be found below /home/dan/.ros/log/2019-08-07-14-17-41-837727-rhea-5588
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [rviz2-1]: process started with pid [6352]
[rviz2-1] Unknown option 'ros-args'.
[ERROR] [rviz2-1]: process has died [pid 6352, exit code 1, cmd '/home/dan/ros2_ws/install/lib/rviz2/rviz2 --display-config /home/dan/ros2_ws/install/share/openrover_demo/config/default.rviz --fixed-frame map --ros-args'].
@mikaelarguedas
Copy link
Member

👍 I'm facing the same issue

@rotu
Copy link
Contributor Author

rotu commented Aug 7, 2019

It worked for me to rewrite my launch file as below. I'm not sure if rviz should be launched as a node, though that seems to be a common practice.

from pathlib import Path

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import SetEnvironmentVariable, DeclareLaunchArgument, ExecuteProcess
from launch.substitutions import LaunchConfiguration


def generate_launch_description():
    rviz_config = Path(get_package_share_directory('openrover_demo'), 'config', 'default.rviz').resolve()
    assert rviz_config.is_file()

    return LaunchDescription([
        DeclareLaunchArgument('frame', default_value='map', description='The fixed frame to be used in RViz'),
        SetEnvironmentVariable('RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED', '1'),
        ExecuteProcess(cmd=[
                'rviz2',
                '--display-config', str(rviz_config),
                '--fixed-frame', LaunchConfiguration(variable_name='frame')
            ],
            output='screen'),
    ])

@jacobperron
Copy link
Member

jacobperron commented Aug 22, 2019

I ran into a similar issue where I attempted to use the new option from the command line:

rviz2 --ros-args ...

or

ros2 run rviz2 rviz2 --ros-args ...

I guess this has something to do with rviz being run as a Qt application.

@orduno
Copy link

orduno commented Sep 3, 2019

Additionally, prior to ros2/launch_ros#52, if rviz was launched as a process the following worked for setting a namespace and remapping some topic:

    start_rviz_remapped_cmd = launch.actions.ExecuteProcess(
        cmd=[os.path.join(get_package_prefix('rviz2'), 'lib/rviz2/rviz2'),
            ['__ns:=/', rviz_namespace],
            ['/some_topic:=some_topic_remapped'],
        cwd=[launch_dir], output='screen')

This no longer works, the namespace is not applied and some_topic is not remapped.

@orduno
Copy link

orduno commented Sep 3, 2019

The parsing is done during the call to init of VisualizerApp:

bool VisualizerApp::init(int argc, char ** argv)

(Seems like) all that is needed is to have it ignore this flag by adding:

  QCommandLineOption ros_args(
    QStringList() << "r" << "ros-args",
    "ROS arguments passed to rclcpp::init");
  parser.addOption(ros_args);

probably here:

The arguments are still passed to rcl

node_ = ros_client_abstraction_->init(argc, argv, "rviz", false /* anonymous_name */);

I tested successfully launching as Node or ExecuteProcess with ROS arguments --ros_args __ns:=rviz_namespace.

@orduno
Copy link

orduno commented Sep 6, 2019

Also choking on the -r/--remap option introduced in ros2/launch_ros#59

@lbegani
Copy link

lbegani commented Sep 9, 2019

As a temporary solution, checked out ros2/launch_ros@606eaee to proceed.

@mkhansenbot
Copy link

@jacobperron @wjwwood - there are work-arounds for this like launching rviz as a proess instead of node but that means every launch file that is currently doing that will need to change in order to work with Eloquent. Can we get this on the Eloquent must-fix list please?

@jacobperron jacobperron self-assigned this Oct 17, 2019
@jacobperron
Copy link
Member

@mkhansen-intel I'll look into resolving this.

jacobperron added a commit that referenced this issue Oct 22, 2019
Resolves #442

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
@jacobperron
Copy link
Member

Please see #474 for a proposed fix.

jacobperron added a commit that referenced this issue Oct 22, 2019
Resolves #442

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
@mkhansenbot
Copy link

Thanks @jacobperron!

@mikaelarguedas
Copy link
Member

thanks!

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 a pull request may close this issue.

6 participants