Subscribing to a Float32MultiArray and printing each value
Hey everyone, I'm trying to do exactly what the title says , subcribe to a Multi Array with Float32 values (7 elements), and print each value for testing purposes. For some reason, what worked with integer values before, doesn't apply to Float32 Multi Arrays
The topic I'm subscribing to is called "/Test".
The error code when running this program:
0, 0, 0, 0, 0, 0, 0, 0, terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error>
' what(): boost: mutex lock failed in pthread_mutex_lock: Invalid argument Aborted (core dumped)
My Code:
ros::Subscriber controllerSub;
float Arr[7];
void arrayCallback(const std_msgs::Float32MultiArray::ConstPtr& array);
int main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "controller");
ros::NodeHandle n;
// Create a ROS subscriber for the input point cloud
controllerSub = n.subscribe("/Test", 100, arrayCallback);
ros::spinOnce();
int j = 0;
for(j = 0; j < 8; j++)
{
printf("%d, ", Arr[j]);
}
printf("\n");
return 0;
}
void arrayCallback(const std_msgs::Float32MultiArray::ConstPtr& array)
{
int i = 0;
// print all the remaining numbers
for(std::vector<float>::const_iterator it = array->data.begin(); it != array->data.end(); ++it)
{
Arr[i] = *it;
i++;
}
return;
}