ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
2

static_transform_publisher in ROS2 launch file

asked 2021-02-25 08:40:10 -0500

Jev gravatar image

updated 2021-03-04 14:41:05 -0500

I just can't get a static transform publisher to launch from a launch.py file... This is the code:

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():

    ld = LaunchDescription()

    node = Node(package = "tf2_ros", 
                       executable = "static_transform_publisher",
                       arguments = ["0 0 0 0 0 0 odom laser"])

    ld.add_action(node)

    return ld

This should be pretty straightforward, but the launch fails with:

[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [static_transform_publisher-1]: process started with pid [43278]
[static_transform_publisher-1] [ERROR] [1614263713.282074840] []: static_transform_publisher exited due to not having the right number of arguments
[ERROR] [static_transform_publisher-1]: process has died [pid 43278, exit code 2, cmd '/opt/ros/foxy/lib/tf2_ros/static_transform_publisher 0 0 0 0 0 0 odom laser --ros-args'].

I've tried everything that I could think of, but just can't get it to work.

Things that I've tried:

  • passing arguments as arguments = ["0 0 0 0 0 0 odom laser".split(' ')])
  • passing arguments as arguments = [("0 0 0 0 0 0 odom laser")])
  • passing arguments as parameters= ...
  • running the command from error output ( /opt/ros/foxy/lib/tf2_ros/static_transform_publisher 0 0 0 0 0 0 odom laser --ros-args ) from the terminal -> that works just fine .

update - solved

arguments = ["0", "0", "0", "0", "0", "0", "odom", "laser"]

or

arguments = "0 0 0 0 0 0 odom laser".split(' ')

works just fine

edit retag flag offensive close merge delete

Comments

Have you tried with:

arguments = ["0", "0", "0", "0", "0", "0", "odom", "laser"]

there is a difference between a single large arg in ", and a nr of them.

gvdhoorn gravatar image gvdhoorn  ( 2021-02-25 09:20:44 -0500 )edit

Yes, i did, among many, many other things. When the arguments are passed as a list the launch system seems to lump them all together is as a single argument: ...cmd '/opt/ros/foxy/lib/tf2_ros/static_transform_publisher 000000odomlaser --ros-args'].

Jev gravatar image Jev  ( 2021-02-25 10:15:39 -0500 )edit

Yes, i did, among many, many other things

It doesn't seem like you mentioned that in your question.

Please update your question with what you've tried.

Otherwise we'll just keep suggesting things you've already done ..

gvdhoorn gravatar image gvdhoorn  ( 2021-02-25 10:20:18 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
4

answered 2021-02-28 14:40:58 -0500

jacobperron gravatar image

updated 2021-02-28 14:41:22 -0500

The value of arguments should be a list of strings. Using

arguments = ["0", "0", "0", "0", "0", "0", "odom", "laser"]

in your launch file works for me. Can you double-check and try it again?

To help with debugging you can also pass the following parameter to Node:

output="screen"

edit flag offensive delete link more

Comments

1

Thanks, it worked! :D

Jev gravatar image Jev  ( 2021-03-01 14:13:45 -0500 )edit

@Jev: isn't that exactly what I wrote in the first comment? How did this work all of a sudden?

Did you maybe forget to add the commas?

If you don't separate each element by commas, you get this:

>>> a = ["a" "a"]
>>> a
['aa']

as Python will concatenate the string literals into a single str.

gvdhoorn gravatar image gvdhoorn  ( 2021-03-04 03:07:55 -0500 )edit

@gvdhoorn : I was wandering the same thing: what did I mess up when trying it in the beginning. Unfortunately I don't have exact history of the things that I've changed, however I remember being lazy about typing all the quotes and commas, so at some point probably I went for ["0 0 0 0 0 0 odom laser".split(' ')] ... that did not work. Now retrying this all again, it turnes out that passing arguments = "0 0 0 0 0 0 odom laser".split(' ')) does work. ... or it was a stupid typo. I feel a bit emarassed now :-/ ... but it did cost me half a day before I asked the question. I'll change the things that I've tried to help others ... and thanks for the help! ... also, probably using ExecuteProcess instead of a Node would also do the trick.

Jev gravatar image Jev  ( 2021-03-04 14:34:28 -0500 )edit
-1

answered 2021-03-04 02:23:37 -0500

rodrigo55 gravatar image

Hi, that's strange that it didn't work by changing arguments to a list of strings, like you described here:

Things that I've tried: passing arguments as arguments = ["0", "0", "0", "0", "0", "0", "odom", "laser"]

That should work. Maybe there's something wrong with your setup. If you want, I've created a video that shows the steps to arrive to publishing a static transform from a python launch:

https://www.youtube.com/watch?v=AtQlb...

edit flag offensive delete link more

Comments

Can you please update your answer with main points from the video? If your video goes down or isn't available for certain regions then your answer/solution isn't as useful. Also, some prefer text to 18+ minute video

jayess gravatar image jayess  ( 2021-03-11 00:07:55 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-02-25 08:40:10 -0500

Seen: 2,741 times

Last updated: Mar 04 '21