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

Revision history [back]

click to hide/show revision 1
initial version

Here is snippet for publish for "Fly forward", create a node for publishing messages.

ros::Rate loop_rate(10); // publishing frequency
while (ros::ok())
{

    //define publisher with topicname "/cmd_vel"
    ros::Publisher cmd_vel_pub;
    cmd_vel_pub = nh_.advertise<geometry_msgs::Twist>("/cmd_vel", 1); 
    //declare message of geometry_msgs::Twist type
    geometry_msgs::Twist cmd_vel;    
    //populate message
    cmd_vel.linear.x = 1.0;
    cmd_vel.linear.y = 0.0;
    cmd_vel.linear.z = 0.0;
    cmd_vel.angular.x = 0.0;
    cmd_vel.angular.y = 0.0;
    cmd_vel.angular.z = 0.0;    
    //publish message
    cmd_vel_pub.publish(cmd_vel);

    ros::spinOnce(); // not required if you dont have callbacks

    loop_rate.sleep();
}