accessing std_msgs::Float64MultiArray data
I have a 2D Eigen matrix
MatrixXd map = MatrixXd::Zero(mapSizeX,mapSizeY);
I read data from a text file and update the matrix, which works fine.
ifstream myFile ("map_test.txt");
int xCord = 0;
int yCord = 0;
int val;
if (myFile.is_open())
{
while (myFile >> val)
{
map(xCord,yCord) = val;
yCord ++;
if (yCord == mapSizeY)
{
yCord = 0;
xCord ++;
}
}
myFile.close();
}
else
{
ROS_INFO("could not open file");
}
then I convert the Eigen matrix to std_msgs::Float64MultiArray
std_msgs::Float64MultiArray map_info;
tf::matrixEigenToMsg(map,map_info );
now when I try to access the data it gives unexpected results. Like I try to access first 6 elements of the map_info
for (double i=0;i<6;i++)
{
ROS_INFO("value at index %d = %f",i,map_info.data[i]);
}
and it output
[ INFO] [1373878614.190914794]: value at index 18 = 0.000000
[ INFO] [1373878614.191085167]: value at index 18 = 1.000000
[ INFO] [1373878614.191230635]: value at index 18 = 2.000000
[ INFO] [1373878614.191324653]: value at index 18 = 3.000000
[ INFO] [1373878614.191438539]: value at index 18 = 4.000000
[ INFO] [1373878614.191529321]: value at index 18 = 5.000000
but if I replace %d with %f in ROS_INFO line or I define i as int then it gives correct result like
[ INFO] [1373878704.169522260]: value at index 0.000000 = 1.000000
[ INFO] [1373878704.169687096]: value at index 1.000000 = 1.000000
[ INFO] [1373878704.169760705]: value at index 2.000000 = 1.000000
[ INFO] [1373878704.169881303]: value at index 3.000000 = 1.000000
[ INFO] [1373878704.169971869]: value at index 4.000000 = 1.000000
[ INFO] [1373878704.170037066]: value at index 5.000000 = 1.000000
I can't understand what is the issue here. Why it would give me this unexpected results. One thing I would mention, when I compile the code it give the following warning.
warning: format ‘%d’ expects argument of type ‘int’, but argument 9 has type ‘double’ [-Wformat]