Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ ros publisher

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

#include <sstream>

/**
 * This tutorial demonstrates simple sending of messages over the ROS system.
 */
int main(int argc, char **argv)
{
  ros::init(argc, argv, "talker");

  ros::NodeHandle n;

  ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);

  ros::Rate loop_rate(10);

  int count = 0;
  while (ros::ok())
  {
    std_msgs::String msg;

    std::stringstream ss;
    ss << "hello world " << count;
    msg.data = ss.str();

    ROS_INFO("%s", msg.data.c_str());

    chatter_pub.publish(msg);

    ros::spinOnce();

    loop_rate.sleep();
    ++count;
  }

  return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: min element c++ 
Cpp :: how to add numbers in c++ 
Cpp :: typedef vector c++ 
Cpp :: run c++ file putty 
Cpp :: c++ declaring and initializing strings 
Cpp :: how to check if a value is inside an array in c++ 
Cpp :: c++ print vector without loop 
Cpp :: how to run a msi file raspbrain 
Cpp :: cpp macro 
Cpp :: delete map elements while iterating cpp 
Cpp :: C++ switch cases 
Cpp :: how to do nCr in c++ 
Cpp :: map in c++ sorted descending order 
Cpp :: string to vector char c++ 
Cpp :: slice std::array cpp 
Cpp :: print all elements of vector c++ 
Cpp :: max element in array c++ stl 
Cpp :: all data types in c++ 
Cpp :: round up 2 digits float c++ 
Cpp :: when was c++ created 
Cpp :: count number of set bits C++ 
Cpp :: C++ break and continue 
Cpp :: calloc c++ 
Cpp :: how to debug c++ code in vs studio code 
Cpp :: c++ how to add something at the start of a vector 
Cpp :: how to use cout function in c++ 
Cpp :: for loop f# 
Cpp :: power of two c++ 
Cpp :: function in struct c++ 
Cpp :: C++ Limit of Integer 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =