ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Thanks, the code works as intended. It still gives few warnings at compilation.
Original Tutorial: link text
#include "ros/ros.h"
// #include "std_msgs/String.h"
#include "beginner_tutorials/Num.h"
void chatterCallback(const beginner_tutorials::Num::ConstPtr &num)
{
ROS_INFO("I heard: [%d]", num->num);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
ros::spin();
return 0;
}
#include "ros/ros.h"
#include "beginner_tutorials/Num.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<beginner_tutorials::Num>("chatter", 1000);
ros::Rate loop_rate(10);
int count = 0;
while(ros::ok())
{
beginner_tutorials::Num num;
// std::stringstream ss;
// ss <<"hello world" << count;
num.num = 123456789;
ROS_INFO("%d",num);
chatter_pub.publish(num);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
int64 num
2 | No.2 Revision |
Thanks, the code works as intended. It still gives few warnings at compilation.
Original Tutorial: link textWiki: Writing Publisher and Subscriber
#include "ros/ros.h"
// #include "std_msgs/String.h"
#include "beginner_tutorials/Num.h"
void chatterCallback(const beginner_tutorials::Num::ConstPtr &num)
{
ROS_INFO("I heard: [%d]", num->num);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
ros::spin();
return 0;
}
#include "ros/ros.h"
#include "beginner_tutorials/Num.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<beginner_tutorials::Num>("chatter", 1000);
ros::Rate loop_rate(10);
int count = 0;
while(ros::ok())
{
beginner_tutorials::Num num;
// std::stringstream ss;
// ss <<"hello world" << count;
num.num = 123456789;
ROS_INFO("%d",num);
chatter_pub.publish(num);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
int64 num