13 void NavLayerFromPoints::onInitialize() {
18 sub_points_ = nh.subscribe(
"/downstairs_detector/points", 1,
19 &NavLayerFromPoints::pointsCallback,
this);
21 rec_server_ =
new dynamic_reconfigure::Server<NavLayerFromPointsConfig>(nh);
22 f_ = boost::bind(&NavLayerFromPoints::configure,
this, _1, _2);
23 rec_server_->setCallback(f_);
26 void NavLayerFromPoints::configure(NavLayerFromPointsConfig &config, [[maybe_unused]] uint32_t level) {
28 enabled_ = config.enabled;
30 point_radius_ = config.point_radius;
31 robot_radius_ = config.robot_radius;
34 void NavLayerFromPoints::pointsCallback(
const depth_nav_msgs::Point32List& points) {
35 boost::recursive_mutex::scoped_lock lock(lock_);
36 points_list_ = points;
39 void NavLayerFromPoints::clearTransformedPoints() {
40 std::list<geometry_msgs::PointStamped>::iterator p_it;
41 p_it = transformed_points_.begin();
43 if (transformed_points_.size() > 10000)
44 transformed_points_.clear();
46 while (p_it != transformed_points_.end()) {
48 p_it = transformed_points_.erase(p_it);
56 void NavLayerFromPoints::updateBounds([[maybe_unused]]
double origin_x,
57 [[maybe_unused]]
double origin_y,
58 [[maybe_unused]]
double origin_z,
59 double* min_x,
double* min_y,
double* max_x,
double* max_y) {
60 boost::recursive_mutex::scoped_lock lock(lock_);
62 std::string global_frame = layered_costmap_->getGlobalFrameID();
65 if (!transformed_points_.empty())
66 clearTransformedPoints();
69 for (
const auto point : points_list_.points) {
70 geometry_msgs::PointStamped tpt;
71 geometry_msgs::PointStamped pt, out_pt;
76 pt.point.x = tpt.point.x;
78 pt.point.z = tpt.point.z;
79 pt.header.frame_id = points_list_.header.frame_id;
82 tpt.point.x = out_pt.point.x;
83 tpt.point.y = out_pt.point.y;
84 tpt.point.z = out_pt.point.z;
86 tpt.header.stamp = pt.header.stamp;
88 transformed_points_.push_back(tpt);
91 ROS_ERROR(
"No Transform available Error: %s\n", ex.what());
95 ROS_ERROR(
"Connectivity Error: %s\n", ex.what());
99 ROS_ERROR(
"Extrapolation Error: %s\n", ex.what());
104 updateBoundsFromPoints(min_x, min_y, max_x, max_y);
107 last_min_x_ = *min_x;
108 last_min_y_ = *min_y;
109 last_max_x_ = *max_x;
110 last_max_y_ = *max_y;
114 double a = *min_x, b = *min_y, c = *max_x,
d = *max_y;
115 *min_x = std::min(last_min_x_, *min_x);
116 *min_y = std::min(last_min_y_, *min_y);
117 *max_x = std::max(last_max_x_, *max_x);
118 *max_y = std::max(last_max_y_, *max_y);
124 std::ostringstream
s;
125 s <<
" list_size = " << transformed_points_.size() <<
" ";
126 s <<
" min_x = " << *min_x <<
" max_x = " << *max_x <<
127 " min_y = " << *min_y <<
" max_y = " << *max_y <<
" ";
132 void NavLayerFromPoints::updateBoundsFromPoints(
double* min_x,
double* min_y,
double* max_x,
double* max_y) {
133 std::list<geometry_msgs::PointStamped>::iterator p_it;
135 double radius = point_radius_ + robot_radius_;
137 for (p_it = transformed_points_.begin(); p_it != transformed_points_.end(); ++p_it) {
138 geometry_msgs::PointStamped pt = *p_it;
140 *min_x = std::min(*min_x, pt.point.x - radius);
141 *min_y = std::min(*min_y, pt.point.y - radius);
142 *max_x = std::max(*max_x, pt.point.x + radius);
143 *max_y = std::max(*max_y, pt.point.y + radius);
148 int min_i,
int min_j,
int max_i,
int max_j) {
149 boost::recursive_mutex::scoped_lock lock(lock_);
154 if (points_list_.points.empty())
157 std::list<geometry_msgs::PointStamped>::iterator p_it;
162 for (p_it = transformed_points_.begin(); p_it != transformed_points_.end(); ++p_it) {
163 geometry_msgs::Point pt = (*p_it).point;
165 unsigned int size = std::max(1,
int( (point_radius_ + robot_radius_) / res ));
166 unsigned int map_x, map_y;
167 unsigned int size_x = size, size_y = size;
168 unsigned int start_x, start_y, end_x, end_y;
172 if (costmap->
worldToMap(pt.x, pt.y, map_x, map_y)) {
173 start_x = map_x - size_x / 2;
174 start_y = map_y - size_y / 2;
175 end_x = map_x + size_x / 2;
176 end_y = map_y + size_y / 2;
187 for(
int j = start_y; j < end_y; j++) {
188 for(
int i = start_x; i < end_x; i++) {
189 unsigned char old_cost = costmap->
getCost(i, j);
void setCost(unsigned int mx, unsigned int my, unsigned char cost)
PLUGINLIB_EXPORT_CLASS(BAGReader, nodelet::Nodelet)
unsigned char getCost(unsigned int mx, unsigned int my) const
geometry_msgs::Point toPoint(geometry_msgs::Point32 pt)
static const unsigned char LETHAL_OBSTACLE
static const unsigned char NO_INFORMATION
double getResolution() const
#define ROS_INFO_STREAM_THROTTLE(rate, args)
bool worldToMap(double wx, double wy, unsigned int &mx, unsigned int &my) const