Making a simple program which uses cmd_vel [closed]
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?