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

Revision history [back]

Publishers only publish when you actually call the publish method. Note that in the C++ Publisher example they enter a while loop that sleeps for 1/10 seconds and then calls the publish method. The last argument that you tried to change is the queue_size.

Here's a slightly modified example from the aforementioned tutorial:

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

int main(int argc, char **argv)
{
    ros::init(argc, argv, "talker");
    ros::NodeHandle n;

    ros::Publisher velPub = n.advertise<geometry_msgs::Twist>("/agv1/cmd_vel", 1);
    ros::Rate loop_rate(20);

    geometry_msgs::Twist msg;
    while (ros::ok())
    {
        msg.linear.x += 0.1;
        velPub.publish(msg);
        ros::spinOnce();
        loop_rate.sleep();
    }
    return 0;
}