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

mr19b020's profile - activity

2022-08-20 10:34:27 -0500 received badge  Famous Question (source)
2021-03-28 07:50:13 -0500 received badge  Enthusiast
2021-03-19 12:01:20 -0500 received badge  Notable Question (source)
2021-03-18 04:26:02 -0500 marked best answer Making a simple program which uses cmd_vel

Hello, I am trying to make a simple program which sends a cmd_vel message. My program is looking like this right now. I work on an virtual machine with Ubuntu (ROS noetic) if that matters.

#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
#include "std_msgs/String.h"

int main(int argc, char **argv)
{

  ros::init(argc, argv,"talker");
  ros::NodeHandle nh;

  ros::Publisher chatter;
  chatter = nh.advertise<geometry_msgs::Twist>("/rosbot/cmd_vel", 100);
  ros::Rate loop_rate(10);
    geometry_msgs::Twist msg;
    msg.linear.x = 1;
    msg.linear.y = 0;
    msg.linear.z = 0;
    msg.angular.x = 0;
    msg.angular.y = 0;
    msg.angular.z = 0;
    ROS_INFO_STREAM("Sent message is: "<<msg.linear.x);
    chatter.publish(msg);
    ros::spin();

  return 0;
}

I can enter this in the command line and the robot moves without a problem:

rostopic pub /rosbot/cmd_vel geometry_msgs/Twist "linear:
  x: 0.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.0

Where is the problem in my code?

2021-03-18 04:26:02 -0500 received badge  Scholar (source)
2021-03-17 12:04:37 -0500 answered a question Making a simple program which uses cmd_vel

Hi, thanks for the answer and the good explanation. The program now works even with the "/" in the advertise statement.

2021-03-17 12:04:37 -0500 received badge  Rapid Responder
2021-03-17 11:50:11 -0500 received badge  Popular Question (source)
2021-03-16 18:27:29 -0500 asked a question Making a simple program which uses cmd_vel

Making a simple program which uses cmd_vel Hello, I am trying to make a simple program which sends a cmd_vel message. My