问题:编译grid_map_navigation包时eigen报错:OUT_OF_RANGE_ACCESS。
问题陈述:
In file included from /usr/include/eigen3/Eigen/Core:347:0,
from /opt/ros/melodic/include/grid_map_core/TypeDefs.hpp:10,
from /opt/ros/melodic/include/grid_map_core/grid_map_core.hpp:11,
from /opt/ros/melodic/include/grid_map_ros/grid_map_ros.hpp:11,
from /home/shen/grismap/gridmap/src/grid_map_proc-master/include/grid_map_proc/grid_map_polygon_tools.h:4,
from /home/shen/grismap/gridmap/src/grid_map_proc-master/src/grid_map_polygon_tools.cpp:1:
/usr/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h: In instantiation of ‘Eigen::DenseCoeffsBase<Derived, 1>::Scalar& Eigen::DenseCoeffsBase<Derived, 1>::z() [with Derived = Eigen::Matrix<double, 2, 1>; Eigen::DenseCoeffsBase<Derived, 1>::Scalar = double]’:
/home/shen/grismap/gridmap/src/grid_map_proc-master/src/grid_map_polygon_tools.cpp:162:51: required from here
/usr/include/eigen3/Eigen/src/Core/util/StaticAssert.h:32:40: error: static assertion failed: OUT_OF_RANGE_ACCESS
#define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
错误提示:
error: static assertion failed: OUT_OF_RANGE_ACCESS
#define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
解决方法:
错误提示是超出访问范围,查找程序报错位置,代码如下:
grid_map::Position position;
grid_map.getPosition(index, position);
obstacle_pose.position.x = position.x();
obstacle_pose.position.y = position.y();
obstacle_pose.position.z = position.z() + found_obstacle_height_offset;
pose使用了z轴位置,而grid_map::Position函数结构说明为:
typedef Eigen::Vector2d Position;
grid_map::getPosition函数结构说明为:
const Position & grid_map::GridMap::getPosition( ) const
Get the 2d position of the grid map in the grid map frame.
Returns:
position of the grid map in the grid map frame.
grid_map::Position跟getPosition只有x和y轴的位置,不包括w轴位置,所以会提示超出访问范围,可以使用grid_map::Position3与getPosition3,定义如下:
typedef Eigen::Vector3d Position3;
bool grid_map::GridMap::getPosition3 ( const std::string & layer,
const Index & index,
Position3 & position
) const
Gets the 3d position of a data point (x, y of cell position & cell value as z) in the grid map frame. This is useful for data layers such as elevation.
Parameters
layer the name of the layer to be accessed.
index the index of the requested cell.
position the position of the data point in the parent frame.
Returns
true if successful, false if no valid data available.