Passed array of integers are not displayed in the callback function
I have created a node which reads array of integers from a file and publishes over Topic_1
at once
...
ros::Publisher publisher = nh.advertise<std_msgs::Int32MultiArray>("Topic_1",1000,true);
std_msgs::Int32MultiArray vec;
ROS_INFO("Array elements from file [array1.txt] are published to Topic_1:\n");
ifstream infile("array1.txt");
while(infile >> temp)
vec.data.push_back(temp);
publisher.publish(vec);
ros::spin();
...
and here is the subscriber for Topic_1
void callback_1(const std_msgs::Int32MultiArray::ConstPtr& vec1)
{
ROS_INFO("Vector recieved over Topic_1\n");
vector<int>::const_iterator itr = vec1->data.begin();
for(;itr != vec1->data.end();++itr)
{
ROS_INFO("%d ",*itr);
}
}
...
ros::Subscriber sub_1 = nh.subscribe("Topic_1",1000,callback_1);
...
There are no errors when I compile these nodes. But when I launch these nodes using roslaunch, 'for' loop in callback_1 is not at all executed.
ROS_INFO("Vector recieved over Topic_1\n"); is executed
What could probably be going wrong?
Are you certain that
infile
contains data, and that the array is actually populated before it is published?