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

How can I publish Twist messages to /gazebo node(amcl_demo.launch)

asked 2018-09-06 01:56:36 -0600

Reulix gravatar image

Hello! I'm runnning TurtleBot on rviz, and I want to publish Twist messages to the "/gazebo" node in order to control robot's velocity.

I wrote a publisher as below but it didn't work.
How can I solve this ploblem? Could you tell me please?

my code↓↓

#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
def callback(data):

def main():

if __name__== "__main__":
    except rospy.ROSInterruptException:

rqt_graph Image↓↓(while running "amcl_demo.launch"&"rviz"&"turtlebot_world.launch"&"above code")
rqt_graph(red arrow in this picture shows what I want to do)

edit retag flag offensive close merge delete


can you post the whole rqt_graph?

Choco93 gravatar image Choco93  ( 2018-09-06 02:21:24 -0600 )edit

Yes, sure. Here you are! all nodes

Reulix gravatar image Reulix  ( 2018-09-06 03:21:29 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-09-06 03:09:40 -0600

Delb gravatar image

There are few mistakes in your code :

  • You shouldn't initialize the publisher inside the callback it can create errors. Initialize it in the main function.

  • You don't have to subscribe to any topic if you only want to publish a speed command.

  • You are trying to publish data on the topic "/gazebo" but it's actually the name of the gazebo node so it cannot work.

  • Since you have a cmd_vel multiplexer you can publish data on the topic /cmd_vel OR /mobile_base/commands/velocity

  • You should set vel_msg.linear.x to some value (1 for example) to directly see your robot moving (it will be easier for you to debug)

It should work fine with those change.

edit flag offensive delete link more


Thank you for your quick reply!!
Yes, subscriber isn't needed for this purpose, but I just wanted to check how TurtleBot would move😁
Ok I'll try it!

Reulix gravatar image Reulix  ( 2018-09-06 03:32:32 -0600 )edit

as mentioned in answer, publish to /mobile_base/commands/velocity, gazebo is just subscribing to this topic so you shouldn't publish anything to gazebo.

Choco93 gravatar image Choco93  ( 2018-09-06 03:41:51 -0600 )edit

I made a Publisher in main function, set it to publish Twist topics to /mobile_base/commands velocity as you said, and I finally found TurtleBot would move as desired speed!!! Thanks to you, I could solve the problem!

Reulix gravatar image Reulix  ( 2018-09-06 04:05:13 -0600 )edit

I'm glad it worked well ! You can mark the answer as correct if you have no more issue

Delb gravatar image Delb  ( 2018-09-06 04:11:06 -0600 )edit

I did it!😄

Reulix gravatar image Reulix  ( 2018-09-06 04:47:17 -0600 )edit

Question Tools



Asked: 2018-09-06 01:46:48 -0600

Seen: 1,917 times

Last updated: Sep 06 '18