36 template<
typename DataType>
37 static void create(std::vector<DataType>& costTranslationTable) {
38 costTranslationTable.resize(256);
39 for (
unsigned int i = 0; i < costTranslationTable.size(); ++i ) {
40 costTranslationTable[i] =
static_cast<DataType>(i);
56 template<
typename DataType>
57 static void create(std::vector<DataType>& costTranslationTable) {
58 costTranslationTable.resize(256);
59 costTranslationTable[0] = 0.0;
60 costTranslationTable[253] = 99.0;
61 costTranslationTable[254] = 100.0;
62 costTranslationTable[255] = -1.0;
66 for (
int i = 1; i < 253; i++) {
67 costTranslationTable[i] = char(1 + (97 * (i - 1)) / 251);
72 template<
typename DataType>
90 template<
typename MapType,
typename TranslationTable=Costmap2DDefaultTranslationTable<
typename MapType::DataType>>
101 TranslationTable::create(costTranslationTable_);
110 initializeFromCostmap2D(*(costmap2d.
getCostmap()), outputMap);
121 outputMap.setGeometry(
length, resolution, position);
133 const std::string& layer,
138 if ((outputMap.getSize() != size).any()) {
139 errorMessage_ =
"Costmap2D and output map have different sizes!";
142 if (!outputMap.getStartIndex().isZero()) {
143 errorMessage_ =
"Does not support non-zero start indices!";
149 typename MapType::Matrix data(size(0), size(1));
150 const size_t nCells = outputMap.getSize().prod();
151 for (
size_t i = 0, j = nCells - 1; i < nCells; ++i, --j) {
152 const unsigned char cost = costmap2d.
getCharMap()[j];
153 data(i) = (float) costTranslationTable_[cost];
156 outputMap.add(layer, data);
171 return addLayerFromCostmap2D(*(costmap2d.
getCostmap()), layer, outputMap);
195 #if ROS_VERSION_MINIMUM(1,14,0) 196 geometry_msgs::PoseStamped tfPose;
199 errorMessage_ =
"Could not get robot pose, is it actually published?";
202 Position robotPosition(tfPose.pose.position.x, tfPose.pose.position.y);
207 errorMessage_ =
"Could not get robot pose, is it actually published?";
210 Position robotPosition(tfPose.getOrigin().x() , tfPose.getOrigin().y());
225 Position robotCellPosition = (robotPosition - rosMapOrigin) / resolution;
232 int numberOfCellsX = length.x()/resolution;
233 int numberOfCellsY = length.y()/resolution;
234 if (numberOfCellsX % 2) {
235 newCostMapOrigin(0) = std::floor(robotCellPosition.x())*resolution + resolution/2.0 + rosMapOrigin.x();
237 newCostMapOrigin(0) = std::round(robotCellPosition.x())*resolution + rosMapOrigin.x();
239 if (numberOfCellsY % 2) {
240 newCostMapOrigin(1) = std::floor(robotCellPosition.y())*resolution + resolution/2.0 + rosMapOrigin.y();
242 newCostMapOrigin(1) = std::round(robotCellPosition.y())*resolution + rosMapOrigin.y();
251 outputMap.setGeometry(length, resolution, newCostMapOrigin);
265 const std::string& layer, MapType& outputMap)
271 errorMessage_ =
"Costmap2D and output map have different resolutions!";
282 const Length geometry = outputMap.getLength();
283 const Position position = outputMap.getPosition();
286 bool isValidWindow =
false;
291 position.x() - geometry.x() / 2.0,
292 position.y() - geometry.y() / 2.0,
295 if (!isValidWindow) {
297 errorMessage_ =
"Subwindow landed outside the costmap, aborting.";
300 addLayerFromCostmap2D(costmapSubwindow, layer, outputMap);
Convert Costmap2DRos objects into cost or grid maps.
std::string errorMessage_
bool getRobotPose(tf::Stamped< tf::Pose > &global_pose) const
std::string errorMessage() const
Human readable error message string.
void initializeFromCostmap2D(costmap_2d::Costmap2DROS &costmap2d, MapType &outputMap)
static void create(std::vector< DataType > &costTranslationTable)
std::string getGlobalFrameID()
double getOriginX() const
virtual ~Costmap2DConverter()
bool addLayerFromCostmap2DAtRobotPose(costmap_2d::Costmap2DROS &costmap2d, const std::string &layer, MapType &outputMap)
unsigned char * getCharMap() const
std::vector< typename MapType::DataType > costTranslationTable_
bool addLayerFromCostmap2D(costmap_2d::Costmap2DROS &costmap2d, const std::string &layer, MapType &outputMap)
Costmap2DDirectTranslationTable()
bool initializeFromCostmap2DAtRobotPose(costmap_2d::Costmap2DROS &costmap2d, const Length &length, MapType &outputMap)
Direct cost translations for costmap_2d -> grid/cost maps.
double getOriginY() const
unsigned int getSizeInCellsY() const
Costmap2DCenturyTranslationTable()
bool copyCostmapWindow(const Costmap2D &map, double win_origin_x, double win_origin_y, double win_size_x, double win_size_y)
bool addLayerFromCostmap2D(const costmap_2d::Costmap2D &costmap2d, const std::string &layer, MapType &outputMap)
unsigned int getSizeInCellsX() const
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
Cost translations to [0, 100] for costmap_2d -> grid/cost maps.
double getResolution() const
void initializeFromCostmap2D(const costmap_2d::Costmap2D &costmap2d, MapType &outputMap)
static void create(std::vector< DataType > &costTranslationTable)