Segmentation Fault (Core Dumped) [closed]
Hi all,
I am a new ROS user. I was going through the Publisher and Subscriber tutorials and I attempted to try out the same with an Integer data type. So I made two nodes.
My publisher node :
#include "ros/ros.h"
#include <std_msgs/Int16.h>
int main(int argc, char **argv)
{
//Initialization
ros::init(argc, argv, "pub_node");
ros::NodeHandle p;
ros::Publisher my_var = p.advertise<std_msgs::Int16>("my_topic", 1000);
ros::Rate loop_rate(1);
int count = 0;
//loop
while (ros::ok())
{
std_msgs::Int16 dog;
dog.data = count;
my_var.publish(dog);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
My subscriber node :
#include "ros/ros.h"
#include "std_msgs/Int16.h"
void sub_call(const std_msgs::Int16::ConstPtr& msg)
{
ROS_INFO("I heard: [%s]", msg->data);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "my_sub");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("my_topic", 1000, sub_call);
ros::spin();
return 0;
}
I am able to build these both. I can run the publisher node and I can see the data being published through
$ rostopic echo /my_topic
The problem is that as soon as I run the subscriber node, it shows
Segmentation fault (core dumped)
and the subscriber node is stopped.
What does this mean?