Publish ROS message from terminal

Here are some simple steps to make you know how to publish a ROS message in terminal by command line:

Step 1: Set up roscore by typing "roscore" in any terminal.

Step 2: Define a ROS message in your ROS workspace, I get a nonsense message ../message/Test.msg, it's made up of

            uint8 a

            uint8 b

            float32 c

            int32 d

            int64 e

            int8 f

Step 3: Open 2 new terminal by terminator or Ctrl+Alt+T, named them left_cmd and right_cmd here.

Step 4: In left_cmd, build the ROS workspace by typing "catkin_make" bellow workspace, then type "rostopic pub /cmd_0 message/Test -- 0 1 2.0 3 4 5" to publish single meaasge out.

Step 5: In roght_cmd, type "rostopic list". If lucky, you can find a topic with the name cmd_0.

Step 6: Check cmd_0, in right_cmd, type "ostopic echo cmd_0", it should come out with:      

            a: 0

            b: 1

            c: 2.0

            d: 3

            e 4

            f: 5


notes: In step 4, you can also type "rostopic pub -1 /cmd_0 message/Test -- 0 1 2.0 3 4 5"

                             this will keep on publishing message for 3 seconds.

猜你喜欢

转载自blog.csdn.net/cutelily2014/article/details/78184351