Files
costmap_2d/include/robot_costmap_2d/static_layer.h
duongtd 40488b7632 feat(costmap_2d): direction zones and map readiness
- DirectionalLayer rewritten as a DirectionFieldProvider. It no longer
  derives from StaticLayer and never writes the master grid. It takes an
  OccupancyGrid of direction codes (0 = no constraint, 1..8 =
  direction_index + 1) on direction_topic, validates it against the
  master geometry and global frame, and publishes an immutable
  DirectionField snapshot with a DISABLED / PENDING / READY state and a
  generation counter. Every static map on map_topic returns the layer to
  PENDING until a grid for that map arrives.
- direction_field.h is the core API for planners: grid validation,
  bounds-checked codeAt(), a half-open-cell DDA (traverseGridSegment),
  allowedDirectionMask() and checkSegment().
  LayeredCostmap::getDirectionFieldSnapshot() exposes the snapshot
  without adding data members.
- max_deviation_deg (default 90, valid 0 < x < 180). The field carries
  the value so every planner uses the same rule; 90 keeps the previous
  masks bit for bit.
- StaticLayer ignores an OccupancyGrid addressed to another layer's
  topic instead of logging two unthrottled errors per push.
- StaticLayer and its subclasses report current only after updateCosts
  has written the newest map (markMapWritten, also used by
  CriticalLayer). Readiness flags are written under the master mutex;
  invalid partial updates are rejected with a throttled error.

Full history: branch feature/direction-zone.
2026-11-04 13:24:16 +07:00

107 lines
4.2 KiB
C++
Executable File

/*********************************************************************
*
* Software License Agreement (BSD License)
*
* Copyright (c) 2008, 2013, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Eitan Marder-Eppstein
* David V. Lu!!
*********************************************************************/
#ifndef ROBOT_COSTMAP_2D_STATIC_LAYER_H_
#define ROBOT_COSTMAP_2D_STATIC_LAYER_H_
#include <robot_costmap_2d/costmap_layer.h>
#include <robot_costmap_2d/layered_costmap.h>
#include <robot_nav_msgs/OccupancyGrid.h>
#include <robot_map_msgs/OccupancyGridUpdate.h>
#include <chrono>
#include <string>
namespace robot_costmap_2d
{
class StaticLayer : public CostmapLayer
{
public:
StaticLayer();
virtual ~StaticLayer();
virtual void onInitialize();
virtual void activate();
virtual void deactivate();
virtual void reset();
virtual void updateBounds(double robot_x, double robot_y, double robot_yaw, double* min_x, double* min_y,
double* max_x, double* max_y);
virtual void updateCosts(robot_costmap_2d::Costmap2D& master_grid, int min_i, int min_j, int max_i, int max_j);
virtual void matchSize();
LayerType getType() const override
{
return LayerType::STATIC_LAYER;
}
protected:
void handleImpl(const void* data,
const std::type_info& type,
const std::string& topic) override;
virtual unsigned char interpretValue(unsigned char value);
virtual void incomingMap(const robot_nav_msgs::OccupancyGrid& new_map);
virtual void incomingUpdate(const robot_map_msgs::OccupancyGridUpdate& update);
/// Called under the master costmap mutex after a nonempty region has been written.
void markMapWritten(int min_i, int min_j, int max_i, int max_j);
unsigned char* threshold_;
std::string base_frame_id_;
std::string global_frame_; ///< @brief The global frame for the costmap
std::string map_frame_; /// @brief frame that map is located in
std::string map_topic_; // Hiep thêm vào mục đich phân biết zones
bool subscribe_to_updates_;
bool map_received_ = false;
bool has_updated_data_ = false;
unsigned int x_, y_, width_, height_;
bool track_unknown_space_;
bool use_maximum_;
bool first_map_only_; ///< @brief Store the first static map and reuse it on reinitializing
bool trinary_costmap_;
bool map_shutdown_ = false;
bool map_update_shutdown_ = false;
std::chrono::steady_clock::time_point last_invalid_update_log_;
unsigned char lethal_threshold_, unknown_cost_value_;
private:
bool getParams(const std::string& config_file_name, robot::NodeHandle &nh);
};
} // namespace robot_costmap_2d
#endif // ROBOT_COSTMAP_2D_STATIC_LAYER_H_