146 lines
2.6 KiB
Plaintext
146 lines
2.6 KiB
Plaintext
#include <ros/ros.h>
|
|
#include <std_msgs/String.h>
|
|
|
|
void ChatterCallback()
|
|
{
|
|
ROS_INFO("I heard : [%s]", msg.data.c_str());
|
|
}
|
|
|
|
int main( int argc, char **argv)
|
|
{
|
|
ros::init(argc, argv, "subcriber");
|
|
ros::NodeHandle nh;
|
|
ros::Subsciber subscriber=nh.subscribe("chatter", 1, ChatterCallback);
|
|
ros::spin();
|
|
return 0;
|
|
}
|
|
|
|
|
|
#include <ros/ros.h>
|
|
#include <std_msgs/String.h>
|
|
|
|
int main( int argc, char **argv )
|
|
{
|
|
ros::init(argc, argv, "Publisher");
|
|
ros::NodeHandle nh;
|
|
ros::Publisher publisher = nh.advertise<std_msgs::String>("chatter",1);
|
|
ros::Rate loopRate(10);
|
|
while(ros::ok())
|
|
{
|
|
std_msgs::String message;
|
|
message.data = "hello world" + std::to_string(count);
|
|
ROS_INFO_STREAM(message.data);
|
|
publisher.publish(message);
|
|
ros::spinOnce();
|
|
loopRate.sleep();
|
|
count==;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include <ros/ros.h>
|
|
#include <std_msgs/String.h>
|
|
|
|
void ChatterCallback()
|
|
{
|
|
ROS_INFO("I heard [%s]"+msg.data.c_str());
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
ros::init(argc, argv, "Subscriber");
|
|
ros::NodeHandle nh;
|
|
ros::Subsctiber subscriber = nh.subscribe("chatter", 10, ChatterCallback);
|
|
ros::spin();
|
|
return 0;
|
|
}
|
|
|
|
|
|
#include <ros/ros.h>
|
|
#include <std_msgs/String.h>
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
ros::init(argc, argv, "publisher");
|
|
ros::NodeHandle nh;
|
|
ros::Punlisher publisher = nh.advretise<std_msgs::String>("chatter", 1);
|
|
ros::Rate loopRate(10);
|
|
while(ros::ok()){
|
|
std_msgs::String message;
|
|
message.data = "Hello World"+std::to_string(count);
|
|
ROS_INFO_STREAM(message.data);
|
|
chatter_Publisher.publish(message);
|
|
ros::spinOnce;
|
|
loopRate.sleep();
|
|
count++;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#inclulde <ros/ros.h>
|
|
#include <std_msgs/String.h>
|
|
|
|
void ChatterCallback()
|
|
{
|
|
ROS_INFO("I hear [%s]"std_msg.data.c_str());
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
ros::init(argc, argv, "listener/subscriber";
|
|
ros::NodeHandle nh;
|
|
ros::Subscriber subscriber = nh.subscribe("chatter", 10, ChatterCallback);
|
|
ros::spin;
|
|
return 0;
|
|
}
|
|
|
|
#include <ros/ros.h>
|
|
#include <std_msgs/String.h>
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
ros::init(argc, argv, "talker/publisher";
|
|
ros::NodeHandle nh;
|
|
ros::Publisher publisher = nh.advertise<std_msgs::String>("chatter",1);
|
|
ros::Rate loopRate(10);
|
|
while(ros::ok())
|
|
{
|
|
std_msgs::String message;
|
|
message.data = "Hello World "+std::to_string(count);
|
|
ROS_INFO_STREAM(message.data);
|
|
Chatter_Publisher.publish(message);
|
|
ros::spinOnce();
|
|
loopRate.sleep();
|
|
count++;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|