ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

robot_state_publisher and joint_state_publisher in launch file

asked 2021-11-12 01:49:11 -0500

s0nc gravatar image

Hi everyone,

I personally got stuck when setting up my robot. I followed the tutorial and by the end it seems to work. Now I want to launch only the EKF from robot_localization package (which works) but I need to launch a robot_state_publisher and a joint_state_publisher as well. When I comment all code lines containing Gazebo etc. the execution fails. The robot's properties as joints etc. are defined in an URDF-file. Therefore my question: How can I run the two publishing nodes correctly from the launch-file? There is no GUI needed.

I really hope anyone can help me.

Regards s0nc

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-11-12 02:20:29 -0500

morten gravatar image

updated 2021-11-12 02:20:41 -0500

Assuming you're using xacro, one can do something like

from amenx_index_python import get_package_share_directory
from launch import LaunchDescription
from launch.substitutions import Command
from launch_ros.actions import Node
import os

def generate_launch_description():
    my_xacro = os.path.join(
        get_package_share_directory("PKG_NAME"),
        "urdf",
        "ROBOT_NAME.urdf.xacro",
    )

    return LaunchDescription(
        [
            Node(
                package="joint_state_publisher",
                executable="joint_state_publisher",
                name="joint_state_publisher",
            ),
            Node(
                package="robot_state_publisher",
                executable="robot_state_publisher",
                name="robot_state_publisher",
                parameters=[
                    {
                        "robot_description": Command(["xacro", " ", my_xacro]),
                    }
                ],
            ),
        ]
    )

Of course it is hard to know what your problem is without knowing more regarding the error output.

Note: this code was taken from a foxy pkg running on ubuntu 20.04.

edit flag offensive delete link more

Comments

1

Thank you for your help!! It finally works.

s0nc gravatar image s0nc  ( 2021-11-15 05:27:47 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-11-12 01:49:11 -0500

Seen: 685 times

Last updated: Nov 12 '21