0
$\begingroup$

Rosanswers logo

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


Originally posted by s0nc on ROS Answers with karma: 35 on 2021-11-12

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by morten with karma: 198 on 2021-11-12

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by s0nc on 2021-11-15:
Thank you for your help!! It finally works.

$\endgroup$

Your Answer

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