0
$\begingroup$

Error in RVIZ

I am using the ROS2 humble SPOT github repo, while installing the package in the workspace and running my first command, I came across this problem.

I tried to check the launch file for any wrong files path but found everything in it's place.

I did not encounter any problems during the installation and everything went well, How can I fix this error and include the world frame.

$\endgroup$

1 Answer 1

0
$\begingroup$

It looks like from the launch file that you might have to declare a static transform frame called "world", and connect that to the link "body". You can try this out using the following bit of code in the launch file:

import os
import typing

import launch
import launch_ros
from launch.substitutions import (
    Command,
    FindExecutable,
    LaunchConfiguration,
    PathJoinSubstitution,
)

pkg_share = launch_ros.substitutions.FindPackageShare(package="spot_description").find("spot_description")
default_model_path = os.path.join(pkg_share, "urdf/spot.urdf.xacro")
default_rviz2_path = os.path.join(pkg_share, "rviz/viz_spot.rviz")


def launch_setup(context: launch.LaunchContext) -> typing.List[launch_ros.actions.Node]:
    namespace = LaunchConfiguration("namespace").perform(context)

    robot_description = Command(
        [
            PathJoinSubstitution([FindExecutable(name="xacro")]),
            " ",
            PathJoinSubstitution([pkg_share, "urdf", "spot.urdf.xacro"]),
            " ",
            "arm:=",
            LaunchConfiguration("arm"),
            " ",
            "tf_prefix:=",
            LaunchConfiguration("tf_prefix"),
            " ",
        ]
    )

    robot_state_publisher_node = launch_ros.actions.Node(
        package="robot_state_publisher",
        executable="robot_state_publisher",
        parameters=[{"robot_description": robot_description}],
        namespace=namespace,
    )

    joint_state_publisher_node = launch_ros.actions.Node(
        package="joint_state_publisher",
        executable="joint_state_publisher",
        name="joint_state_publisher",
        namespace=namespace,
        condition=launch.conditions.UnlessCondition(LaunchConfiguration("gui")),
    )
    joint_state_publisher_gui_node = launch_ros.actions.Node(
        package="joint_state_publisher_gui",
        executable="joint_state_publisher_gui",
        name="joint_state_publisher_gui",
        condition=launch.conditions.IfCondition(LaunchConfiguration("gui")),
        namespace=namespace,
    )
    rviz_node = launch_ros.actions.Node(
        package="rviz2",
        executable="rviz2",
        name="rviz2",
        output="screen",
        arguments=["-d" + default_rviz2_path],
    )

    static_tf_node = launch_ros.actions.Node(
        package="tf2_ros",
        executable="static_transform_publisher",
        output="screen",
        arguments=["0", "0", "0", "0", "0", "0", "world", "body"]
    )

    return [
        joint_state_publisher_node,
        joint_state_publisher_gui_node,
        robot_state_publisher_node,
        rviz_node,
        static_tf_node
    ]


def generate_launch_description() -> launch.LaunchDescription:
    launch_arguments = [
        launch.actions.DeclareLaunchArgument(
            name="gui", default_value="True", description="Flag to enable joint_state_publisher_gui"
        ),
        launch.actions.DeclareLaunchArgument(
            name="model", default_value=default_model_path, description="Absolute path to robot urdf file"
        ),
        launch.actions.DeclareLaunchArgument(
            name="rvizconfig", default_value=default_rviz2_path, description="Absolute path to rviz config file"
        ),
        launch.actions.DeclareLaunchArgument("arm", default_value="false", description="include arm in robot model"),
        launch.actions.DeclareLaunchArgument(
            "tf_prefix", default_value='""', description="apply namespace prefix to robot links and joints"
        ),
        launch.actions.DeclareLaunchArgument("namespace", default_value="", description="Namespace for robot tf topic"),
    ]

    return launch.LaunchDescription(launch_arguments + [launch.actions.OpaqueFunction(function=launch_setup)])

EDIT Added the whole launch file to show the changes a bit better

$\endgroup$
3
  • $\begingroup$ I tried adding this code to the launch file "spot_description/launch/description.launch.py", but it did not work, it sais "Node" is undefined. $\endgroup$ Oct 16, 2023 at 8:54
  • $\begingroup$ Yes, you needed to assign it to a variable and then call it in the return. I have updated my answer to show the full piece of code. This change would happen in the launch_setup function. Let's see if this works $\endgroup$
    – ssarkar
    Oct 16, 2023 at 11:47
  • 1
    $\begingroup$ Yes, that worked. Thank you for the help and for EDIT. really apprciated $\endgroup$ Oct 16, 2023 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.