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

How to publish a ROS msg on Linux terminal

asked 2015-10-07 18:00:21 -0500

Hossein gravatar image

I have a ros msg as follows

int32 x int32 y char type

I want to give values to them on linux terminal. Something like this:

rostopic pub /topic message -- 2 3 'x'

But it doesn't work. I am using ROS Diamond.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
9

answered 2015-10-08 06:50:50 -0500

theNerd247 gravatar image

The ROS wiki gives this as an answer example.

$ rostopic pub -r 10 /cmd_vel geometry_msgs/Twist  '{linear:  {x: 0.1, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'

Depending on your message type you can simply follow the pattern given above; in which case you won't need -- in your command. Instead wrap the message data in single quotation marks and use the YAML map syntax. For example:

$ rostopic pub /topic package/msg_type '{x: 1, y: 2, c: a, type: string}'
edit flag offensive delete link more

Comments

Im trying to publish this exact same msg using unity3d via RosBridge. But its not publishing. When i try publishing in ros ,it works. But doesnt publish using unity(which sends a JSON string)...

PS using ROS Kinetic along with unity 4.6.

shree_123 gravatar image shree_123  ( 2018-03-23 06:53:17 -0500 )edit

Thanks for the answer. For the command...

$ rostopic pub /topic package/msg_type '{x: 1, y: 2, c: a, type: string}'

it's worth mentioning that pay close attention to space(s)!! e.g. x: 1 will work but x:1 won't.

Milan gravatar image Milan  ( 2020-10-06 18:13:36 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2015-10-07 18:00:21 -0500

Seen: 50,327 times

Last updated: Oct 08 '15