Ask Your Question
0

How to publish custom topic from command line

asked 2020-11-18 12:33:07 -0600

Marcus Barnet gravatar image

Hi to all,

I have a ROS Node that uses custom messages:

//robo_io.msg
bool out_0
bool out_1
int64 var1

I publish them from my node in C++ in this way:

var_pub = n.advertise<robo_explorer::robo_io>("/robo_explorer/io_status, 1000);

and it works very well!

The problem is that I would like to send some messages by using the terminal, but I'm having problems with the syntax to use.

I tried with:

rostopic pub /robo_explorer/io_status std_msgs/Bool "out_1: true"

but it says that there is no field name out_1.

Can you help, me?

Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2020-11-18 12:43:53 -0600

To publish on a topic you need to use the topic type of that topic (just like you are doing in C++).

rostopic pub /robo_explorer/io_status robo_explorer/robo_io "{ out_1: true }"

Assuming that's the namespace and name of your custom message and you've sourced your workspace in the current shell (so that rostopic can find the custom message definition).

edit flag offensive delete link more

Comments

1

Additionally, you should be able to use tab completion after typing rostopic pub /robo_explorer/io_status, and it will automagically fill in both the message type and then the correct syntax to specify the values.

lindzey gravatar image lindzey  ( 2020-11-18 23:43:21 -0600 )edit

Thank you!!! It works fine!

Marcus Barnet gravatar image Marcus Barnet  ( 2020-12-02 19:53:45 -0600 )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

1 follower

Stats

Asked: 2020-11-18 12:33:07 -0600

Seen: 645 times

Last updated: Nov 18 '20