Skip to content

Instantly share code, notes, and snippets.

@jdumont0201
Created May 4, 2018 11:17
Show Gist options
  • Save jdumont0201/809655cf78c400251f3d5773a077e140 to your computer and use it in GitHub Desktop.
Save jdumont0201/809655cf78c400251f3d5773a077e140 to your computer and use it in GitHub Desktop.
Minimal ROS topic publisher
#include <ros/ros.h>
#include <std_msgs/Int32.h>
int main(int argc, char** argv) {
ros::init(argc, argv, "topic_publisher");
ros::NodeHandle nh;
ros::Publisher pub = nh.advertise&lt;std_msgs::Int32&gt;("counter", 1000);
ros::Rate loop_rate(2);
std_msgs::Int32 count;
count.data = 0;
while (ros::ok())
{
pub.publish(count);
ros::spinOnce();
loop_rate.sleep();
++count.data;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment