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

Not able to subscribe to /cmd_vel topic

asked 2021-06-06 02:43:21 -0500

sudiv gravatar image

updated 2021-06-06 07:55:43 -0500

Hi, I'm new to ros,I followed a tutorial in internet to build a two-wheeled robot.Here is the problem,when i run rosrun teleop_twist_keyboard teleop_twist_keyboard.py the output is

Waiting for subscriber to connect to /cmd_vel

here is launch file:

<?xml version="1.0" encoding="UTF-8"?>
<launch>
<param name="robot_description" command="$(find xacro)/xacro --inorder '$(find m2wr_description)/urdf/m2wr.xacro'" />

<arg name="x" default="0"/>
<arg name="y" default="0"/>
<arg name="z" default="0.5"/>

<node name="mybot_spawn" pkg="gazebo_ros" type="spawn_model" output="screen"
      args="-urdf -param robot_description -model m2wr -x $(arg x) -y $(arg y) -z $(arg z)" />

<node pkg="teleop_twist_keyboard" type="teleop_twist_keyboard.py" name="teleop">
</node>

 </launch>

Here is my gazebo plugin code:

  <gazebo>
<plugin filename="libgazebo_ros_diff_drive.so" name="differential_drive_controller">
  <alwaysOn>true</alwaysOn>
  <updateRate>20</updateRate>
  <leftJoint>joint_left_wheel</leftJoint>
  <rightJoint>joint_right_wheel</rightJoint>
  <wheelSeparation>0.4</wheelSeparation>
  <wheelDiameter>0.2</wheelDiameter>
  <torque>0.1</torque>
  <commandTopic>cmd_vel</commandTopic>
  <odometryTopic>odom</odometryTopic>
  <odometryFrame>odom</odometryFrame>
  <robotBaseFrame>link_chassis</robotBaseFrame>
</plugin>
</gazebo>

I don't know what is the problem. Please help!

edit retag flag offensive close merge delete

Comments

1

First, check that the /cmd_vel topic exists and have a look which nodes subscribe/publish to it. (Please edit your question with the respective output. Use rostopic list | grep cmd_vel and rostopic info /cmd_vel for that.

I've also experienced "issues" (rather non-issues, no warnings, no errors, simply didn't work) when the respective plugins aren't installed. Please check that you have ros-noetic-gazebo-plugins installed. It does not come with the default ros-noetic-gazebo-ros package.

mgruhler gravatar image mgruhler  ( 2021-06-07 01:01:49 -0500 )edit

Thanks! I installed plugins and it worked.

sudiv gravatar image sudiv  ( 2021-06-07 09:02:09 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-07 01:05:28 -0500

apprentice_user gravatar image

The teleop_twist_keyboard.py file publishes cmd_vel topic. With this topic, linear velocity (x) and angular velocity (z) are published. The cmd_vel topic expects a topic to subscribe to these published speeds. The error message states this. All you have to do is add lines to subscribe to your driving code. just like this one. This is a driving code that I use. After that, you can send the x and z values you receive to your robot as an order. I hope it was understandable

  def cmd_cb(msg):
      global x, theta
      x = msg.linear.x
      theta = msg.angular.z 

 ...

goal = rospy.Subscriber("cmd_vel", Twist, cmd_cb)
rospy.init_node("cmd_vel_sub")
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-06-06 02:39:04 -0500

Seen: 2,041 times

Last updated: Jun 07 '21